| 43 | }; |
| 44 | |
| 45 | int av_thread_message_queue_alloc(AVThreadMessageQueue **mq, |
| 46 | unsigned nelem, |
| 47 | unsigned elsize) |
| 48 | { |
| 49 | #if HAVE_THREADS |
| 50 | AVThreadMessageQueue *rmq; |
| 51 | int ret = 0; |
| 52 | |
| 53 | if (nelem > INT_MAX / elsize) |
| 54 | return AVERROR(EINVAL); |
| 55 | if (!(rmq = av_mallocz(sizeof(*rmq)))) |
| 56 | return AVERROR(ENOMEM); |
| 57 | if ((ret = pthread_mutex_init(&rmq->lock, NULL))) { |
| 58 | av_free(rmq); |
| 59 | return AVERROR(ret); |
| 60 | } |
| 61 | if ((ret = pthread_cond_init(&rmq->cond_recv, NULL))) { |
| 62 | pthread_mutex_destroy(&rmq->lock); |
| 63 | av_free(rmq); |
| 64 | return AVERROR(ret); |
| 65 | } |
| 66 | if ((ret = pthread_cond_init(&rmq->cond_send, NULL))) { |
| 67 | pthread_cond_destroy(&rmq->cond_recv); |
| 68 | pthread_mutex_destroy(&rmq->lock); |
| 69 | av_free(rmq); |
| 70 | return AVERROR(ret); |
| 71 | } |
| 72 | if (!(rmq->fifo = av_fifo_alloc2(nelem, elsize, 0))) { |
| 73 | pthread_cond_destroy(&rmq->cond_send); |
| 74 | pthread_cond_destroy(&rmq->cond_recv); |
| 75 | pthread_mutex_destroy(&rmq->lock); |
| 76 | av_free(rmq); |
| 77 | return AVERROR(ENOMEM); |
| 78 | } |
| 79 | rmq->elsize = elsize; |
| 80 | *mq = rmq; |
| 81 | return 0; |
| 82 | #else |
| 83 | *mq = NULL; |
| 84 | return AVERROR(ENOSYS); |
| 85 | #endif /* HAVE_THREADS */ |
| 86 | } |
| 87 | |
| 88 | void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq, |
| 89 | void (*free_func)(void *msg)) |