History

lavu/threadmessage: add av_thread_message_queue_nb_elems()

Clément Bœsch committed 8 years ago

Commit 71fa82b1 parent 02e49705 files · +28 −2Browse files

Unified · Split

5 files
  1. doc/APIchanges +3 −0
  2. libavutil/threadmessage.c +13 −0
  3. libavutil/threadmessage.h +8 −0
  4. libavutil/version.h +1 −1
  5. tests/api/api-threadmessage-test.c +3 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2017-10-21 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2018-04-xx - xxxxxxxxxx - lavu 56.16.100 - threadmessage.h
19+ Add av_thread_message_queue_nb_elems().
20+
1821 -------- 8< --------- FFmpeg 4.0 was cut here -------- 8< ---------
1922
2023 2018-04-03 - d6fc031caf - lavu 56.13.100 - pixdesc.h
libavutil/threadmessage.c+13−0
@@ -102,6 +102,19 @@ void av_thread_message_queue_free(AVThreadMessageQueue **mq) · 101 unmodified lines
102102 #endif
103103 }
104104
105+int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq)
106+{
107+#if HAVE_THREADS
108+ int ret;
109+ pthread_mutex_lock(&mq->lock);
110+ ret = av_fifo_size(mq->fifo);
111+ pthread_mutex_unlock(&mq->lock);
112+ return ret / mq->elsize;
113+#else
114+ return AVERROR(ENOSYS);
115+#endif
116+}
117+
105118 #if HAVE_THREADS
106119
107120 static int av_thread_message_queue_send_locked(AVThreadMessageQueue *mq,
libavutil/threadmessage.h+8−0
@@ -95,6 +95,14 @@ void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, · 94 unmodified lines
9595 void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq,
9696 void (*free_func)(void *msg));
9797
98+/**
99+ * Return the current number of messages in the queue.
100+ *
101+ * @return the current number of messages or AVERROR(ENOSYS) if lavu was built
102+ * without thread support
103+ */
104+int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq);
105+
98106 /**
99107 * Flush the message queue
100108 *
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
7979 */
8080
8181 #define LIBAVUTIL_VERSION_MAJOR 56
82−#define LIBAVUTIL_VERSION_MINOR 15
82+#define LIBAVUTIL_VERSION_MINOR 16
8383 #define LIBAVUTIL_VERSION_MICRO 100
8484
8585 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
tests/api/api-threadmessage-test.c+3−1
@@ -130,7 +130,9 @@ static void *receiver_thread(void *arg) · 129 unmodified lines
130130
131131 for (i = 0; i < rd->workload; i++) {
132132 if (rand() % rd->workload < rd->workload / 10) {
133− av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue\n", rd->id);
133+ av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue, "
134+ "discarding %d message(s)\n", rd->id,
135+ av_thread_message_queue_nb_elems(rd->queue));
134136 av_thread_message_flush(rd->queue);
135137 } else {
136138 struct message msg;

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