]> git.sur5r.net Git - openldap/blob - libraries/libldap_r/thr_pth.c
fdffc531cfe9878aa599a7e844413b3b64086e47
[openldap] / libraries / libldap_r / thr_pth.c
1 /*
2  * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted only
6  * as authorized by the OpenLDAP Public License.  A copy of this
7  * license is available at http://www.OpenLDAP.org/license.html or
8  * in file LICENSE in the top-level directory of the distribution.
9  */
10
11 /* thr_thr.c - wrappers around solaris threads */
12
13 #include "portable.h"
14
15 #if defined( HAVE_GNU_PTH )
16
17 #include "ldap_pvt_thread.h"
18
19 /*******************
20  *                 *
21  * GNU Pth Threads *
22  *                 *
23  *******************/
24
25 static pth_attr_t detach_attr;
26
27 int
28 ldap_pvt_thread_initialize( void )
29 {
30         detach_attr = pth_attr_new();
31         pth_attr_set( detach_attr, PTH_ATTR_JOINABLE, FALSE );
32         return pth_init();
33 }
34
35 int
36 ldap_pvt_thread_destroy( void )
37 {
38         pth_attr_destroy(detach_attr);
39         pth_kill();
40         return 0;
41 }
42
43 int 
44 ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 
45         int detach,
46         void *(*start_routine)( void *),
47         void *arg)
48 {
49         *thread = pth_spawn( detach ? detach_attr : PTH_ATTR_DEFAULT,
50                 start_routine, arg );
51
52         return *thread == NULL;
53 }
54
55 void 
56 ldap_pvt_thread_exit( void *retval )
57 {
58         pth_exit( retval );
59 }
60
61 int ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
62 {
63         pth_join( thread, thread_return );
64         return 0;
65 }
66
67 int 
68 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
69 {
70         pth_raise( thread, signo );
71         return 0;
72 }
73         
74 int 
75 ldap_pvt_thread_yield( void )
76 {
77         pth_yield(NULL);
78         return 0;
79 }
80
81 int 
82 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
83 {
84         return( pth_cond_init( cond ) );
85 }
86
87 int 
88 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
89 {
90         return( pth_cond_notify( cond, 0 ) );
91 }
92
93 int
94 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
95 {
96         return( pth_cond_notify( cond, 1 ) );
97 }
98
99 int 
100 ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond, 
101                           ldap_pvt_thread_mutex_t *mutex )
102 {
103         return( pth_cond_await( cond, mutex, NULL ) );
104 }
105
106 int
107 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cv )
108 {
109         return 0;
110 }
111
112 int 
113 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
114 {
115         return( pth_mutex_init( mutex ) );
116 }
117
118 int 
119 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
120 {
121         return 0;
122 }
123
124 int 
125 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
126 {
127         return( pth_mutex_acquire( mutex, 0, NULL ) );
128 }
129
130 int 
131 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
132 {
133         return( pth_mutex_release( mutex ) );
134 }
135
136 int
137 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mutex )
138 {
139         return( pth_mutex_acquire( mutex, 1, NULL ) );
140 }
141
142 #endif /* HAVE_GNU_PTH */