1 /* thr_cthreads.c - wrapper for mach cthreads */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* This work was initially developed by Luke Howard for inclusion
22 #if defined( HAVE_MACH_CTHREADS )
23 #include "ldap_pvt_thread.h"
26 ldap_int_thread_initialize( void )
32 ldap_int_thread_destroy( void )
38 ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
40 void *(*start_routine)( void *), void *arg)
42 *thread = cthread_fork( (cthread_fn_t) start_routine, arg);
43 return ( *thread == NULL ? -1 : 0 );
47 ldap_pvt_thread_exit( void *retval )
49 cthread_exit( (any_t) retval );
53 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
56 status = (void *) cthread_join ( thread );
57 if (thread_return != NULL)
59 *thread_return = status;
65 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
71 ldap_pvt_thread_yield( void )
78 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
80 condition_init( cond );
85 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond )
87 condition_clear( cond );
92 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
94 condition_signal( cond );
99 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
101 condition_broadcast( cond );
106 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
107 ldap_pvt_thread_mutex_t *mutex )
109 condition_wait( cond, mutex );
114 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
122 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
124 mutex_clear( mutex );
129 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
136 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
138 mutex_unlock( mutex );
143 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mutex )
145 return mutex_try_lock( mutex );
149 ldap_pvt_thread_self( void )
151 return cthread_self();
154 #endif /* HAVE_MACH_CTHREADS */