]> git.sur5r.net Git - openldap/blob - libraries/libldap_r/thr_pth.c
In preparation for thread pools
[openldap] / libraries / libldap_r / thr_pth.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 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_thr.c - wrappers around solaris threads */
13
14 #include "portable.h"
15
16 #if defined( HAVE_GNU_PTH )
17
18 #include "ldap_int_thread.h"
19
20 /*******************
21  *                 *
22  * GNU Pth Threads *
23  *                 *
24  *******************/
25
26 static pth_attr_t detach_attr;
27
28 int
29 ldap_int_thread_initialize( void )
30 {
31         detach_attr = pth_attr_new();
32         pth_attr_set( detach_attr, PTH_ATTR_JOINABLE, FALSE );
33         return pth_init();
34 }
35
36 int
37 ldap_int_thread_destroy( void )
38 {
39         pth_attr_destroy(detach_attr);
40         pth_kill();
41         return 0;
42 }
43
44 int 
45 ldap_int_thread_create( ldap_int_thread_t * thread, 
46         int detach,
47         void *(*start_routine)( void *),
48         void *arg)
49 {
50         *thread = pth_spawn( detach ? detach_attr : PTH_ATTR_DEFAULT,
51                 start_routine, arg );
52
53         return *thread == NULL;
54 }
55
56 void 
57 ldap_int_thread_exit( void *retval )
58 {
59         pth_exit( retval );
60 }
61
62 int ldap_int_thread_join( ldap_int_thread_t thread, void **thread_return )
63 {
64         pth_join( thread, thread_return );
65         return 0;
66 }
67
68 int 
69 ldap_int_thread_kill( ldap_int_thread_t thread, int signo )
70 {
71         pth_raise( thread, signo );
72         return 0;
73 }
74         
75 int 
76 ldap_int_thread_yield( void )
77 {
78         pth_yield(NULL);
79         return 0;
80 }
81
82 int 
83 ldap_int_thread_cond_init( ldap_int_thread_cond_t *cond )
84 {
85         return( pth_cond_init( cond ) );
86 }
87
88 int 
89 ldap_int_thread_cond_signal( ldap_int_thread_cond_t *cond )
90 {
91         return( pth_cond_notify( cond, 0 ) );
92 }
93
94 int
95 ldap_int_thread_cond_broadcast( ldap_int_thread_cond_t *cond )
96 {
97         return( pth_cond_notify( cond, 1 ) );
98 }
99
100 int 
101 ldap_int_thread_cond_wait( ldap_int_thread_cond_t *cond, 
102                           ldap_int_thread_mutex_t *mutex )
103 {
104         return( pth_cond_await( cond, mutex, NULL ) );
105 }
106
107 int
108 ldap_int_thread_cond_destroy( ldap_int_thread_cond_t *cv )
109 {
110         return 0;
111 }
112
113 int 
114 ldap_int_thread_mutex_init( ldap_int_thread_mutex_t *mutex )
115 {
116         return( pth_mutex_init( mutex ) );
117 }
118
119 int 
120 ldap_int_thread_mutex_destroy( ldap_int_thread_mutex_t *mutex )
121 {
122         return 0;
123 }
124
125 int 
126 ldap_int_thread_mutex_lock( ldap_int_thread_mutex_t *mutex )
127 {
128         return( pth_mutex_acquire( mutex, 0, NULL ) );
129 }
130
131 int 
132 ldap_int_thread_mutex_unlock( ldap_int_thread_mutex_t *mutex )
133 {
134         return( pth_mutex_release( mutex ) );
135 }
136
137 int
138 ldap_int_thread_mutex_trylock( ldap_int_thread_mutex_t *mutex )
139 {
140         return( pth_mutex_acquire( mutex, 1, NULL ) );
141 }
142
143 #endif /* HAVE_GNU_PTH */