]> git.sesse.net Git - vlc/blobdiff - src/libvlc.c
lower case the module_* functions
[vlc] / src / libvlc.c
index 87920fb96a02f1cafa7ab843848bccd8c57548c9..07b3ed14151af193db67d20b59de5f96dd55bd2a 100644 (file)
 #   include <hal/libhal.h>
 #endif
 
+#if defined(__GNUC__)
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 0)
+#define USE_SYNC
+#endif
+#endif
+
 #include <vlc_playlist.h>
 #include <vlc_interface.h>
 
 
 #include <vlc_vlm.h>
 
+#ifdef __APPLE__
+# include <libkern/OSAtomic.h>
+#endif
+
 #include <assert.h>
 
 /*****************************************************************************
@@ -116,13 +126,21 @@ static bool b_daemon = false;
  */
 void *vlc_gc_init (gc_object_t *p_gc, void (*pf_destruct) (gc_object_t *))
 {
+    /* There is no point in using the GC if there is destructor... */
+    assert (pf_destruct);
     p_gc->pf_destructor = pf_destruct;
 
+    p_gc->refs = 1;
+#ifdef USE_SYNC
+    __sync_synchronize ();
+#elif defined(__APPLE__)
+    OSMemoryBarrier ();
+#else
     /* Nobody else can possibly lock the spin - it's there as a barrier */
     vlc_spin_init (&p_gc->spin);
     vlc_spin_lock (&p_gc->spin);
-    p_gc->refs = 1;
     vlc_spin_unlock (&p_gc->spin);
+#endif
     return p_gc;
 }
 
@@ -133,12 +151,19 @@ void *vlc_gc_init (gc_object_t *p_gc, void (*pf_destruct) (gc_object_t *))
  */
 void *vlc_hold (gc_object_t * p_gc)
 {
+    uintptr_t refs;
     assert( p_gc );
 
+#ifdef USE_SYNC
+    refs = __sync_fetch_and_add (&p_gc->refs, 1);
+#elif defined(__APPLE__)
+    refs = OSAtomicIncrement32Barrier((int*)&p_gc->refs) - 1;
+#else
     vlc_spin_lock (&p_gc->spin);
-    assert (p_gc->refs > 0);
-    p_gc->refs++;
+    refs = p_gc->refs++;
     vlc_spin_unlock (&p_gc->spin);
+#endif
+    assert (refs > 0);
     return p_gc;
 }
 
@@ -148,17 +173,28 @@ void *vlc_hold (gc_object_t * p_gc)
  */
 void vlc_release (gc_object_t *p_gc)
 {
-    bool dead;
+    unsigned refs;
 
     assert( p_gc );
+
+#ifdef USE_SYNC
+    refs = __sync_fetch_and_sub (&p_gc->refs, 1);
+#elif defined(__APPLE__)
+    refs = OSAtomicDecrement32Barrier((int*)&p_gc->refs) + 1;
+#else
     vlc_spin_lock (&p_gc->spin);
-    assert (p_gc->refs > 0);
-    dead = !--p_gc->refs;
+    refs = p_gc->refs--;
     vlc_spin_unlock (&p_gc->spin);
+#endif
 
-    if (dead)
+    assert (refs > 0);
+    if (refs == 1)
     {
+#ifdef USE_SYNC
+#elif defined(__APPLE__)
+#else
         vlc_spin_destroy (&p_gc->spin);
+#endif
         p_gc->pf_destructor (p_gc);
     }
 }
@@ -761,7 +797,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     /*
      * Choose the best memcpy module
      */
-    priv->p_memcpy_module = module_Need( p_libvlc, "memcpy", "$memcpy", 0 );
+    priv->p_memcpy_module = module_need( p_libvlc, "memcpy", "$memcpy", 0 );
 
     priv->b_stats = config_GetInt( p_libvlc, "stats" ) > 0;
     priv->i_timers = 0;
@@ -777,10 +813,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     vlc_mutex_init( &p_libvlc->p_stats->lock );
     priv->p_stats_computer = NULL;
 
-    /* Init the array that holds every input item */
-    ARRAY_INIT( priv->input_items );
-    priv->i_last_input_id = 0;
-
     /*
      * Initialize hotkey handling
      */
@@ -802,7 +834,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         msg_Err( p_libvlc, "playlist initialization failed" );
         if( priv->p_memcpy_module != NULL )
         {
-            module_Unneed( p_libvlc, priv->p_memcpy_module );
+            module_unneed( p_libvlc, priv->p_memcpy_module );
         }
         module_EndBank( p_libvlc );
         return VLC_EGENERIC;
@@ -983,7 +1015,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     var_Get( p_libvlc, "open", &val );
     if ( val.psz_string != NULL && *val.psz_string )
     {
-        playlist_t *p_playlist = pl_Yield( p_libvlc );
+        playlist_t *p_playlist = pl_Hold( p_libvlc );
         playlist_AddExt( p_playlist, val.psz_string, NULL, PLAYLIST_INSERT, 0,
                          -1, NULL, 0, true, pl_Unlocked );
         pl_Release( p_libvlc );
@@ -1026,10 +1058,10 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     playlist_ServicesDiscoveryKillAll( p_playlist );
 
     /* Free playlist */
-    /* Any thread still running must not assume pl_Yield() succeeds. */
+    /* Any thread still running must not assume pl_Hold() succeeds. */
     msg_Dbg( p_libvlc, "removing playlist" );
     priv->p_playlist = NULL;
-    vlc_object_kill( p_playlist ); /* <-- memory barrier for pl_Yield() */
+    vlc_object_kill( p_playlist ); /* <-- memory barrier for pl_Hold() */
     vlc_thread_join( p_playlist );
     vlc_object_release( p_playlist );
 
@@ -1047,15 +1079,6 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     stats_TimersDumpAll( p_libvlc );
     stats_TimersCleanAll( p_libvlc );
 
-    bool b_clean = true;
-    FOREACH_ARRAY( input_item_t *p_del, priv->input_items )
-        msg_Err( p_libvlc, "input item %p has not been deleted properly: name %s",
-            p_del, p_del->psz_name ? p_del->psz_name : "(null)" );
-        b_clean = false;
-    FOREACH_END();
-    assert( b_clean );
-    ARRAY_RESET( priv->input_items );
-
     msg_Dbg( p_libvlc, "removing stats" );
     vlc_mutex_destroy( &p_libvlc->p_stats->lock );
     FREENULL( p_libvlc->p_stats );
@@ -1098,7 +1121,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
 
     if( priv->p_memcpy_module )
     {
-        module_Unneed( p_libvlc, priv->p_memcpy_module );
+        module_unneed( p_libvlc, priv->p_memcpy_module );
         priv->p_memcpy_module = NULL;
     }
 
@@ -1288,7 +1311,7 @@ static int GetFilenames( libvlc_int_t *p_vlc, int i_argc, const char *ppsz_argv[
         /* TODO: write an internal function of this one, to avoid
          *       unnecessary lookups. */
 
-        playlist_t *p_playlist = pl_Yield( p_vlc );
+        playlist_t *p_playlist = pl_Hold( p_vlc );
         playlist_AddExt( p_playlist, ppsz_argv[i_opt], NULL, PLAYLIST_INSERT,
                          0, -1, ( i_options ? &ppsz_argv[i_opt + 1] : NULL ),
                          i_options, true, pl_Unlocked );
@@ -1401,14 +1424,12 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
 #else
 #   define OPTION_VALUE_SEP " "
 #endif
-    vlc_list_t *p_list = NULL;
     char psz_spaces_text[PADDING_SPACES+LINE_START+1];
     char psz_spaces_longtext[LINE_START+3];
     char psz_format[sizeof(COLOR_FORMAT_STRING)];
     char psz_format_bool[sizeof(COLOR_FORMAT_STRING_BOOL)];
     char psz_buffer[10000];
     char psz_short[4];
-    int i_index;
     int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
     int i_width_description = i_width + PADDING_SPACES - 1;
     bool b_advanced    = config_GetInt( p_this, "advanced" ) > 0;
@@ -1443,7 +1464,9 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
     }
 
     /* List all modules */
-    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    module_t **list = module_list_get (NULL);
+    if (!list)
+        return;
 
     /* Ugly hack to make sure that the help options always come first
      * (part 1) */
@@ -1451,10 +1474,10 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
         Usage( p_this, "help" );
 
     /* Enumerate the config for each module */
-    for( i_index = 0; i_index < p_list->i_count; i_index++ )
+    for (size_t i = 0; list[i]; i++)
     {
         bool b_help_module;
-        module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object;
+        module_t *p_parser = list[i];
         module_config_t *p_item = NULL;
         module_config_t *p_section = NULL;
         module_config_t *p_end = p_parser->p_config + p_parser->confsize;
@@ -1847,7 +1870,7 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
     }
 
     /* Release the module list */
-    vlc_list_release( p_list );
+    module_list_free (list);
 }
 
 /*****************************************************************************
@@ -1858,10 +1881,8 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
  *****************************************************************************/
 static void ListModules( libvlc_int_t *p_this, bool b_verbose )
 {
-    vlc_list_t *p_list = NULL;
-    module_t *p_parser = NULL;
+    module_t *p_parser;
     char psz_spaces[22];
-    int i_index;
 
     bool b_color = config_GetInt( p_this, "color" ) > 0;
 
@@ -1872,15 +1893,13 @@ static void ListModules( libvlc_int_t *p_this, bool b_verbose )
 #endif
 
     /* List all modules */
-    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    module_t **list = module_list_get (NULL);
 
     /* Enumerate each module */
-    for( i_index = 0; i_index < p_list->i_count; i_index++ )
+    for (size_t j = 0; (p_parser = list[j]) != NULL; j++)
     {
         int i;
 
-        p_parser = (module_t *)p_list->p_values[i_index].p_object ;
-
         /* Nasty hack, but right now I'm too tired to think about a nice
          * solution */
         i = 22 - strlen( p_parser->psz_object_name ) - 1;
@@ -1928,8 +1947,7 @@ static void ListModules( libvlc_int_t *p_this, bool b_verbose )
 
         psz_spaces[i] = ' ';
     }
-
-    vlc_list_release( p_list );
+    module_list_free (list);
 
 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
     PauseConsole();