[vlc-commits] Inline all remaining calls to vlc_cleanup_run()

Rémi Denis-Courmont git at videolan.org
Wed Jul 8 20:16:31 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jul  7 21:47:32 2015 +0300| [901fa0d6c70835c09a60cb0f14fddcf38d6b0670] | committer: Rémi Denis-Courmont

Inline all remaining calls to vlc_cleanup_run()

The code size saving in vlc_cleanup_run() is marginal and premature
optimization. In practice, vlc_cleanup_run() makes the source code
harder to follow/read, confuses static analyzers and generates false
positive clobber warnings (on some OSes due to long jumps).

It did exercise some of the cleanup code paths though.

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

 include/vlc_threads.h            |    3 ++-
 modules/lua/extension_thread.c   |    3 ++-
 modules/stream_filter/decomp.c   |    7 ++++++-
 modules/video_filter/remoteosd.c |    3 ++-
 src/android/thread.c             |   18 +++++++++++-------
 src/input/decoder.c              |    3 ++-
 src/input/es_out_timeshift.c     |    3 ++-
 src/input/vlm.c                  |    3 ++-
 src/misc/addons.c                |    3 ++-
 src/misc/threads.c               |    3 ++-
 10 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 7837827..3437199 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -457,7 +457,8 @@ VLC_API void vlc_cond_broadcast(vlc_cond_t *);
 
    // -- foobar is now true, do something about it here --
 
-   vlc_cleanup_run(); // release the mutex
+   vlc_cleanup_pop();
+   vlc_mutex_unlock(&lock);
   @endcode
  *
  * \note This function is a cancellation point. In case of thread cancellation,
diff --git a/modules/lua/extension_thread.c b/modules/lua/extension_thread.c
index 68c32c5..17d4276 100644
--- a/modules/lua/extension_thread.c
+++ b/modules/lua/extension_thread.c
@@ -428,7 +428,8 @@ static void* Run( void *data )
         vlc_mutex_lock( &p_ext->p_sys->command_lock );
     }
 
-    vlc_cleanup_run( );
+    vlc_cleanup_pop( );
+    vlc_mutex_unlock( &p_ext->p_sys->command_lock );
     msg_Dbg( p_mgr, "Extension thread end: '%s'", p_ext->psz_title );
 
     // Note: At this point, the extension should be deactivated
diff --git a/modules/stream_filter/decomp.c b/modules/stream_filter/decomp.c
index 06435cd..6bddceb 100644
--- a/modules/stream_filter/decomp.c
+++ b/modules/stream_filter/decomp.c
@@ -169,7 +169,12 @@ static void *Thread (void *data)
                 break;
             }
         }
-        vlc_cleanup_run (); /* free (buf) */
+        vlc_cleanup_pop ();
+#ifdef HAVE_VMSPLICE
+        munmap (buf, bufsize);
+#else
+        free (buf);
+#endif
     }
     while (!error);
 
diff --git a/modules/video_filter/remoteosd.c b/modules/video_filter/remoteosd.c
index 47e60d6..1f9715f 100644
--- a/modules/video_filter/remoteosd.c
+++ b/modules/video_filter/remoteosd.c
@@ -807,7 +807,8 @@ static void* update_request_thread( void *obj )
                 break;
             }
         }
-        vlc_cleanup_run();
+        vlc_cleanup_pop();
+        p_filter->p_sys->b_continue = false;
     }
     else
     {
diff --git a/src/android/thread.c b/src/android/thread.c
index d39b29c..b9668d1 100644
--- a/src/android/thread.c
+++ b/src/android/thread.c
@@ -323,11 +323,11 @@ int vlc_cond_timedwait (vlc_cond_t *condvar, vlc_mutex_t *p_mutex,
 /* pthread */
 static void clean_detached_thread(void *data)
 {
-    struct vlc_thread *thread = data;
+    struct vlc_thread *th = data;
 
     /* release thread handle */
-    vlc_mutex_destroy(&thread->lock);
-    free(thread);
+    vlc_mutex_destroy(&th->lock);
+    free(th);
 }
 
 static void *detached_thread(void *data)
@@ -336,9 +336,11 @@ static void *detached_thread(void *data)
 
     thread = th;
 
-    vlc_cleanup_push(clean_detached_thread, data);
+    vlc_cleanup_push(clean_detached_thread, th);
     th->entry(th->data);
-    vlc_cleanup_run();
+    vlc_cleanup_pop();
+    vlc_mutex_destroy(&th->lock);
+    free(th);
 
     return NULL;
 }
@@ -358,7 +360,8 @@ static void *joinable_thread(void *data)
     vlc_cleanup_push(finish_joinable_thread, th);
     thread = th;
     ret = th->entry(th->data);
-    vlc_cleanup_run();
+    vlc_cleanup_pop();
+    vlc_sem_post(&th->finished);
 
     return ret;
 }
@@ -531,7 +534,8 @@ void mwait (mtime_t deadline)
     vlc_mutex_lock (&lock);
     mutex_cleanup_push (&lock);
     while (!vlc_cond_timedwait (&wait, &lock, deadline));
-    vlc_cleanup_run ();
+    vlc_cleanup_pop ();
+    vlc_mutex_unlock (&lock);
 
     vlc_cond_destroy (&wait);
     vlc_mutex_destroy (&lock);
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 68d8e7c..253ca99 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1435,7 +1435,8 @@ static void *DecoderThread( void *p_data )
         }
 
         p_block = vlc_fifo_DequeueUnlocked( p_owner->p_fifo );
-        vlc_cleanup_run();
+        vlc_cleanup_pop();
+        vlc_fifo_Unlock( p_owner->p_fifo );
 
         int canc = vlc_savecancel();
         DecoderProcess( p_dec, p_block );
diff --git a/src/input/es_out_timeshift.c b/src/input/es_out_timeshift.c
index 511ba73..b1d1b75 100644
--- a/src/input/es_out_timeshift.c
+++ b/src/input/es_out_timeshift.c
@@ -1011,7 +1011,8 @@ static void *TsRun( void *p_data )
         }
         i_deadline = cmd.i_date + p_ts->i_cmd_delay + p_ts->i_rate_delay + p_ts->i_buffering_delay;
 
-        vlc_cleanup_run();
+        vlc_cleanup_pop();
+        vlc_mutex_unlock( &p_ts->lock );
 
         /* Regulate the speed of command processing to the same one than
          * reading  */
diff --git a/src/input/vlm.c b/src/input/vlm.c
index cf69ade..86d63f0 100644
--- a/src/input/vlm.c
+++ b/src/input/vlm.c
@@ -412,7 +412,8 @@ static void* Manage( void* p_object )
                 vlc_cond_wait( &vlm->wait_manage, &vlm->lock_manage );
         }
         vlm->input_state_changed = false;
-        vlc_cleanup_run( );
+        vlc_cleanup_pop( );
+        vlc_mutex_unlock( &vlm->lock_manage );
 
         int canc = vlc_savecancel ();
         /* destroy the inputs that wants to die, and launch the next input */
diff --git a/src/misc/addons.c b/src/misc/addons.c
index a625a5c..f581f8c 100644
--- a/src/misc/addons.c
+++ b/src/misc/addons.c
@@ -336,7 +336,8 @@ static void *FinderThread( void *p_data )
         }
         psz_uri = p_manager->p_priv->finder.uris.p_elems[0];
         ARRAY_REMOVE( p_manager->p_priv->finder.uris, 0 );
-        vlc_cleanup_run();
+        vlc_cleanup_pop();
+        vlc_mutex_unlock( &p_manager->p_priv->finder.lock );
 
         addons_finder_t *p_finder =
                 vlc_custom_create( p_manager->p_priv->p_parent, sizeof( *p_finder ), "entries finder" );
diff --git a/src/misc/threads.c b/src/misc/threads.c
index d805f0d..1972621 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -169,6 +169,7 @@ void vlc_sem_wait (vlc_sem_t *sem)
     while (!sem->value)
         vlc_cond_wait (&sem->wait, &sem->lock);
     sem->value--;
-    vlc_cleanup_run ();
+    vlc_cleanup_pop ();
+    vlc_mutex_unlock (&sem->lock);
 }
 #endif /* LIBVLC_NEED_SEMAPHORE */



More information about the vlc-commits mailing list