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

git at videolan.org git at videolan.org
Sat Jun 5 12:35:09 CEST 2010


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

vlc_global_mutex: common functions for process-wide mutexes

(cherry picked from commit e3c350269cf1b482d2f6842e5b31a83be27a1c40)
(kept core part only to minimize changes)

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

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

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 3caa97d..88226cd 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -430,4 +430,12 @@ class vlc_mutex_locker
 };
 #endif
 
+enum {
+   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 e618f92..c4c5a41 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -544,6 +544,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..04e83e8 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -233,3 +233,22 @@ 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[] = {
+    };
+    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