1 /* thread.c - glue routines to provide a consistent thread interface */
5 #if defined( THREAD_SUNOS4_LWP )
7 /***********************************************************************
9 * under sunos 4 - use the built in non-preemptive lwp threads package *
11 ***********************************************************************/
13 extern stkalign_t *get_stack();
14 static void lwp_create_stack();
17 pthread_attr_init( pthread_attr_t *attr )
24 pthread_attr_destroy( pthread_attr_t *attr )
30 pthread_attr_getdetachstate( pthread_attr_t *attr, int *detachstate )
37 pthread_attr_setdetachstate( pthread_attr_t *attr, int detachstate )
55 if ( (stack = get_stack( &stackno )) == NULL ) {
58 return( lwp_create( tid, lwp_create_stack, MINPRIO, 0, stack, 3, func,
63 lwp_create_stack( VFP func, void *arg, int stackno )
67 free_stack( stackno );
83 pthread_join( pthread_t tid, int *status )
90 pthread_kill( pthread_t tid, int sig )
97 pthread_mutex_init( pthread_mutex_t *mp, pthread_mutexattr_t *attr )
99 return( mon_create( mp ) );
103 pthread_mutex_destroy( pthread_mutex_t *mp )
105 return( mon_destroy( *mp ) );
109 pthread_mutex_lock( pthread_mutex_t *mp )
111 return( mon_enter( *mp ) );
115 pthread_mutex_unlock( pthread_mutex_t *mp )
117 return( mon_exit( *mp ) );
121 pthread_mutex_trylock( pthread_mutex_t *mp )
123 return( mon_cond_enter( *mp ) );
127 pthread_cond_init( pthread_cond_t *cv, pthread_condattr_t *attr )
130 * lwp cv_create requires the monitor id be passed in
131 * when the cv is created, pthreads passes it when the
132 * condition is waited for. so, we fake the creation
133 * here and actually do it when the cv is waited for
143 pthread_cond_destroy( pthread_cond_t *cv )
145 return( cv->lcv_created ? cv_destroy( cv->lcv_cv ) : 0 );
149 pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mp )
151 if ( ! cv->lcv_created ) {
152 cv_create( &cv->lcv_cv, *mp );
156 return( cv_wait( cv->lcv_cv ) );
160 pthread_cond_signal( pthread_cond_t *cv )
162 return( cv->lcv_created ? cv_notify( cv->lcv_cv ) : 0 );
166 pthread_cond_broadcast( pthread_cond_t *cv )
168 return( cv->lcv_created ? cv_broadcast( cv->lcv_cv ) : 0 );
171 #else /* end sunos4 */
173 # if defined( THREAD_SUNOS5_LWP )
175 /***********************************************************************
177 * under sunos 5 - use the built in preemptive solaris threads package *
179 ***********************************************************************/
182 pthread_attr_init( pthread_attr_t *attr )
189 pthread_attr_destroy( pthread_attr_t *attr )
196 pthread_attr_getdetachstate( pthread_attr_t *attr, int *detachstate )
198 *detachstate = *attr;
203 pthread_attr_setdetachstate( pthread_attr_t *attr, int detachstate )
218 return( thr_create( NULL, 0, func, arg, attr, tid ) );
234 pthread_join( pthread_t tid, int *status )
236 thr_join( tid, NULL, (void **) status );
240 pthread_kill( pthread_t tid, int sig )
242 thr_kill( tid, sig );
247 pthread_mutex_init( pthread_mutex_t *mp, pthread_mutexattr_t *attr )
249 return( mutex_init( mp, attr ? *attr : USYNC_THREAD, NULL ) );
253 pthread_mutex_destroy( pthread_mutex_t *mp )
255 return( mutex_destroy( mp ) );
259 pthread_mutex_lock( pthread_mutex_t *mp )
261 return( mutex_lock( mp ) );
265 pthread_mutex_unlock( pthread_mutex_t *mp )
267 return( mutex_unlock( mp ) );
271 pthread_mutex_trylock( pthread_mutex_t *mp )
273 return( mutex_trylock( mp ) );
277 pthread_cond_init( pthread_cond_t *cv, pthread_condattr_t *attr )
279 return( cond_init( cv, attr ? *attr : USYNC_THREAD, NULL ) );
283 pthread_cond_destroy( pthread_cond_t *cv )
285 return( cond_destroy( cv ) );
289 pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mp )
291 return( cond_wait( cv, mp ) );
295 pthread_cond_signal( pthread_cond_t *cv )
297 return( cond_signal( cv ) );
301 pthread_cond_broadcast( pthread_cond_t *cv )
303 return( cond_broadcast( cv ) );
307 #else /* end sunos5 threads */
309 #if defined( THREAD_MIT_PTHREADS )
311 /***********************************************************************
313 * pthreads package by Chris Provenzano of MIT - provides all the *
314 * pthreads calls already, so no mapping to do *
316 ***********************************************************************/
318 #else /* end mit pthreads */
320 #if defined( THREAD_DCE_PTHREADS )
322 /***********************************************************************
324 * pthreads package with DCE - no mapping to do (except to create a *
325 * pthread_kill() routine) *
327 ***********************************************************************/
331 pthread_kill( pthread_t tid, int sig )
333 kill( getpid(), sig );
336 #endif /* dce pthreads */
337 #endif /* mit pthreads */
338 #endif /* sunos5 lwp */
339 #endif /* sunos4 lwp */
343 /***********************************************************************
345 * no threads package defined for this system - fake ok returns from *
346 * all threads routines (making it single-threaded). *
348 ***********************************************************************/
352 pthread_attr_init( pthread_attr_t *attr )
359 pthread_attr_destroy( pthread_attr_t *attr )
366 pthread_attr_getdetachstate( pthread_attr_t *attr, int *detachstate )
373 pthread_attr_setdetachstate( pthread_attr_t *attr, int detachstate )
406 pthread_kill( pthread_t tid, int sig )
412 pthread_join( pthread_t tid, int *status )
419 pthread_mutex_init( pthread_mutex_t *mp, pthread_mutexattr_t *attr )
426 pthread_mutex_destroy( pthread_mutex_t *mp )
433 pthread_mutex_lock( pthread_mutex_t *mp )
440 pthread_mutex_unlock( pthread_mutex_t *mp )
447 pthread_mutex_trylock( pthread_mutex_t *mp )
454 pthread_cond_init( pthread_cond_t *cv, pthread_condattr_t *attr )
461 pthread_cond_destroy( pthread_cond_t *cv )
468 pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mp )
475 pthread_cond_signal( pthread_cond_t *cv )
482 pthread_cond_broadcast( pthread_cond_t *cv )
487 #endif /* no threads package */