Commit 9ffae683 authored by Rémi Denis-Courmont's avatar 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.
parent f1c5ba55
...@@ -212,11 +212,6 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -212,11 +212,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
priv->p_dialog_provider = NULL; priv->p_dialog_provider = NULL;
priv->p_vlm = 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 */ /* Find verbosity from VLC_VERBOSE environment variable */
psz_env = getenv( "VLC_VERBOSE" ); psz_env = getenv( "VLC_VERBOSE" );
if( psz_env != NULL ) if( psz_env != NULL )
...@@ -235,9 +230,6 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -235,9 +230,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
vlc_ExitInit( &priv->exit ); vlc_ExitInit( &priv->exit );
return p_libvlc; return p_libvlc;
error:
vlc_object_release (p_libvlc);
return NULL;
} }
/** /**
...@@ -1049,8 +1041,6 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc ) ...@@ -1049,8 +1041,6 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
} }
vlc_mutex_unlock( &global_lock ); vlc_mutex_unlock( &global_lock );
msg_Destroy (priv->msg_bank);
/* Destroy mutexes */ /* Destroy mutexes */
vlc_ExitDestroy( &priv->exit ); vlc_ExitDestroy( &priv->exit );
vlc_mutex_destroy( &priv->timer_lock ); vlc_mutex_destroy( &priv->timer_lock );
......
...@@ -69,15 +69,6 @@ void vlc_assert_locked (vlc_mutex_t *); ...@@ -69,15 +69,6 @@ void vlc_assert_locked (vlc_mutex_t *);
extern uint32_t cpu_flags; extern uint32_t cpu_flags;
uint32_t CPUCapabilities( void ); 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 * LibVLC exit event handling
*/ */
...@@ -182,7 +173,6 @@ typedef struct libvlc_priv_t ...@@ -182,7 +173,6 @@ typedef struct libvlc_priv_t
bool playlist_active; bool playlist_active;
/* Messages */ /* Messages */
msg_bank_t *msg_bank; ///< The message bank
int i_verbose; ///< info messages int i_verbose; ///< info messages
bool b_color; ///< color messages? bool b_color; ///< color messages?
......
...@@ -51,11 +51,6 @@ ...@@ -51,11 +51,6 @@
#include <vlc_charset.h> #include <vlc_charset.h>
#include "../libvlc.h" #include "../libvlc.h"
static inline msg_bank_t *libvlc_bank (libvlc_int_t *inst)
{
return (libvlc_priv (inst))->msg_bank;
}
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
...@@ -64,49 +59,12 @@ static void PrintMsg ( vlc_object_t *, const msg_item_t * ); ...@@ -64,49 +59,12 @@ static void PrintMsg ( vlc_object_t *, const msg_item_t * );
/** /**
* Store all data required by messages interfaces. * Store all data required by messages interfaces.
*/ */
struct msg_bank_t vlc_rwlock_t msg_lock = VLC_STATIC_RWLOCK;
{ msg_subscription_t *msg_head;
/** 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);
}
struct msg_subscription_t struct msg_subscription_t
{ {
libvlc_int_t *instance; msg_subscription_t *prev, *next;
msg_callback_t func; msg_callback_t func;
msg_cb_data_t *opaque; msg_cb_data_t *opaque;
}; };
...@@ -116,7 +74,6 @@ struct msg_subscription_t ...@@ -116,7 +74,6 @@ struct msg_subscription_t
* Whenever a message is emitted, a callback will be called. * Whenever a message is emitted, a callback will be called.
* Callback invocation are serialized within a subscription. * Callback invocation are serialized within a subscription.
* *
* @param instance LibVLC instance to get messages from
* @param cb callback function * @param cb callback function
* @param opaque data for the callback function * @param opaque data for the callback function
* @return a subscription pointer, or NULL in case of failure * @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, ...@@ -128,14 +85,14 @@ msg_subscription_t *msg_Subscribe (libvlc_int_t *instance, msg_callback_t cb,
if (sub == NULL) if (sub == NULL)
return NULL; return NULL;
sub->instance = instance; sub->prev = NULL;
sub->func = cb; sub->func = cb;
sub->opaque = opaque; sub->opaque = opaque;
msg_bank_t *bank = libvlc_bank (instance); vlc_rwlock_wrlock (&msg_lock);
vlc_rwlock_wrlock (&bank->lock); sub->next = msg_head;
TAB_APPEND (bank->i_sub, bank->pp_sub, sub); msg_head = sub;
vlc_rwlock_unlock (&bank->lock); vlc_rwlock_unlock (&msg_lock);
return sub; return sub;
} }
...@@ -146,11 +103,17 @@ msg_subscription_t *msg_Subscribe (libvlc_int_t *instance, msg_callback_t cb, ...@@ -146,11 +103,17 @@ msg_subscription_t *msg_Subscribe (libvlc_int_t *instance, msg_callback_t cb,
*/ */
void msg_Unsubscribe (msg_subscription_t *sub) void msg_Unsubscribe (msg_subscription_t *sub)
{ {
msg_bank_t *bank = libvlc_bank (sub->instance); vlc_rwlock_wrlock (&msg_lock);
if (sub->next != NULL)
vlc_rwlock_wrlock (&bank->lock); sub->next->prev = sub->prev;
TAB_REMOVE (bank->i_sub, bank->pp_sub, sub); if (sub->prev != NULL)
vlc_rwlock_unlock (&bank->lock); sub->prev->next = sub->next;
else
{
assert (msg_head == sub);
msg_head = sub->next;
}
vlc_rwlock_unlock (&msg_lock);
free (sub); free (sub);
} }
...@@ -186,8 +149,6 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module, ...@@ -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 ) if( p_this->i_flags & OBJECT_FLAGS_QUIET )
return; return;
msg_bank_t *bank = libvlc_bank (p_this->p_libvlc);
/* C locale to get error messages in English in the logs */ /* C locale to get error messages in English in the logs */
locale_t c = newlocale (LC_MESSAGES_MASK, "C", (locale_t)0); locale_t c = newlocale (LC_MESSAGES_MASK, "C", (locale_t)0);
locale_t locale = uselocale (c); locale_t locale = uselocale (c);
...@@ -277,14 +238,10 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module, ...@@ -277,14 +238,10 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, const char *psz_module,
PrintMsg( p_this, &msg ); PrintMsg( p_this, &msg );
vlc_rwlock_rdlock (&bank->lock); vlc_rwlock_rdlock (&msg_lock);
for (int i = 0; i < bank->i_sub; i++) for (msg_subscription_t *sub = msg_head; sub != NULL; sub = sub->next)
{
msg_subscription_t *sub = bank->pp_sub[i];
sub->func (sub->opaque, &msg); sub->func (sub->opaque, &msg);
} vlc_rwlock_unlock (&msg_lock);
vlc_rwlock_unlock (&bank->lock);
if (likely(str != (char *)nomemstr)) if (likely(str != (char *)nomemstr))
free (str); free (str);
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#ifdef UNDER_CE #ifdef UNDER_CE
# include <mmsystem.h> # include <mmsystem.h>
#endif #endif
#include "config/configuration.h"
static vlc_threadvar_t thread_key; static vlc_threadvar_t thread_key;
...@@ -64,6 +63,7 @@ struct vlc_thread ...@@ -64,6 +63,7 @@ struct vlc_thread
static CRITICAL_SECTION super_mutex; static CRITICAL_SECTION super_mutex;
static HANDLE super_cond; static HANDLE super_cond;
extern vlc_rwlock_t config_lock, msg_lock;
BOOL WINAPI DllMain (HINSTANCE, DWORD, LPVOID); BOOL WINAPI DllMain (HINSTANCE, DWORD, LPVOID);
...@@ -81,9 +81,11 @@ BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) ...@@ -81,9 +81,11 @@ BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
InitializeCriticalSection (&super_mutex); InitializeCriticalSection (&super_mutex);
vlc_threadvar_create (&thread_key, NULL); vlc_threadvar_create (&thread_key, NULL);
vlc_rwlock_init (&config_lock); vlc_rwlock_init (&config_lock);
vlc_rwlock_init (&msg_lock);
break; break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
vlc_rwlock_destroy (&msg_lock);
vlc_rwlock_destroy (&config_lock); vlc_rwlock_destroy (&config_lock);
vlc_threadvar_delete (&thread_key); vlc_threadvar_delete (&thread_key);
DeleteCriticalSection (&super_mutex); DeleteCriticalSection (&super_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment