1 /* thr_cthreads.c - wrapper for mach cthreads */
2 /* $OpenLDAP: pkg/ldap/libraries/libldap_r/thr_cthreads.c,v 1.20.2.4 2008/02/11 23:26:42 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 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" /* Get the thread interface */
24 #define LDAP_THREAD_IMPLEMENTATION
25 #include "ldap_thr_debug.h" /* May rename the symbols defined below */
28 ldap_int_thread_initialize( void )
34 ldap_int_thread_destroy( void )
40 ldap_pvt_thread_create( ldap_pvt_thread_t
* thread
,
42 void *(*start_routine
)( void *), void *arg
)
44 *thread
= cthread_fork( (cthread_fn_t
) start_routine
, arg
);
45 return ( *thread
== NULL
? -1 : 0 );
49 ldap_pvt_thread_exit( void *retval
)
51 cthread_exit( (any_t
) retval
);
55 ldap_pvt_thread_join( ldap_pvt_thread_t thread
, void **thread_return
)
58 status
= (void *) cthread_join ( thread
);
59 if (thread_return
!= NULL
)
61 *thread_return
= status
;
67 ldap_pvt_thread_kill( ldap_pvt_thread_t thread
, int signo
)
73 ldap_pvt_thread_yield( void )
80 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t
*cond
)
82 condition_init( cond
);
87 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t
*cond
)
89 condition_clear( cond
);
94 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t
*cond
)
96 condition_signal( cond
);
101 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t
*cond
)
103 condition_broadcast( cond
);
108 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t
*cond
,
109 ldap_pvt_thread_mutex_t
*mutex
)
111 condition_wait( cond
, mutex
);
116 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t
*mutex
)
124 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t
*mutex
)
126 mutex_clear( mutex
);
131 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t
*mutex
)
138 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t
*mutex
)
140 mutex_unlock( mutex
);
145 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t
*mutex
)
147 return mutex_try_lock( mutex
);
151 ldap_pvt_thread_self( void )
153 return cthread_self();
157 ldap_pvt_thread_key_create( ldap_pvt_thread_key_t
*key
)
159 return cthread_keycreate( key
);
163 ldap_pvt_thread_key_destroy( ldap_pvt_thread_key_t key
)
169 ldap_pvt_thread_key_setdata( ldap_pvt_thread_key_t key
, void *data
)
171 return cthread_setspecific( key
, data
);
175 ldap_pvt_thread_key_getdata( ldap_pvt_thread_key_t key
, void **data
)
177 return cthread_getspecific( key
, data
);
180 #endif /* HAVE_MACH_CTHREADS */