[02/10] avcodec: Allow locking and unlocking an avformat specific mutex

Message ID 1320154365-10834-2-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö Nov. 1, 2011, 1:32 p.m.
This extends the lock manager in avcodec to manage two separate
mutexes via the user-specified lock functions.
---
 libavcodec/internal.h |    3 +++
 libavcodec/utils.c    |   23 +++++++++++++++++++++++
 libavcodec/version.h  |    2 +-
 3 files changed, 27 insertions(+), 1 deletions(-)

Comments

Luca Barbato Nov. 4, 2011, 8:31 p.m. | #1
On 11/1/11 6:32 AM, Martin Storsjö wrote:
> This extends the lock manager in avcodec to manage two separate
> mutexes via the user-specified lock functions.

Ok, let's think about moving them somewhere else later.

Patch

diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index e676148..54d57d2 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -55,4 +55,7 @@  int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b);
 
 unsigned int avpriv_toupper4(unsigned int x);
 
+int avpriv_lock_avformat(void);
+int avpriv_unlock_avformat(void);
+
 #endif /* AVCODEC_INTERNAL_H */
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 35c9eeb..cd8dce9 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -48,6 +48,7 @@ 
 static int volatile entangled_thread_counter=0;
 static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
 static void *codec_mutex;
+static void *avformat_mutex;
 
 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
 {
@@ -1270,6 +1271,8 @@  int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
     if (ff_lockmgr_cb) {
         if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
             return -1;
+        if (ff_lockmgr_cb(&avformat_mutex, AV_LOCK_DESTROY))
+            return -1;
     }
 
     ff_lockmgr_cb = cb;
@@ -1277,6 +1280,26 @@  int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
     if (ff_lockmgr_cb) {
         if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
             return -1;
+        if (ff_lockmgr_cb(&avformat_mutex, AV_LOCK_CREATE))
+            return -1;
+    }
+    return 0;
+}
+
+int avpriv_lock_avformat(void)
+{
+    if (ff_lockmgr_cb) {
+        if ((*ff_lockmgr_cb)(&avformat_mutex, AV_LOCK_OBTAIN))
+            return -1;
+    }
+    return 0;
+}
+
+int avpriv_unlock_avformat(void)
+{
+    if (ff_lockmgr_cb) {
+        if ((*ff_lockmgr_cb)(&avformat_mutex, AV_LOCK_RELEASE))
+            return -1;
     }
     return 0;
 }
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 65cc559..3fc418e 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -21,7 +21,7 @@ 
 #define AVCODEC_VERSION_H
 
 #define LIBAVCODEC_VERSION_MAJOR 53
-#define LIBAVCODEC_VERSION_MINOR 15
+#define LIBAVCODEC_VERSION_MINOR 16
 #define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \