]> git.sur5r.net Git - openldap/blob - libraries/libldap_r/thr_pth.c
ITS#2562: add missing arg to hash_lanman
[openldap] / libraries / libldap_r / thr_pth.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, Redwood City, California, USA
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted only
7  * as authorized by the OpenLDAP Public License.  A copy of this
8  * license is available at http://www.OpenLDAP.org/license.html or
9  * in file LICENSE in the top-level directory of the distribution.
10  */
11
12 /* thr_pth.c - wrappers around GNU Pth */
13
14 #include "portable.h"
15
16 #if defined( HAVE_GNU_PTH )
17
18 #include "ldap_pvt_thread.h"
19 #include <errno.h>
20
21 /*******************
22  *                 *
23  * GNU Pth Threads *
24  *                 *
25  *******************/
26
27 static pth_attr_t detach_attr;
28 static pth_attr_t joined_attr;
29
30 int
31 ldap_int_thread_initialize( void )
32 {
33         if( !pth_init() ) {
34                 return -1;
35         }
36         detach_attr = pth_attr_new();
37         joined_attr = pth_attr_new();
38 #if LDAP_PVT_THREAD_STACK_SIZE
39         pth_attr_set( joined_attr, PTH_ATTR_STACK_SIZE, LDAP_PVT_THREAD_STACK_SIZE );
40         pth_attr_set( detach_attr, PTH_ATTR_STACK_SIZE, LDAP_PVT_THREAD_STACK_SIZE );
41 #endif
42         return pth_attr_set( detach_attr, PTH_ATTR_JOINABLE, FALSE );
43 }
44
45 int
46 ldap_int_thread_destroy( void )
47 {
48         pth_attr_destroy(detach_attr);
49         pth_kill();
50         return 0;
51 }
52
53 int 
54 ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 
55         int detach,
56         void *(*start_routine)( void *),
57         void *arg)
58 {
59         *thread = pth_spawn( detach ? detach_attr : joined_attr,
60                 start_routine, arg );
61
62         return *thread == NULL ? errno : 0;
63 }
64
65 void 
66 ldap_pvt_thread_exit( void *retval )
67 {
68         pth_exit( retval );
69 }
70
71 int ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
72 {
73         return pth_join( thread, thread_return ) ? 0 : errno;
74 }
75
76 int 
77 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
78 {
79         return pth_raise( thread, signo ) ? 0 : errno;
80 }
81         
82 int 
83 ldap_pvt_thread_yield( void )
84 {
85         return pth_yield(NULL) ? 0 : errno;
86 }
87
88 int 
89 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
90 {
91         return( pth_cond_init( cond ) ? 0 : errno );
92 }
93
94 int 
95 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
96 {
97         return( pth_cond_notify( cond, 0 ) ? 0 : errno );
98 }
99
100 int
101 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
102 {
103         return( pth_cond_notify( cond, 1 ) ? 0 : errno );
104 }
105
106 int 
107 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond, 
108         ldap_pvt_thread_mutex_t *mutex )
109 {
110         return( pth_cond_await( cond, mutex, NULL ) ? 0 : errno );
111 }
112
113 int
114 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cv )
115 {
116         return 0;
117 }
118
119 int 
120 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
121 {
122         return( pth_mutex_init( mutex ) ? 0 : errno );
123 }
124
125 int 
126 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
127 {
128         return 0;
129 }
130
131 int 
132 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
133 {
134         return( pth_mutex_acquire( mutex, 0, NULL ) ? 0 : errno );
135 }
136
137 int 
138 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
139 {
140         return( pth_mutex_release( mutex ) ? 0 : errno );
141 }
142
143 int
144 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mutex )
145 {
146         return( pth_mutex_acquire( mutex, 1, NULL ) ? 0 : errno );
147 }
148
149 ldap_pvt_thread_t
150 ldap_pvt_thread_self( void )
151 {
152         return pth_self();
153 }
154
155 #ifdef LDAP_THREAD_HAVE_RDWR
156 int 
157 ldap_pvt_thread_rdwr_init( ldap_pvt_thread_rdwr_t *rw )
158 {
159         return pth_rwlock_init( rw ) ? 0 : errno;
160 }
161
162 int 
163 ldap_pvt_thread_rdwr_destroy( ldap_pvt_thread_rdwr_t *rw )
164 {
165         return 0;
166 }
167
168 int ldap_pvt_thread_rdwr_rlock( ldap_pvt_thread_rdwr_t *rw )
169 {
170         return pth_rwlock_acquire( rw, PTH_RWLOCK_RD, 0, NULL ) ? 0 : errno;
171 }
172
173 int ldap_pvt_thread_rdwr_rtrylock( ldap_pvt_thread_rdwr_t *rw )
174 {
175         return pth_rwlock_acquire( rw, PTH_RWLOCK_RD, 1, NULL ) ? 0 : errno;
176 }
177
178 int ldap_pvt_thread_rdwr_runlock( ldap_pvt_thread_rdwr_t *rw )
179 {
180         return pth_rwlock_release( rw ) ? 0 : errno;
181 }
182
183 int ldap_pvt_thread_rdwr_wlock( ldap_pvt_thread_rdwr_t *rw )
184 {
185         return pth_rwlock_acquire( rw, PTH_RWLOCK_RW, 0, NULL ) ? 0 : errno;
186 }
187
188 int ldap_pvt_thread_rdwr_wtrylock( ldap_pvt_thread_rdwr_t *rw )
189 {
190         return pth_rwlock_acquire( rw, PTH_RWLOCK_RW, 1, NULL ) ? 0 : errno;
191 }
192
193 int ldap_pvt_thread_rdwr_wunlock( ldap_pvt_thread_rdwr_t *rw )
194 {
195         return pth_rwlock_release( rw ) ? 0 : errno;
196 }
197
198 #endif /* LDAP_THREAD_HAVE_RDWR */
199 #endif /* HAVE_GNU_PTH */