Le duodi 12 frimaire, an CCXXIV, Clement Boesch a écrit : > From: Clément Bœsch <clem...@stupeflix.com> > > --- > libavutil/threadmessage.c | 32 ++++++++++++++++++++++++++++++++ > libavutil/threadmessage.h | 12 ++++++++++++ > 2 files changed, 44 insertions(+) > > diff --git a/libavutil/threadmessage.c b/libavutil/threadmessage.c > index b7fcbe2..66b5fc6 100644 > --- a/libavutil/threadmessage.c > +++ b/libavutil/threadmessage.c > @@ -40,6 +40,8 @@ struct AVThreadMessageQueue { > int err_send; > int err_recv; > unsigned elsize; > + void (*free_func)(void *msg); > + void *tmp_msg; > #else > int dummy; > #endif > @@ -81,10 +83,21 @@ int av_thread_message_queue_alloc(AVThreadMessageQueue > **mq, > #endif /* HAVE_THREADS */ > } > > +int av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq, > + void (*free_func)(void *msg)) > +{ > + mq->free_func = free_func; > + av_freep(&mq->tmp_msg); > + mq->tmp_msg = av_mallocz(mq->elsize); > + return mq->tmp_msg ? 0 : AVERROR(ENOMEM); > +} > + > void av_thread_message_queue_free(AVThreadMessageQueue **mq) > { > #if HAVE_THREADS > if (*mq) { > + av_thread_message_flush(*mq); > + av_freep(&(*mq)->tmp_msg); > av_fifo_freep(&(*mq)->fifo); > pthread_cond_destroy(&(*mq)->cond); > pthread_mutex_destroy(&(*mq)->lock); > @@ -182,3 +195,22 @@ void > av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, > pthread_mutex_unlock(&mq->lock); > #endif /* HAVE_THREADS */ > } > + > +void av_thread_message_flush(AVThreadMessageQueue *mq) > +{ > +#if HAVE_THREADS > + int used, off; > + > + pthread_mutex_lock(&mq->lock); > + used = av_fifo_size(mq->fifo); > + if (mq->free_func) { > + for (off = 0; off < used; off += mq->elsize) {
> + av_fifo_generic_peek_at(mq->fifo, mq->tmp_msg, off, mq->elsize, > NULL); > + mq->free_func(mq->tmp_msg); Could this use av_fifo_generic_peek() to avoid the ugly extra allocation? > + } > + } > + av_fifo_drain(mq->fifo, used); > + pthread_cond_broadcast(&mq->cond); > + pthread_mutex_unlock(&mq->lock); > +#endif /* HAVE_THREADS */ > +} > diff --git a/libavutil/threadmessage.h b/libavutil/threadmessage.h > index a8481d8..c59cb06 100644 > --- a/libavutil/threadmessage.h > +++ b/libavutil/threadmessage.h > @@ -88,4 +88,16 @@ void > av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq, > void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, > int err); > > +/** > + * Set the optional free message callback function which will be called if an > + * operation is removing messages from the queue. > + */ > +int av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq, > + void (*free_func)(void *msg)); > + > +/** > + * Flush the message queue I will not block for that, but I am still not satisfied with the explanations, and therefore I find this documentation insufficient. Maybe wait for other advice? > + */ > +void av_thread_message_flush(AVThreadMessageQueue *mq); > + > #endif /* AVUTIL_THREADMESSAGE_H */ Regards, -- Nicolas George
signature.asc
Description: Digital signature
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel