#include <vlc_fs.h>
#include <vlc_cpu.h>
#include <vlc_url.h>
+#include <vlc_atomic.h>
#include "libvlc.h"
assert (pf_destruct);
p_gc->pf_destructor = pf_destruct;
- p_gc->refs = 1;
-#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
- __sync_synchronize ();
-#elif defined (WIN32) && defined (__GNUC__)
-#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);
- vlc_spin_unlock (&p_gc->spin);
-#endif
+ vlc_atomic_set (&p_gc->refs, 1);
return p_gc;
}
void *vlc_hold (gc_object_t * p_gc)
{
uintptr_t refs;
+
assert( p_gc );
- assert ((((uintptr_t)&p_gc->refs) & (sizeof (void *) - 1)) == 0); /* alignment */
-
-#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
- refs = __sync_add_and_fetch (&p_gc->refs, 1);
-#elif defined (WIN64)
- refs = InterlockedIncrement64 (&p_gc->refs);
-#elif defined (WIN32)
- refs = InterlockedIncrement (&p_gc->refs);
-#elif defined(__APPLE__)
- refs = OSAtomicIncrement32Barrier((int*)&p_gc->refs);
-#else
- vlc_spin_lock (&p_gc->spin);
- refs = ++p_gc->refs;
- vlc_spin_unlock (&p_gc->spin);
-#endif
+ refs = vlc_atomic_inc (&p_gc->refs);
assert (refs != 1); /* there had to be a reference already */
return p_gc;
}
unsigned refs;
assert( p_gc );
- assert ((((uintptr_t)&p_gc->refs) & (sizeof (void *) - 1)) == 0); /* alignment */
-
-#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
- refs = __sync_sub_and_fetch (&p_gc->refs, 1);
-#elif defined (WIN64)
- refs = InterlockedDecrement64 (&p_gc->refs);
-#elif defined (WIN32)
- refs = InterlockedDecrement (&p_gc->refs);
-#elif defined(__APPLE__)
- refs = OSAtomicDecrement32Barrier((int*)&p_gc->refs);
-#else
- vlc_spin_lock (&p_gc->spin);
- refs = --p_gc->refs;
- vlc_spin_unlock (&p_gc->spin);
-#endif
-
+ refs = vlc_atomic_dec (&p_gc->refs);
assert (refs != (uintptr_t)(-1)); /* reference underflow?! */
if (refs == 0)
- {
-#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
-#elif defined (WIN32) && defined (__GNUC__)
-#elif defined(__APPLE__)
-#else
- vlc_spin_destroy (&p_gc->spin);
-#endif
p_gc->pf_destructor (p_gc);
- }
}
/*****************************************************************************
#endif
/* Initialize mutexes */
+ vlc_mutex_init( &priv->ml_lock );
vlc_mutex_init( &priv->timer_lock );
vlc_ExitInit( &priv->exit );
var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING );
var_Create( p_libvlc, "record-file", VLC_VAR_STRING );
+ /* some default internal settings */
+ var_Create( p_libvlc, "window", VLC_VAR_STRING );
+ var_Create( p_libvlc, "user-agent", VLC_VAR_STRING );
+ var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" );
+
/* Initialize playlist and get commandline files */
p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) );
if( !p_playlist )
/* Get the ML */
if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) == true )
{
- priv->p_ml = __ml_Create( VLC_OBJECT( p_libvlc ), NULL );
+ priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL );
if( !priv->p_ml )
{
msg_Err( p_libvlc, "ML initialization failed" );
}
#endif
+#ifdef __APPLE__
var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );
var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER );
var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
+#endif
#ifdef WIN32
var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_ADDRESS );
#endif
media_library_t* p_ml = priv->p_ml;
if( p_ml )
{
- __ml_Destroy( VLC_OBJECT( p_ml ) );
+ ml_Destroy( VLC_OBJECT( p_ml ) );
vlc_object_release( p_ml );
libvlc_priv(p_playlist->p_libvlc)->p_ml = NULL;
}
/* Destroy mutexes */
vlc_ExitDestroy( &priv->exit );
vlc_mutex_destroy( &priv->timer_lock );
+ vlc_mutex_destroy( &priv->ml_lock );
#ifndef NDEBUG /* Hack to dump leaked objects tree */
if( vlc_internals( p_libvlc )->i_refcount > 1 )
}
}
- /* TODO: write an internal function of this one, to avoid
- * unnecessary lookups. */
- char *mrl = make_URI( args[n] );
+ char *mrl = make_URI( args[n], NULL );
if( !mrl )
continue;