History

lavu/threadmessage: switch to new FIFO API

Anton Khirnov committed 4 years ago

Commit 90eef1c1 parent d1bd1891 file · +19 −19Browse files

Unified · Split

libavutil/threadmessage.c+19−19
@@ -24,7 +24,7 @@ · 23 unmodified lines
2424
2525 struct AVThreadMessageQueue {
2626 #if HAVE_THREADS
27− AVFifoBuffer *fifo;
27+ AVFifo *fifo;
2828 pthread_mutex_t lock;
2929 pthread_cond_t cond_recv;
3030 pthread_cond_t cond_send;
@@ -64,7 +64,7 @@ int av_thread_message_queue_alloc(AVThreadMessageQueue **mq, · 33 unmodified lines
6464 av_free(rmq);
6565 return AVERROR(ret);
6666 }
67− if (!(rmq->fifo = av_fifo_alloc(elsize * nelem))) {
67+ if (!(rmq->fifo = av_fifo_alloc2(nelem, elsize, 0))) {
6868 pthread_cond_destroy(&rmq->cond_send);
6969 pthread_cond_destroy(&rmq->cond_recv);
7070 pthread_mutex_destroy(&rmq->lock);
@@ -93,7 +93,7 @@ void av_thread_message_queue_free(AVThreadMessageQueue **mq) · 22 unmodified lines
9393 #if HAVE_THREADS
9494 if (*mq) {
9595 av_thread_message_flush(*mq);
96− av_fifo_freep(&(*mq)->fifo);
96+ av_fifo_freep2(&(*mq)->fifo);
9797 pthread_cond_destroy(&(*mq)->cond_send);
9898 pthread_cond_destroy(&(*mq)->cond_recv);
9999 pthread_mutex_destroy(&(*mq)->lock);
@@ -107,9 +107,9 @@ int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq) · 7 unmodified lines
107107 #if HAVE_THREADS
108108 int ret;
109109 pthread_mutex_lock(&mq->lock);
110− ret = av_fifo_size(mq->fifo);
110+ ret = av_fifo_can_read(mq->fifo);
111111 pthread_mutex_unlock(&mq->lock);
112− return ret / mq->elsize;
112+ return ret;
113113 #else
114114 return AVERROR(ENOSYS);
115115 #endif
@@ -121,14 +121,14 @@ static int av_thread_message_queue_send_locked(AVThreadMessageQueue *mq, · 5 unmodified lines
121121 void *msg,
122122 unsigned flags)
123123 {
124− while (!mq->err_send && av_fifo_space(mq->fifo) < mq->elsize) {
124+ while (!mq->err_send && !av_fifo_can_write(mq->fifo)) {
125125 if ((flags & AV_THREAD_MESSAGE_NONBLOCK))
126126 return AVERROR(EAGAIN);
127127 pthread_cond_wait(&mq->cond_send, &mq->lock);
128128 }
129129 if (mq->err_send)
130130 return mq->err_send;
131− av_fifo_generic_write(mq->fifo, msg, mq->elsize, NULL);
131+ av_fifo_write(mq->fifo, msg, 1);
132132 /* one message is sent, signal one receiver */
133133 pthread_cond_signal(&mq->cond_recv);
134134 return 0;
@@ -138,14 +138,14 @@ static int av_thread_message_queue_recv_locked(AVThreadMessageQueue *mq, · 3 unmodified lines
138138 void *msg,
139139 unsigned flags)
140140 {
141− while (!mq->err_recv && av_fifo_size(mq->fifo) < mq->elsize) {
141+ while (!mq->err_recv && !av_fifo_can_read(mq->fifo)) {
142142 if ((flags & AV_THREAD_MESSAGE_NONBLOCK))
143143 return AVERROR(EAGAIN);
144144 pthread_cond_wait(&mq->cond_recv, &mq->lock);
145145 }
146− if (av_fifo_size(mq->fifo) < mq->elsize)
146+ if (!av_fifo_can_read(mq->fifo))
147147 return mq->err_recv;
148− av_fifo_generic_read(mq->fifo, msg, mq->elsize, NULL);
148+ av_fifo_read(mq->fifo, msg, 1);
149149 /* one message space appeared, signal one sender */
150150 pthread_cond_signal(&mq->cond_send);
151151 return 0;
@@ -208,25 +208,25 @@ void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, · 56 unmodified lines
208208 }
209209
210210 #if HAVE_THREADS
211−static void free_func_wrap(void *arg, void *msg, int size)
211+static int free_func_wrap(void *arg, void *buf, size_t *nb_elems)
212212 {
213213 AVThreadMessageQueue *mq = arg;
214− mq->free_func(msg);
214+ uint8_t *msg = buf;
215+ for (size_t i = 0; i < *nb_elems; i++)
216+ mq->free_func(msg + i * mq->elsize);
217+ return 0;
215218 }
216219 #endif
217220
218221 void av_thread_message_flush(AVThreadMessageQueue *mq)
219222 {
220223 #if HAVE_THREADS
221− int used, off;
222− void *free_func = mq->free_func;
224+ size_t used;
223225
224226 pthread_mutex_lock(&mq->lock);
225− used = av_fifo_size(mq->fifo);
226− if (free_func)
227− for (off = 0; off < used; off += mq->elsize)
228− av_fifo_generic_peek_at(mq->fifo, mq, off, mq->elsize, free_func_wrap);
229− av_fifo_drain(mq->fifo, used);
227+ used = av_fifo_can_read(mq->fifo);
228+ if (mq->free_func)
229+ av_fifo_read_to_cb(mq->fifo, free_func_wrap, mq, &used);
230230 /* only the senders need to be notified since the queue is empty and there
231231 * is nothing to read */
232232 pthread_cond_broadcast(&mq->cond_send);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t