*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <vlc/vlc.h>
#elif defined( HAVE_CTHREADS_H )
#endif
-/*****************************************************************************
- * Global variable for named mutexes
- *****************************************************************************/
-typedef struct vlc_namedmutex_t vlc_namedmutex_t;
-struct vlc_namedmutex_t
-{
- vlc_mutex_t lock;
-
- char *psz_name;
- int i_usage;
- vlc_namedmutex_t *p_next;
-};
-
/*****************************************************************************
* vlc_threads_init: initialize threads system
*****************************************************************************
*****************************************************************************/
int __vlc_threads_init( vlc_object_t *p_this )
{
- libvlc_t *p_libvlc = (libvlc_t *)p_this;
+ libvlc_global_data_t *p_libvlc_global = (libvlc_global_data_t *)p_this;
int i_ret = VLC_SUCCESS;
/* If we have lazy mutex initialization, use it. Otherwise, we just
i_status = VLC_THREADS_PENDING;
/* We should be safe now. Do all the initialization stuff we want. */
- p_libvlc->b_ready = VLC_FALSE;
+ p_libvlc_global->b_ready = VLC_FALSE;
#if defined( PTH_INIT_IN_PTH_H )
i_ret = ( pth_init() == FALSE );
hInstLib = LoadLibrary( "kernel32" );
if( hInstLib )
{
- p_libvlc->SignalObjectAndWait =
+ p_libvlc_global->SignalObjectAndWait =
(SIGNALOBJECTANDWAIT)GetProcAddress( hInstLib,
"SignalObjectAndWait" );
}
}
else
{
- p_libvlc->SignalObjectAndWait = NULL;
+ p_libvlc_global->SignalObjectAndWait = NULL;
}
- p_libvlc->b_fast_mutex = 0;
- p_libvlc->i_win9x_cv = 0;
+ p_libvlc_global->b_fast_mutex = 0;
+ p_libvlc_global->i_win9x_cv = 0;
#elif defined( HAVE_KERNEL_SCHEDULER_H )
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
#elif defined( HAVE_CTHREADS_H )
#endif
- p_root = vlc_object_create( p_libvlc, VLC_OBJECT_ROOT );
+ p_root = vlc_object_create( p_libvlc_global, VLC_OBJECT_GLOBAL );
if( p_root == NULL )
i_ret = VLC_ENOMEM;
* function and have a 100% correct vlc_cond_wait() implementation.
* As this function is not available on Win9x, we can use the faster
* CriticalSections */
- if( p_this->p_libvlc->SignalObjectAndWait &&
- !p_this->p_libvlc->b_fast_mutex )
+ if( p_this->p_libvlc_global->SignalObjectAndWait &&
+ !p_this->p_libvlc_global->b_fast_mutex )
{
/* We are running on NT/2K/XP, we can use SignalObjectAndWait */
p_mutex->mutex = CreateMutex( 0, FALSE, 0 );
/*****************************************************************************
* vlc_mutex_destroy: destroy a mutex, inner version
*****************************************************************************/
-int __vlc_mutex_destroy( char * psz_file, int i_line, vlc_mutex_t *p_mutex )
+int __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mutex )
{
int i_result;
/* In case of error : */
p_condvar->i_waiting_threads = 0;
/* Misc init */
- p_condvar->i_win9x_cv = p_this->p_libvlc->i_win9x_cv;
- p_condvar->SignalObjectAndWait = p_this->p_libvlc->SignalObjectAndWait;
+ p_condvar->i_win9x_cv = p_this->p_libvlc_global->i_win9x_cv;
+ p_condvar->SignalObjectAndWait = p_this->p_libvlc_global->SignalObjectAndWait;
- if( (p_condvar->SignalObjectAndWait && !p_this->p_libvlc->b_fast_mutex)
+ if( (p_condvar->SignalObjectAndWait &&
+ !p_this->p_libvlc_global->b_fast_mutex)
|| p_condvar->i_win9x_cv == 0 )
{
/* Create an auto-reset event. */
/*****************************************************************************
* vlc_cond_destroy: destroy a condition, inner version
*****************************************************************************/
-int __vlc_cond_destroy( char * psz_file, int i_line, vlc_cond_t *p_condvar )
+int __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar )
{
int i_result;
/* In case of error : */
* Note that i_priority is only taken into account on platforms supporting
* userland real-time priority threads.
*****************************************************************************/
-int __vlc_thread_create( vlc_object_t *p_this, char * psz_file, int i_line,
- char *psz_name, void * ( *func ) ( void * ),
+int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line,
+ const char *psz_name, void * ( *func ) ( void * ),
int i_priority, vlc_bool_t b_wait )
{
int i_ret;
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
i_ret = pthread_create( &p_this->thread_id, NULL, func, p_data );
- if( config_GetType( p_this, "rt-priority" ) && config_GetInt( p_this, "rt-priority" ) )
+#ifndef __APPLE__
+ if( config_GetInt( p_this, "rt-priority" ) )
+#endif
{
int i_error, i_policy;
struct sched_param param;
memset( ¶m, 0, sizeof(struct sched_param) );
- i_priority += config_GetInt( p_this, "rt-offset" );
+ if( config_GetType( p_this, "rt-offset" ) )
+ {
+ i_priority += config_GetInt( p_this, "rt-offset" );
+ }
if( i_priority <= 0 )
{
param.sched_priority = (-1) * i_priority;
i_priority = 0;
}
}
+#ifndef __APPLE__
else
{
i_priority = 0;
}
+#endif
#elif defined( HAVE_CTHREADS_H )
p_this->thread_id = cthread_fork( (cthread_fn_t)func, (any_t)p_data );
}
else
{
-#ifdef HAVE_STRERROR
msg_Err( p_this, "%s thread could not be created at %s:%d (%s)",
psz_name, psz_file, i_line, strerror(i_ret) );
-#else
- msg_Err( p_this, "%s thread could not be created at %s:%d",
- psz_name, psz_file, i_line );
-#endif
vlc_mutex_unlock( &p_this->object_lock );
}
* vlc_thread_set_priority: set the priority of the current thread when we
* couldn't set it in vlc_thread_create (for instance for the main thread)
*****************************************************************************/
-int __vlc_thread_set_priority( vlc_object_t *p_this, char * psz_file,
+int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file,
int i_line, int i_priority )
{
#if defined( PTH_INIT_IN_PTH_H ) || defined( ST_INIT_IN_ST_H )
}
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
- if( config_GetType( p_this, "rt-priority" ) && config_GetInt( p_this, "rt-priority" ) )
+#ifndef __APPLE__
+ if( config_GetInt( p_this, "rt-priority" ) )
+#endif
{
int i_error, i_policy;
struct sched_param param;
memset( ¶m, 0, sizeof(struct sched_param) );
- i_priority += config_GetInt( p_this, "rt-offset" );
+ if( config_GetType( p_this, "rt-offset" ) )
+ {
+ i_priority += config_GetInt( p_this, "rt-offset" );
+ }
if( i_priority <= 0 )
{
param.sched_priority = (-1) * i_priority;
/*****************************************************************************
* vlc_thread_join: wait until a thread exits, inner version
*****************************************************************************/
-void __vlc_thread_join( vlc_object_t *p_this, char * psz_file, int i_line )
+void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line )
{
int i_ret = 0;
if( i_ret )
{
-#ifdef HAVE_STRERROR
msg_Err( p_this, "thread_join(%u) failed at %s:%d (%s)",
(unsigned int)p_this->thread_id, psz_file, i_line,
strerror(i_ret) );
-#else
- msg_Err( p_this, "thread_join(%u) failed at %s:%d",
- (unsigned int)p_this->thread_id, psz_file, i_line );
-#endif
}
else
{