# include <fcntl.h>
# include <errno.h> /* ENOSYS */
#endif
-#ifdef HAVE_SYS_EVENTFD_H
+
+#include <assert.h>
+
+#if defined (HAVE_SYS_EVENTFD_H)
# include <sys/eventfd.h>
+# define HAVE_EVENTFD 1
#endif
-#include <assert.h>
+
/*****************************************************************************
* Local prototypes
p_priv->i_object_type = i_type;
p_new->psz_object_type = psz_type;
- p_new->psz_object_name = NULL;
+ p_priv->psz_object_name = NULL;
p_new->b_die = false;
p_new->b_error = false;
p_new->p_private = NULL;
/* Initialize mutexes and condvars */
- vlc_mutex_init( &p_priv->lock );
vlc_mutex_init( &p_priv->var_lock );
vlc_cond_init( &p_priv->var_wait );
p_priv->pipes[0] = p_priv->pipes[1] = -1;
switch( i_type )
{
- case VLC_OBJECT_INTF:
- i_size = sizeof(intf_thread_t);
- psz_type = "interface";
- break;
case VLC_OBJECT_DECODER:
i_size = sizeof(decoder_t);
psz_type = "decoder";
break;
- case VLC_OBJECT_PACKETIZER:
- i_size = sizeof(decoder_t);
- psz_type = "packetizer";
- break;
case VLC_OBJECT_AOUT:
i_size = sizeof(aout_instance_t);
psz_type = "audio output";
vlc_destructor_t pf_destructor )
{
vlc_object_internals_t *p_priv = vlc_internals(p_this );
+
+ vlc_spin_lock( &p_priv->ref_spin );
p_priv->pf_destructor = pf_destructor;
+ vlc_spin_unlock( &p_priv->ref_spin );
}
/**
free( p_this->psz_header );
- FREENULL( p_this->psz_object_name );
+ free( p_priv->psz_object_name );
vlc_spin_destroy( &p_priv->ref_spin );
- vlc_mutex_destroy( &p_priv->lock );
if( p_priv->pipes[1] != -1 && p_priv->pipes[1] != p_priv->pipes[0] )
close( p_priv->pipes[1] );
if( p_priv->pipes[0] != -1 )
}
-/** Inter-object signaling */
-
-void __vlc_object_lock( vlc_object_t *obj )
-{
- vlc_mutex_lock( &(vlc_internals(obj)->lock) );
-}
-
-void __vlc_object_unlock( vlc_object_t *obj )
-{
- vlc_assert_locked( &(vlc_internals(obj)->lock) );
- vlc_mutex_unlock( &(vlc_internals(obj)->lock) );
-}
-void __vlc_object_assert_locked( vlc_object_t *obj )
-{
- vlc_assert_locked( &(vlc_internals(obj)->lock) );
-}
-
#ifdef WIN32
# include <winsock2.h>
# include <ws2tcpip.h>
#define close( a ) closesocket (a)
#endif /* WIN32 */
+static vlc_mutex_t pipe_lock = VLC_STATIC_MUTEX;
+
/**
* Returns the readable end of a pipe that becomes readable once termination
* of the object is requested (vlc_object_kill()).
{
vlc_object_internals_t *internals = vlc_internals( obj );
- vlc_object_lock (obj);
+ vlc_mutex_lock (&pipe_lock);
if (internals->pipes[0] == -1)
{
/* This can only ever happen if someone killed us without locking: */
assert (internals->pipes[1] == -1);
-#ifdef HAVE_SYS_EVENTFD_H
+#ifdef HAVE_EVENTFD
internals->pipes[0] = internals->pipes[1] = eventfd (0, 0);
if (internals->pipes[0] == -1)
#endif
write (internals->pipes[1], &(uint64_t){ 1 }, sizeof (uint64_t));
}
}
- vlc_object_unlock (obj);
+ vlc_mutex_unlock (&pipe_lock);
return internals->pipes[0];
}
int fd = -1;
vlc_thread_cancel( p_this );
- vlc_object_lock( p_this );
+ vlc_mutex_lock( &pipe_lock );
if( !p_this->b_die )
{
fd = priv->pipes[1];
}
/* This also serves as a memory barrier toward vlc_object_alive(): */
- vlc_object_unlock( p_this );
+ vlc_mutex_unlock( &pipe_lock );
if (fd != -1)
{
{
vlc_object_t *p_found;
+ /* Reading psz_object_name from a separate inhibits thread-safety.
+ * Use a libvlc address variable instead for that sort of things! */
+ msg_Warn( p_this, "%s(%s) is not safe!", __func__, psz_name );
/* If have the requested name ourselves, don't look further */
if( !(i_mode & FIND_STRICT)
- && p_this->psz_object_name
- && !strcmp( p_this->psz_object_name, psz_name ) )
+ && vlc_internals(p_this)->psz_object_name
+ && !strcmp( vlc_internals(p_this)->psz_object_name, psz_name ) )
{
vlc_object_hold( p_this );
return p_this;
if( b_should_destroy )
{
- /* We have no children */
- assert (internals->i_children == 0);
parent = p_this->p_parent;
#ifndef NDEBUG
fprintf( stderr,
"ERROR: leaking object (%p, type:%s, name:%s)\n",
leaked, leaked->psz_object_type,
- leaked->psz_object_name );
+ vlc_internals(leaked)->psz_object_name );
/* Dump object to ease debugging */
vlc_object_dump( leaked );
fflush(stderr);
if (parent)
/* Detach from parent to protect against FIND_CHILDREN */
vlc_object_detach_unlocked (p_this);
+
+ /* We have no children */
+ assert (internals->i_children == 0);
}
libvlc_unlock (p_this->p_libvlc);
p_tmp = p_this->p_parent;
if( p_tmp )
{
- if( p_tmp->psz_object_name
- && !strcmp( p_tmp->psz_object_name, psz_name ) )
+ if( vlc_internals(p_tmp)->psz_object_name
+ && !strcmp( vlc_internals(p_tmp)->psz_object_name, psz_name ) )
{
vlc_object_hold( p_tmp );
return p_tmp;
for( i = vlc_internals( p_this )->i_children; i--; )
{
p_tmp = vlc_internals( p_this )->pp_children[i];
- if( p_tmp->psz_object_name
- && !strcmp( p_tmp->psz_object_name, psz_name ) )
+ if( vlc_internals(p_tmp)->psz_object_name
+ && !strcmp( vlc_internals(p_tmp)->psz_object_name, psz_name ) )
{
vlc_object_hold( p_tmp );
return p_tmp;
int canc = vlc_savecancel ();
memset( &psz_name, 0, sizeof(psz_name) );
- if( p_this->psz_object_name )
+ if( vlc_internals(p_this)->psz_object_name )
{
- snprintf( psz_name, 49, " \"%s\"", p_this->psz_object_name );
+ snprintf( psz_name, 49, " \"%s\"",
+ vlc_internals(p_this)->psz_object_name );
if( psz_name[48] )
psz_name[48] = '\"';
}