1 /*
2 * Copyright (c) 2014 Nicolas George
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
22 #include <stddef.h>
23
29
31 #if HAVE_THREADS
36 int err_send;
37 int err_recv;
38 unsigned elsize;
39 void (*free_func)(void *msg);
40 #else
42 #endif
43 };
44
46 unsigned nelem,
47 unsigned elsize)
48 {
49 #if HAVE_THREADS
52
53 if (nelem > INT_MAX / elsize)
60 }
65 }
71 }
78 }
79 rmq->elsize = elsize;
80 *mq = rmq;
81 return 0;
82 #else
85 #endif /* HAVE_THREADS */
86 }
87
89 void (*free_func)(void *msg))
90 {
91 #if HAVE_THREADS
92 mq->free_func = free_func;
93 #endif
94 }
95
97 {
98 #if HAVE_THREADS
99 if (*mq) {
106 }
107 #endif
108 }
109
111 {
112 #if HAVE_THREADS
118 #else
120 #endif
121 }
122
123 #if HAVE_THREADS
124
126 void *msg,
128 {
133 }
134 if (mq->err_send)
135 return mq->err_send;
137 /* one message is sent, signal one receiver */
139 return 0;
140 }
141
143 void *msg,
145 {
150 }
152 return mq->err_recv;
154 /* one message space appeared, signal one sender */
156 return 0;
157 }
158
159 #endif /* HAVE_THREADS */
160
162 void *msg,
164 {
165 #if HAVE_THREADS
167
169 ret = av_thread_message_queue_send_locked(mq, msg,
flags);
172 #else
174 #endif /* HAVE_THREADS */
175 }
176
178 void *msg,
180 {
181 #if HAVE_THREADS
183
185 ret = av_thread_message_queue_recv_locked(mq, msg,
flags);
188 #else
190 #endif /* HAVE_THREADS */
191 }
192
194 int err)
195 {
196 #if HAVE_THREADS
198 mq->err_send = err;
201 #endif /* HAVE_THREADS */
202 }
203
205 int err)
206 {
207 #if HAVE_THREADS
209 mq->err_recv = err;
212 #endif /* HAVE_THREADS */
213 }
214
215 #if HAVE_THREADS
216 static int free_func_wrap(
void *
arg,
void *buf,
size_t *nb_elems)
217 {
219 uint8_t *msg = buf;
220 for (
size_t i = 0;
i < *nb_elems;
i++)
221 mq->free_func(msg +
i * mq->elsize);
222 return 0;
223 }
224 #endif
225
227 {
228 #if HAVE_THREADS
229 size_t used;
230
233 if (mq->free_func)
235 /* only the senders need to be notified since the queue is empty and there
236 * is nothing to read */
239 #endif /* HAVE_THREADS */
240 }