]> git.sur5r.net Git - openldap/blob - libraries/libldap_r/thr_cthreads.c
Happy New Year!
[openldap] / libraries / libldap_r / thr_cthreads.c
1 /* thr_cthreads.c - wrapper for mach cthreads */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2012 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16 /* This work was initially developed by Luke Howard for inclusion
17  * in U-MICH LDAP 3.3.
18  */
19
20 #include "portable.h"
21
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 */
26
27 int
28 ldap_int_thread_initialize( void )
29 {
30         return 0;
31 }
32
33 int
34 ldap_int_thread_destroy( void )
35 {
36         return 0;
37 }
38
39 int 
40 ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 
41         int detach,
42         void *(*start_routine)( void *), void *arg)
43 {
44         *thread = cthread_fork( (cthread_fn_t) start_routine, arg);
45         return ( *thread == NULL ? -1 : 0 );    
46 }
47
48 void 
49 ldap_pvt_thread_exit( void *retval )
50 {
51         cthread_exit( (any_t) retval );
52 }
53
54 int 
55 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
56 {
57         void *status;
58         status = (void *) cthread_join ( thread );
59         if (thread_return != NULL)
60                 {
61                 *thread_return = status;
62                 }
63         return 0;
64 }
65
66 int 
67 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
68 {
69         return 0;
70 }
71
72 int 
73 ldap_pvt_thread_yield( void )
74 {
75         cthread_yield();
76         return 0;
77 }
78
79 int 
80 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
81 {
82         condition_init( cond );
83         return( 0 );
84 }
85
86 int 
87 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond )
88 {
89         condition_clear( cond );
90         return( 0 );
91 }
92
93 int 
94 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
95 {
96         condition_signal( cond );
97         return( 0 );
98 }
99
100 int
101 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
102 {
103         condition_broadcast( cond );
104         return( 0 );
105 }
106
107 int 
108 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond, 
109                           ldap_pvt_thread_mutex_t *mutex )
110 {
111         condition_wait( cond, mutex );
112         return( 0 );    
113 }
114
115 int 
116 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
117 {
118         mutex_init( mutex );
119         mutex->name = NULL;
120         return ( 0 );
121 }
122
123 int 
124 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
125 {
126         mutex_clear( mutex );
127         return ( 0 );   
128 }
129         
130 int 
131 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
132 {
133         mutex_lock( mutex );
134         return ( 0 );
135 }
136
137 int 
138 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
139 {
140         mutex_unlock( mutex );
141         return ( 0 );
142 }
143
144 int
145 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mutex )
146 {
147         return mutex_try_lock( mutex );
148 }
149
150 ldap_pvt_thread_t
151 ldap_pvt_thread_self( void )
152 {
153         return cthread_self();
154 }
155
156 int
157 ldap_pvt_thread_key_create( ldap_pvt_thread_key_t *key )
158 {
159         return cthread_keycreate( key );
160 }
161
162 int
163 ldap_pvt_thread_key_destroy( ldap_pvt_thread_key_t key )
164 {
165         return( 0 );
166 }
167
168 int
169 ldap_pvt_thread_key_setdata( ldap_pvt_thread_key_t key, void *data )
170 {
171         return cthread_setspecific( key, data );
172 }
173
174 int
175 ldap_pvt_thread_key_getdata( ldap_pvt_thread_key_t key, void **data )
176 {
177         return cthread_getspecific( key, data );
178 }
179
180 #endif /* HAVE_MACH_CTHREADS */