[vlc-commits] Make log messages subscriber static

Rémi Denis-Courmont git at videolan.org
Fri Aug 19 23:00:12 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Aug 19 21:03:08 2011 +0300| [9ffae683ff9e79eee3a3c4d9ca3ed3e6010d6034] | committer: Rémi Denis-Courmont

Make log messages subscriber static

In other words, the message callbacks are now shared across all LibVLC
instances. That is a requirement to enable:
 - LibVLC applications to catch messages during LibVLC init/deinit,
 - emitting log messages when no VLC object point is available.

That makes no difference for VLC interfaces, since there is only one
LibVLC instances in a VLC process.

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

 src/libvlc.c        |   10 ------
 src/libvlc.h        |   10 ------
 src/misc/messages.c |   87 +++++++++++++--------------------------------------
 src/win32/thread.c  |    4 ++-
 4 files changed, 25 insertions(+), 86 deletions(-)

diff --git a/src/libvlc.c b/src/libvlc.c
index 91c86fa..e40db76 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -212,11 +212,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
     priv->p_dialog_provider = NULL;
     priv->p_vlm = NULL;
 
-    /* Initialize message queue */
-    priv->msg_bank = msg_Create ();
-    if (unlikely(priv->msg_bank == NULL))
-        goto error;
-
     /* Find verbosity from VLC_VERBOSE environment variable */
     psz_env = getenv( "VLC_VERBOSE" );
     if( psz_env != NULL )
@@ -235,9 +230,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
     vlc_ExitInit( &priv->exit );
 
     return p_libvlc;
-error:
-    vlc_object_release (p_libvlc);
-    return NULL;
 }
 
 /**
@@ -1049,8 +1041,6 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
     }
     vlc_mutex_unlock( &global_lock );
 
-    msg_Destroy (priv->msg_bank);
-
     /* Destroy mutexes */
     vlc_ExitDestroy( &priv->exit );
     vlc_mutex_destroy( &priv->timer_lock );
diff --git a/src/libvlc.h b/src/libvlc.h
index 6cd275b..ebb97ea 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -70,15 +70,6 @@ extern uint32_t cpu_flags;
 uint32_t CPUCapabilities( void );
 
 /*
- * Message/logging stuff
- */
-
-typedef struct msg_bank_t msg_bank_t;
-
-msg_bank_t *msg_Create (void);
-void msg_Destroy (msg_bank_t *);
-
-/*
  * LibVLC exit event handling
  */
 typedef struct vlc_exit
@@ -182,7 +173,6 @@ typedef struct libvlc_priv_t
     bool               playlist_active;
 
     /* Messages */
-    msg_bank_t        *msg_bank;    ///< The message bank
     int                i_verbose;   ///< info messages
     bool               b_color;     ///< color messages?
 
diff --git a/src/misc/messages.c b/src/misc/messages.c
index b03d95c..93fcee5 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -51,11 +51,6 @@
 #include <vlc_charset.h>
 #include "../libvlc.h"
 
-static inline msg_bank_t *libvlc_bank (libvlc_int_t *inst)
-{
-    return (libvlc_priv (inst))->msg_bank;
-}
-
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -64,49 +59,12 @@ static void PrintMsg ( vlc_object_t *, const msg_item_t * );
 /**
  * Store all data required by messages interfaces.
  */
-struct msg_bank_t
-{
-    /** Message queue lock */
-    vlc_rwlock_t lock;
-
-    /* Subscribers */
-    int i_sub;
-    msg_subscription_t **pp_sub;
-};
-
-/**
- * Initialize messages queues
- * This function initializes all message queues
- */
-msg_bank_t *msg_Create (void)
-{
-    msg_bank_t *bank = malloc (sizeof (*bank));
-
-    vlc_rwlock_init (&bank->lock);
-    bank->i_sub = 0;
-    bank->pp_sub = NULL;
-    return bank;
-}
-
-/**
- * Destroy the message queues
- *
- * This functions prints all messages remaining in the queues,
- * then frees all the allocated resources
- * No other messages interface functions should be called after this one.
- */
-void msg_Destroy (msg_bank_t *bank)
-{
-    if (unlikely(bank->i_sub != 0))
-        fputs ("stale interface subscribers (LibVLC might crash)\n", stderr);
-
-    vlc_rwlock_destroy (&bank->lock);
-    free (bank);
-}
+vlc_rwlock_t msg_lock = VLC_STATIC_RWLOCK;
+msg_subscription_t *msg_head;
 
 struct msg_subscription_t
 {
-    libvlc_int_t   *instance;
+    msg_subscription_t *prev, *next;
     msg_callback_t  func;
     msg_cb_data_t  *opaque;
 };
@@ -116,7 +74,6 @@ struct msg_subscription_t
  * Whenever a message is emitted, a callback will be called.
  * Callback invocation are serialized within a subscription.
  *
- * @param instance LibVLC instance to get messages from
  * @param cb callback function
  * @param opaque data for the callback function
  * @return a subscription pointer, or NULL in case of failure
@@ -128,14 +85,14 @@ msg_subscription_t *msg_Subscribe (libvlc_int_t *instance, msg_callback_t cb,
     if (sub == NULL)
         return NULL;
 
-    sub->instance = instance;
+    sub->prev = NULL;
     sub->func = cb;
     sub->opaque = opaque;
 
-    msg_bank_t *bank = libvlc_bank (instance);
-    vlc_rwlock_wrlock (&bank->lock);
-    TAB_APPEND (bank->i_sub, bank->pp_sub, sub);
-    vlc_rwlock_unlock (&bank->lock);
+    vlc_rwlock_wrlock (&msg_lock);
+    sub->next = msg_head;
+    msg_head = sub;
+    vlc_rwlock_unlock (&msg_lock);
 
     return sub;
 }
@@ -146,11 +103,17 @@ msg_subscription_t *msg_Subscribe (libvlc_int_t *instance, msg_callback_t cb,
  */
 void msg_Unsubscribe (msg_subscription_t *sub)
 {
-    msg_bank_t *bank = libvlc_bank (sub->instance);
-
-    vlc_rwlock_wrlock (&bank->lock);
-    TAB_REMOVE (bank->i_sub, bank->pp_sub, sub);
-    vlc_rwlock_unlock (&bank->lock);
+    vlc_rwlock_wrlock (&msg_lock);
+    if (sub->next != NULL)
+        sub->next->prev = sub->prev;
+    if (sub->prev != NULL)
+        sub->prev->next = sub->next;
+    else
+    {
+        assert (msg_head == sub);
+        msg_head = sub->next;
+    }
+    vlc_rwlock_unlock (&msg_lock);
     free (sub);
 }
 
@@ -186,8 +149,6 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module,
     if( p_this->i_flags & OBJECT_FLAGS_QUIET )
         return;
 
-    msg_bank_t *bank = libvlc_bank (p_this->p_libvlc);
-
     /* C locale to get error messages in English in the logs */
     locale_t c = newlocale (LC_MESSAGES_MASK, "C", (locale_t)0);
     locale_t locale = uselocale (c);
@@ -277,14 +238,10 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module,
 
     PrintMsg( p_this, &msg );
 
-    vlc_rwlock_rdlock (&bank->lock);
-    for (int i = 0; i < bank->i_sub; i++)
-    {
-        msg_subscription_t *sub = bank->pp_sub[i];
-
+    vlc_rwlock_rdlock (&msg_lock);
+    for (msg_subscription_t *sub = msg_head; sub != NULL; sub = sub->next)
         sub->func (sub->opaque, &msg);
-    }
-    vlc_rwlock_unlock (&bank->lock);
+    vlc_rwlock_unlock (&msg_lock);
 
     if (likely(str != (char *)nomemstr))
         free (str);
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 965db99..a70b15c 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -39,7 +39,6 @@
 #ifdef UNDER_CE
 # include <mmsystem.h>
 #endif
-#include "config/configuration.h"
 
 static vlc_threadvar_t thread_key;
 
@@ -64,6 +63,7 @@ struct vlc_thread
 
 static CRITICAL_SECTION super_mutex;
 static HANDLE           super_cond;
+extern vlc_rwlock_t config_lock, msg_lock;
 
 BOOL WINAPI DllMain (HINSTANCE, DWORD, LPVOID);
 
@@ -81,9 +81,11 @@ BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
             InitializeCriticalSection (&super_mutex);
             vlc_threadvar_create (&thread_key, NULL);
             vlc_rwlock_init (&config_lock);
+            vlc_rwlock_init (&msg_lock);
             break;
 
         case DLL_PROCESS_DETACH:
+            vlc_rwlock_destroy (&msg_lock);
             vlc_rwlock_destroy (&config_lock);
             vlc_threadvar_delete (&thread_key);
             DeleteCriticalSection (&super_mutex);



More information about the vlc-commits mailing list