Gradient: callback thread-safety
authorRémi Denis-Courmont <remi@remlab.net>
Tue, 19 May 2009 17:21:04 +0000 (20:21 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 19 May 2009 17:59:07 +0000 (20:59 +0300)
modules/video_filter/gradient.c

index c875bd1..948cb4a 100644 (file)
@@ -108,6 +108,7 @@ static const char *const ppsz_filter_options[] = {
  *****************************************************************************/
 struct filter_sys_t
 {
+    vlc_mutex_t lock;
     int i_mode;
 
     /* For the gradient mode */
@@ -189,6 +190,7 @@ static int Create( vlc_object_t *p_this )
     p_filter->p_sys->b_cartoon =
         var_CreateGetBoolCommand( p_filter, FILTER_PREFIX "cartoon" );
 
+    vlc_mutex_init( &p_filter->p_sys->lock );
     var_AddCallback( p_filter, FILTER_PREFIX "mode",
                      GradientCallback, p_filter->p_sys );
     var_AddCallback( p_filter, FILTER_PREFIX "type",
@@ -211,13 +213,22 @@ static int Create( vlc_object_t *p_this )
 static void Destroy( vlc_object_t *p_this )
 {
     filter_t *p_filter = (filter_t *)p_this;
-
-    free( p_filter->p_sys->p_buf32 );
-    free( p_filter->p_sys->p_buf32_bis );
-    free( p_filter->p_sys->p_buf8 );
-    free( p_filter->p_sys->p_pre_hough );
-
-    free( p_filter->p_sys );
+    filter_sys_t *p_sys = p_filter->p_sys;
+
+    var_DelCallback( p_filter, FILTER_PREFIX "mode",
+                     GradientCallback, p_sys );
+    var_DelCallback( p_filter, FILTER_PREFIX "type",
+                     GradientCallback, p_sys );
+    var_DelCallback( p_filter, FILTER_PREFIX "cartoon",
+                     GradientCallback, p_sys );
+    vlc_mutex_destroy( &p_sys->lock );
+
+    free( p_sys->p_buf32 );
+    free( p_sys->p_buf32_bis );
+    free( p_sys->p_buf8 );
+    free( p_sys->p_pre_hough );
+
+    free( p_sys );
 }
 
 /*****************************************************************************
@@ -240,6 +251,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         return NULL;
     }
 
+    vlc_mutex_lock( &p_filter->p_sys->lock );
     switch( p_filter->p_sys->i_mode )
     {
         case EDGE:
@@ -257,6 +269,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         default:
             break;
     }
+    vlc_mutex_unlock( &p_filter->p_sys->lock );
 
     return CopyInfoAndRelease( p_outpic, p_pic );
 }
@@ -757,6 +770,8 @@ static int GradientCallback( vlc_object_t *p_this, char const *psz_var,
 {
     VLC_UNUSED(oldval);
     filter_sys_t *p_sys = (filter_sys_t *)p_data;
+
+    vlc_mutex_lock( &p_sys->lock );
     if( !strcmp( psz_var, FILTER_PREFIX "mode" ) )
     {
         if( !strcmp( newval.psz_string, "gradient" ) )
@@ -785,5 +800,7 @@ static int GradientCallback( vlc_object_t *p_this, char const *psz_var,
     {
         p_sys->b_cartoon = newval.b_bool;
     }
+    vlc_mutex_unlock( &p_sys->lock );
+
     return VLC_SUCCESS;
 }