lavu/threadmessage: add av_thread_message_queue_nb_elems()
authorClément Bœsch <u@pkh.me>
Sat, 21 Apr 2018 19:42:19 +0000 (21:42 +0200)
committerClément Bœsch <u@pkh.me>
Thu, 26 Apr 2018 17:41:19 +0000 (19:41 +0200)
doc/APIchanges
libavutil/threadmessage.c
libavutil/threadmessage.h
libavutil/version.h
tests/api/api-threadmessage-test.c

index 4f6ac2a..8d305d5 100644 (file)
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2018-04-xx - xxxxxxxxxx - lavu 56.16.100 - threadmessage.h
+  Add av_thread_message_queue_nb_elems().
+
 -------- 8< --------- FFmpeg 4.0 was cut here -------- 8< ---------
 
 2018-04-03 - d6fc031caf - lavu 56.13.100 - pixdesc.h
index 872e939..764b7fb 100644 (file)
@@ -102,6 +102,19 @@ void av_thread_message_queue_free(AVThreadMessageQueue **mq)
 #endif
 }
 
+int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq)
+{
+#if HAVE_THREADS
+    int ret;
+    pthread_mutex_lock(&mq->lock);
+    ret = av_fifo_size(mq->fifo);
+    pthread_mutex_unlock(&mq->lock);
+    return ret / mq->elsize;
+#else
+    return AVERROR(ENOSYS);
+#endif
+}
+
 #if HAVE_THREADS
 
 static int av_thread_message_queue_send_locked(AVThreadMessageQueue *mq,
index 8480a0a..42ce655 100644 (file)
@@ -96,6 +96,14 @@ void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq,
                                            void (*free_func)(void *msg));
 
 /**
+ * Return the current number of messages in the queue.
+ *
+ * @return the current number of messages or AVERROR(ENOSYS) if lavu was built
+ *         without thread support
+ */
+int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq);
+
+/**
  * Flush the message queue
  *
  * This function is mostly equivalent to reading and free-ing every message
index 3874217..2356700 100644 (file)
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  15
+#define LIBAVUTIL_VERSION_MINOR  16
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
index 05a8062..3c693a7 100644 (file)
@@ -130,7 +130,9 @@ static void *receiver_thread(void *arg)
 
     for (i = 0; i < rd->workload; i++) {
         if (rand() % rd->workload < rd->workload / 10) {
-            av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue\n", rd->id);
+            av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue, "
+                   "discarding %d message(s)\n", rd->id,
+                   av_thread_message_queue_nb_elems(rd->queue));
             av_thread_message_flush(rd->queue);
         } else {
             struct message msg;