[vlc-devel] commit: Lock 'msg_bank' when creating and destroying. (Jean-Paul Saman )
git version control
git at videolan.org
Mon Oct 27 16:23:27 CET 2008
vlc | branch: 0.8.6-bugfix | Jean-Paul Saman <jpsaman at videolan.org> | Tue Oct 21 10:37:53 2008 +0200| [2a71fc44ed626204032adb5f2ee5ef330cf6fe3b] | committer: Jean-Paul Saman
Lock 'msg_bank' when creating and destroying.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2a71fc44ed626204032adb5f2ee5ef330cf6fe3b
---
src/misc/messages.c | 24 +++++++++++++++++-------
1 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/misc/messages.c b/src/misc/messages.c
index 31d4d4e..5aca681 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -74,7 +74,7 @@ static void CreateMsgQueue( vlc_object_t *p_this, int i_queue );
void __msg_Create( vlc_object_t *p_this )
{
vlc_mutex_init( p_this, &(p_this->p_libvlc->msg_bank.lock) );
-
+ vlc_mutex_lock( &(p_this->p_libvlc->msg_bank.lock) );
CreateMsgQueue( p_this, MSG_QUEUE_NORMAL );
CreateMsgQueue( p_this, MSG_QUEUE_HTTPD_ACCESS );
@@ -86,7 +86,7 @@ void __msg_Create( vlc_object_t *p_this )
SetFilePointer( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->
logfile, 0, NULL, FILE_END );
#endif
-
+ vlc_mutex_unlock( &(p_this->p_libvlc->msg_bank.lock) );
}
static void CreateMsgQueue( vlc_object_t *p_this, int i_queue )
@@ -134,6 +134,8 @@ void __msg_Flush( vlc_object_t *p_this )
void __msg_Destroy( vlc_object_t *p_this )
{
int i;
+
+ vlc_mutex_lock( &(p_this->p_libvlc->msg_bank.lock) );
for( i = p_this->p_libvlc->msg_bank.i_queues -1 ; i >= 0; i-- )
{
msg_queue_t *p_queue = p_this->p_libvlc->msg_bank.pp_queues[i];
@@ -141,8 +143,9 @@ void __msg_Destroy( vlc_object_t *p_this )
{
msg_Err( p_this, "stale interface subscribers" );
}
+ vlc_mutex_lock( &p_queue->lock );
FlushMsg( p_queue );
-
+ vlc_mutex_unlock( &p_queue->lock );
#ifdef UNDER_CE
if( i == MSG_QUEUE_NORMAL )
CloseHandle( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile );
@@ -152,7 +155,9 @@ void __msg_Destroy( vlc_object_t *p_this )
REMOVE_ELEM( p_this->p_libvlc->msg_bank.pp_queues,
p_this->p_libvlc->msg_bank.i_queues, i );
free( p_queue );
+ p_queue = NULL;
}
+ vlc_mutex_unlock( &(p_this->p_libvlc->msg_bank.lock) );
vlc_mutex_destroy( &(p_this->p_libvlc->msg_bank.lock) );
}
@@ -348,6 +353,11 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
}
p_bank = &p_this->p_libvlc->msg_bank;
+ if( p_bank->i_queues <= 0 )
+ {
+ return;
+ }
+ vlc_mutex_lock( &p_bank->lock );
/*
* Convert message to string
@@ -369,6 +379,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
vfprintf( stderr, psz_format, args );
va_end( args );
fputs( "\n", stderr );
+ vlc_mutex_unlock( &p_bank->lock );
return;
}
@@ -407,8 +418,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
#endif
/* Put message in queue */
- vlc_mutex_lock( &p_bank->lock );
- for( i = 0 ; i <p_bank->i_queues ;i++ )
+ for( i = 0 ; i < p_bank->i_queues ;i++ )
{
if( p_bank->pp_queues[i]->i_id == i_queue_id )
{
@@ -418,9 +428,9 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
if( p_queue == NULL )
{
- vlc_mutex_unlock( &p_bank->lock );
if( psz_str ) free( psz_str );
if( psz_header ) free( psz_header );
+ vlc_mutex_unlock( &p_bank->lock );
return;
}
@@ -498,7 +508,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
free( p_item->psz_header );
}
- vlc_mutex_unlock ( &p_queue->lock );
+ vlc_mutex_unlock( &p_queue->lock );
vlc_mutex_unlock( &p_bank->lock );
}
More information about the vlc-devel
mailing list