From 1b2e878cc468b38f521c8f5157d8e02b7e0de9a3 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 16 Sep 1998 05:04:54 +0000 Subject: [PATCH] Wrap sched_yield() use with #ifndef SCHED_YIELD_MISSING --- include/lthread.h | 53 +++++++++- libraries/liblthread/thread.c | 178 +++++++++++++++++++++++++++++++++- 2 files changed, 225 insertions(+), 6 deletions(-) diff --git a/include/lthread.h b/include/lthread.h index d1b34d8ecf..d3fd3d0ec6 100644 --- a/include/lthread.h +++ b/include/lthread.h @@ -3,7 +3,40 @@ #ifndef _LTHREAD_H #define _LTHREAD_H -#if defined( THREAD_SUNOS4_LWP ) +#if defined ( THREAD_NEXT_CTHREADS ) + +#define _THREAD + +#include + +typedef cthread_fn_t VFP; +typedef int pthread_attr_t; +typedef cthread_t pthread_t; + +/* default attr states */ +#define pthread_mutexattr_default NULL +#define pthread_condattr_default NULL + +/* thread state - joinable or not */ +#define PTHREAD_CREATE_JOINABLE 0 +#define PTHREAD_CREATE_DETACHED 1 +/* thread scope - who is in scheduling pool */ +#define PTHREAD_SCOPE_PROCESS 0 +#define PTHREAD_SCOPE_SYSTEM 1 + +/* mutex attributes and mutex type */ +typedef int pthread_mutexattr_t; +typedef struct mutex pthread_mutex_t; + +/* mutex and condition variable scope - process or system */ +#define PTHREAD_SHARE_PRIVATE 0 +#define PTHREAD_SHARE_PROCESS 1 + +/* condition variable attributes and condition variable type */ +typedef int pthread_condattr_t; +typedef struct condition pthread_cond_t; + +#elif defined( THREAD_SUNOS4_LWP ) /*********************************** * * * thread definitions for sunos4 * @@ -66,9 +99,11 @@ typedef void *(*VFP)(); /* sunos5 threads are preemptive */ #define PTHREAD_PREEMPTIVE 1 +#if !defined(__SunOS_5_6) /* thread attributes and thread type */ typedef int pthread_attr_t; typedef thread_t pthread_t; +#endif /* ! sunos56 */ /* default attr states */ #define pthread_mutexattr_default NULL @@ -81,17 +116,21 @@ typedef thread_t pthread_t; #define PTHREAD_SCOPE_PROCESS 0 #define PTHREAD_SCOPE_SYSTEM THR_BOUND +#if !defined(__SunOS_5_6) /* mutex attributes and mutex type */ typedef int pthread_mutexattr_t; typedef mutex_t pthread_mutex_t; +#endif /* ! sunos56 */ /* mutex and condition variable scope - process or system */ #define PTHREAD_SHARE_PRIVATE USYNC_THREAD #define PTHREAD_SHARE_PROCESS USYNC_PROCESS +#if !defined(__SunOS_5_6) /* condition variable attributes and condition variable type */ typedef int pthread_condattr_t; typedef cond_t pthread_cond_t; +#endif /* ! sunos56 */ #else /* end sunos5 */ @@ -127,6 +166,18 @@ typedef cond_t pthread_cond_t; #define pthread_attr_setdetachstate( a, b ) \ pthread_attr_setdetach_np( a, b ) +#else /* end dce pthreads */ + +#if defined( POSIX_THREADS ) + +#define _THREAD + +#include + +#define pthread_mutexattr_default NULL +#define pthread_condattr_default NULL + +#endif /* posix threads */ #endif /* dce pthreads */ #endif /* mit pthreads */ #endif /* sunos5 */ diff --git a/libraries/liblthread/thread.c b/libraries/liblthread/thread.c index 89a85c70b4..12574d0606 100644 --- a/libraries/liblthread/thread.c +++ b/libraries/liblthread/thread.c @@ -2,7 +2,157 @@ #include #include "lthread.h" -#if defined( THREAD_SUNOS4_LWP ) +#if defined( THREAD_NEXT_CTHREADS ) + +/*********************************************************************** + * * + * under NEXTSTEP or OPENSTEP use CThreads * + * lukeh@xedoc.com.au * + * * + ***********************************************************************/ + +int +pthread_attr_init( pthread_attr_t *attr ) +{ + *attr = 0; + return( 0 ); +} + +int +pthread_attr_destroy( pthread_attr_t *attr ) +{ + return( 0 ); +} + +int +pthread_attr_getdetachstate( pthread_attr_t *attr, int *detachstate ) +{ + *detachstate = *attr; + return( 0 ); +} + +int +pthread_attr_setdetachstate( pthread_attr_t *attr, int detachstate ) +{ + *attr = detachstate; + return( 0 ); +} + +/* ARGSUSED */ +int +pthread_create( + pthread_t *tid, + pthread_attr_t *attr, + VFP func, + void *arg +) +{ + *tid = cthread_fork(func, arg); + return ( *tid == NULL ? -1 : 0 ); +} + +void +pthread_yield() +{ + cthread_yield(); +} + +void +pthread_exit( any_t a ) +{ + cthread_exit( a ); +} + +void +pthread_join( pthread_t tid, int *pStatus ) +{ + int status; + status = (int) cthread_join ( tid ); + if (pStatus != NULL) + { + *pStatus = status; + } +} + +/* ARGSUSED */ +void +pthread_kill( pthread_t tid, int sig ) +{ + return; +} + +/* ARGSUSED */ +int +pthread_mutex_init( pthread_mutex_t *mp, pthread_mutexattr_t *attr ) +{ + mutex_init( mp ); + mp->name = NULL; + return ( 0 ); +} + +int +pthread_mutex_destroy( pthread_mutex_t *mp ) +{ + mutex_clear( mp ); + return ( 0 ); +} + +int +pthread_mutex_lock( pthread_mutex_t *mp ) +{ + mutex_lock( mp ); + return ( 0 ); +} + +int +pthread_mutex_unlock( pthread_mutex_t *mp ) +{ + mutex_unlock( mp ); + return ( 0 ); +} + +int +pthread_mutex_trylock( pthread_mutex_t *mp ) +{ + return mutex_try_lock( mp ); +} + +int +pthread_cond_init( pthread_cond_t *cv, pthread_condattr_t *attr ) +{ + condition_init( cv ); + return( 0 ); +} + +int +pthread_cond_destroy( pthread_cond_t *cv ) +{ + condition_clear( cv ); + return( 0 ); +} + +int +pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mp ) +{ + condition_wait( cv, mp ); + return( 0 ); +} + +int +pthread_cond_signal( pthread_cond_t *cv ) +{ + condition_signal( cv ); + return( 0 ); +} + +int +pthread_cond_broadcast( pthread_cond_t *cv ) +{ + condition_broadcast( cv ); + return( 0 ); +} + +#elif defined( THREAD_SUNOS4_LWP ) /*********************************************************************** * * @@ -44,7 +194,7 @@ pthread_attr_setdetachstate( pthread_attr_t *attr, int detachstate ) int pthread_create( pthread_t *tid, - pthread_attr_t attr, + pthread_attr_t *attr, VFP func, void *arg ) @@ -178,6 +328,7 @@ pthread_cond_broadcast( pthread_cond_t *cv ) * * ***********************************************************************/ +#if !defined(__SunOS_5_6) int pthread_attr_init( pthread_attr_t *attr ) { @@ -210,13 +361,14 @@ pthread_attr_setdetachstate( pthread_attr_t *attr, int detachstate ) int pthread_create( pthread_t *tid, - pthread_attr_t attr, + pthread_attr_t *attr, VFP func, void *arg ) { - return( thr_create( NULL, 0, func, arg, attr, tid ) ); + return( thr_create( NULL, 0, func, arg, *attr, tid ) ); } +#endif /* ! sunos56 */ void pthread_yield() @@ -224,6 +376,7 @@ pthread_yield() thr_yield(); } +#if !defined(__SunOS_5_6) void pthread_exit() { @@ -302,6 +455,7 @@ pthread_cond_broadcast( pthread_cond_t *cv ) { return( cond_broadcast( cv ) ); } +#endif /* ! sunos56 */ #else /* end sunos5 threads */ @@ -333,6 +487,20 @@ pthread_kill( pthread_t tid, int sig ) kill( getpid(), sig ); } +#else + +#if defined ( POSIX_THREADS ) + +#ifndef SCHED_YIELD_MISSING +#include + +void pthread_yield( void ) +{ + sched_yield(); +} +#endif + +#endif /* posix threads */ #endif /* dce pthreads */ #endif /* mit pthreads */ #endif /* sunos5 lwp */ @@ -379,7 +547,7 @@ pthread_attr_setdetachstate( pthread_attr_t *attr, int detachstate ) int pthread_create( pthread_t *tid, - pthread_attr_t attr, + pthread_attr_t *attr, VFP func, void *arg ) -- 2.47.2