Commit 50c84f60 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Remove error value from locks and condvar initialization

On Linux, these functions cannot fail. On Windows, mutexes cannot fail
and neither can real condition varaibles (but we use events instead to
support pre-Vista versions). In practice, the needed resources are
allocated as part of the mutex structure and per-thread data.

In any case, basically none of the call sites for those functions were
checking for errors. It seems best to abort in case of error than to
hit undefined behaviour. We probably do not want to clutter the tree
with untested never used error paths.
parent 7108136d
......@@ -139,13 +139,13 @@ typedef DWORD vlc_threadvar_t;
/*****************************************************************************
* Function definitions
*****************************************************************************/
VLC_EXPORT( int, vlc_mutex_init, ( vlc_mutex_t * ) );
VLC_EXPORT( int, vlc_mutex_init_recursive, ( vlc_mutex_t * ) );
VLC_EXPORT( void, vlc_mutex_init, ( vlc_mutex_t * ) );
VLC_EXPORT( void, vlc_mutex_init_recursive, ( vlc_mutex_t * ) );
VLC_EXPORT( void, vlc_mutex_destroy, ( vlc_mutex_t * ) );
VLC_EXPORT( void, vlc_mutex_lock, ( vlc_mutex_t * ) );
VLC_EXPORT( int, vlc_mutex_trylock, ( vlc_mutex_t * ) LIBVLC_USED );
VLC_EXPORT( void, vlc_mutex_unlock, ( vlc_mutex_t * ) );
VLC_EXPORT( int, vlc_cond_init, ( vlc_cond_t * ) );
VLC_EXPORT( void, vlc_cond_init, ( vlc_cond_t * ) );
VLC_EXPORT( void, vlc_cond_destroy, ( vlc_cond_t * ) );
VLC_EXPORT( void, vlc_cond_signal, (vlc_cond_t *) );
VLC_EXPORT( void, vlc_cond_broadcast, (vlc_cond_t *) );
......@@ -242,9 +242,10 @@ typedef pthread_spinlock_t vlc_spinlock_t;
/**
* Initializes a spinlock.
*/
static inline int vlc_spin_init (vlc_spinlock_t *spin)
static inline void vlc_spin_init (vlc_spinlock_t *spin)
{
return pthread_spin_init (spin, PTHREAD_PROCESS_PRIVATE);
if (pthread_spin_init (spin, PTHREAD_PROCESS_PRIVATE))
abort ();
}
/**
......@@ -278,9 +279,10 @@ typedef CRITICAL_SECTION vlc_spinlock_t;
/**
* Initializes a spinlock.
*/
static inline int vlc_spin_init (vlc_spinlock_t *spin)
static inline void vlc_spin_init (vlc_spinlock_t *spin)
{
return !InitializeCriticalSectionAndSpinCount(spin, 4000);
if (!InitializeCriticalSectionAndSpinCount(spin, 4000))
abort ();
}
/**
......@@ -312,9 +314,9 @@ static inline void vlc_spin_destroy (vlc_spinlock_t *spin)
/* Fallback to plain mutexes if spinlocks are not available */
typedef vlc_mutex_t vlc_spinlock_t;
static inline int vlc_spin_init (vlc_spinlock_t *spin)
static inline void vlc_spin_init (vlc_spinlock_t *spin)
{
return vlc_mutex_init (spin);
vlc_mutex_init (spin);
}
# define vlc_spin_lock vlc_mutex_lock
......
......@@ -135,13 +135,12 @@ int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
/*****************************************************************************
* vlc_mutex_init: initialize a mutex
*****************************************************************************/
int vlc_mutex_init( vlc_mutex_t *p_mutex )
void vlc_mutex_init( vlc_mutex_t *p_mutex )
{
pthread_mutexattr_t attr;
int i_result;
pthread_mutexattr_init( &attr );
if( pthread_mutexattr_init( &attr ) )
abort();
#ifndef NDEBUG
/* Create error-checking mutex to detect problems more easily. */
# if defined (__GLIBC__) && (__GLIBC_MINOR__ < 6)
......@@ -150,18 +149,17 @@ int vlc_mutex_init( vlc_mutex_t *p_mutex )
pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_ERRORCHECK );
# endif
#endif
i_result = pthread_mutex_init( p_mutex, &attr );
if( pthread_mutex_init( p_mutex, &attr ) )
abort();
pthread_mutexattr_destroy( &attr );
return i_result;
}
/*****************************************************************************
* vlc_mutex_init: initialize a recursive mutex (Do not use)
*****************************************************************************/
int vlc_mutex_init_recursive( vlc_mutex_t *p_mutex )
void vlc_mutex_init_recursive( vlc_mutex_t *p_mutex )
{
pthread_mutexattr_t attr;
int i_result;
pthread_mutexattr_init( &attr );
#if defined (__GLIBC__) && (__GLIBC_MINOR__ < 6)
......@@ -169,9 +167,9 @@ int vlc_mutex_init_recursive( vlc_mutex_t *p_mutex )
#else
pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
#endif
i_result = pthread_mutex_init( p_mutex, &attr );
if( pthread_mutex_init( p_mutex, &attr ) )
abort();
pthread_mutexattr_destroy( &attr );
return( i_result );
}
......@@ -254,15 +252,12 @@ void vlc_mutex_unlock (vlc_mutex_t *p_mutex)
/*****************************************************************************
* vlc_cond_init: initialize a condition variable
*****************************************************************************/
int vlc_cond_init( vlc_cond_t *p_condvar )
void vlc_cond_init( vlc_cond_t *p_condvar )
{
pthread_condattr_t attr;
int ret;
ret = pthread_condattr_init (&attr);
if (ret)
return ret;
if (pthread_condattr_init (&attr))
abort ();
#if !defined (_POSIX_CLOCK_SELECTION)
/* Fairly outdated POSIX support (that was defined in 2001) */
# define _POSIX_CLOCK_SELECTION (-1)
......@@ -272,9 +267,9 @@ int vlc_cond_init( vlc_cond_t *p_condvar )
pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
#endif
ret = pthread_cond_init (p_condvar, &attr);
if (pthread_cond_init (p_condvar, &attr))
abort ();
pthread_condattr_destroy (&attr);
return ret;
}
/**
......
......@@ -158,7 +158,7 @@ BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
}
/*** Mutexes ***/
int vlc_mutex_init( vlc_mutex_t *p_mutex )
void vlc_mutex_init( vlc_mutex_t *p_mutex )
{
/* This creates a recursive mutex. This is OK as fast mutexes have
* no defined behavior in case of recursive locking. */
......@@ -167,7 +167,7 @@ int vlc_mutex_init( vlc_mutex_t *p_mutex )
return 0;
}
int vlc_mutex_init_recursive( vlc_mutex_t *p_mutex )
void vlc_mutex_init_recursive( vlc_mutex_t *p_mutex )
{
InitializeCriticalSection( &p_mutex->mutex );
p_mutex->initialized = 1;
......@@ -220,11 +220,12 @@ void vlc_mutex_unlock (vlc_mutex_t *p_mutex)
}
/*** Condition variables ***/
int vlc_cond_init( vlc_cond_t *p_condvar )
void vlc_cond_init( vlc_cond_t *p_condvar )
{
/* Create a manual-reset event (manual reset is needed for broadcast). */
*p_condvar = CreateEvent (NULL, TRUE, FALSE, NULL);
return *p_condvar ? 0 : ENOMEM;
if (!*p_condvar)
abort();
}
void vlc_cond_destroy (vlc_cond_t *p_condvar)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment