[vlc-commits] commit: vlc_global_mutex: common functions for process-wide mutexes ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Thu Jun 3 22:55:52 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jun  3 23:25:31 2010 +0300| [e3c350269cf1b482d2f6842e5b31a83be27a1c40] | committer: Rémi Denis-Courmont 

vlc_global_mutex: common functions for process-wide mutexes

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e3c350269cf1b482d2f6842e5b31a83be27a1c40
---

 include/vlc_threads.h |   10 ++++++++++
 src/libvlccore.sym    |    1 +
 src/misc/threads.c    |   21 +++++++++++++++++++++
 3 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index e9d1c8d..5d9ab65 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -442,4 +442,14 @@ class vlc_mutex_locker
 };
 #endif
 
+enum {
+   VLC_AVCODEC_MUTEX = 0,
+   VLC_GCRYPT_MUTEX,
+   VLC_MAX_MUTEX
+};
+
+VLC_EXPORT( void, vlc_global_mutex, ( unsigned, bool ) );
+#define vlc_global_lock( n ) vlc_global_mutex( n, true )
+#define vlc_global_unlock( n ) vlc_global_mutex( n, false )
+
 #endif /* !_VLC_THREADS_H */
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index d8cd222..bb3ad12 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -551,6 +551,7 @@ vlc_mutex_init_recursive
 vlc_mutex_lock
 vlc_mutex_trylock
 vlc_mutex_unlock
+vlc_global_mutex
 vlc_object_attach
 vlc_object_create
 vlc_object_find
diff --git a/src/misc/threads.c b/src/misc/threads.c
index 5099041..ba93c1b 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -233,3 +233,24 @@ void vlc_thread_cancel (vlc_object_t *obj)
     if (priv->b_thread)
         vlc_cancel (priv->thread_id);
 }
+
+/*** Global locks ***/
+
+void vlc_global_mutex (unsigned n, bool acquire)
+{
+    static vlc_mutex_t locks[] = {
+        VLC_STATIC_MUTEX,
+        VLC_STATIC_MUTEX,
+    };
+    assert (n < (sizeof (locks) / sizeof (locks[0])));
+    vlc_mutex_t *lock = locks + n;
+
+    if (acquire)
+        vlc_mutex_lock (lock);
+    else
+        vlc_mutex_unlock (lock);
+
+    /* Compile-time assertion ;-) */
+    char enough_locks[(sizeof (locks) / sizeof (locks[0])) - VLC_MAX_MUTEX];
+    (void) enough_locks;
+}



More information about the vlc-commits mailing list