MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / av_thread_message_queue_alloc

Function av_thread_message_queue_alloc

libavutil/threadmessage.c:45–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43};
44
45int 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
88void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq,
89 void (*free_func)(void *msg))

Callers 4

fifo_initFunction · 0.85
sch_add_decFunction · 0.85
mainFunction · 0.85

Calls 7

av_fifo_alloc2Function · 0.85
av_malloczFunction · 0.70
av_freeFunction · 0.70
pthread_mutex_initFunction · 0.50
pthread_cond_initFunction · 0.50
pthread_mutex_destroyFunction · 0.50
pthread_cond_destroyFunction · 0.50

Tested by 1

mainFunction · 0.68