]> git.sur5r.net Git - openldap/blob - libraries/libldap_r/thr_cthreads.c
Avoid premature free
[openldap] / libraries / libldap_r / thr_cthreads.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_cthreads.c - wrapper for mach cthreads */
13
14 #include "portable.h"
15
16 #if defined( HAVE_MACH_CTHREADS )
17 #include "ldap_pvt_thread.h"
18
19 /***********************************************************************
20  *                                                                     *
21  * under NEXTSTEP or OPENSTEP use CThreads                             *
22  * lukeh@xedoc.com.au                                                  *
23  *                                                                     *
24  ***********************************************************************/
25
26 int
27 ldap_int_thread_initialize( void )
28 {
29         return 0;
30 }
31
32 int
33 ldap_int_thread_destroy( void )
34 {
35         return 0;
36 }
37
38 int 
39 ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 
40         int detach,
41         void *(*start_routine)( void *), void *arg)
42 {
43         *thread = cthread_fork( (cthread_fn_t) start_routine, arg);
44         return ( *thread == NULL ? -1 : 0 );    
45 }
46
47 void 
48 ldap_pvt_thread_exit( void *retval )
49 {
50         cthread_exit( (any_t) retval );
51 }
52
53 int 
54 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
55 {
56         void *status;
57         status = (void *) cthread_join ( thread );
58         if (thread_return != NULL)
59                 {
60                 *thread_return = status;
61                 }
62         return 0;
63 }
64
65 int 
66 ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
67 {
68         return 0;
69 }
70
71 int 
72 ldap_pvt_thread_yield( void )
73 {
74         cthread_yield();
75         return 0;
76 }
77
78 int 
79 ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
80 {
81         condition_init( cond );
82         return( 0 );
83 }
84
85 int 
86 ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond )
87 {
88         condition_clear( cond );
89         return( 0 );
90 }
91
92 int 
93 ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
94 {
95         condition_signal( cond );
96         return( 0 );
97 }
98
99 int
100 ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
101 {
102         condition_broadcast( cond );
103         return( 0 );
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         condition_wait( cond, mutex );
111         return( 0 );    
112 }
113
114 int 
115 ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
116 {
117         mutex_init( mutex );
118         mutex->name = NULL;
119         return ( 0 );
120 }
121
122 int 
123 ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
124 {
125         mutex_clear( mutex );
126         return ( 0 );   
127 }
128         
129 int 
130 ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
131 {
132         mutex_lock( mutex );
133         return ( 0 );
134 }
135
136 int 
137 ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
138 {
139         mutex_unlock( mutex );
140         return ( 0 );
141 }
142
143 int
144 ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mutex )
145 {
146         return mutex_try_lock( mutex );
147 }
148
149 #endif /* HAVE_MACH_CTHREADS */