]> git.sur5r.net Git - openldap/blob - include/ldap_int_thread.h
4f398498dedffb16f07a34c95f0566211885fe74
[openldap] / include / ldap_int_thread.h
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 /* ldap_int_thread.h - ldap internal thread wrappers header file */
12
13 #ifndef _LDAP_INT_THREAD_H
14 #define _LDAP_INT_THREAD_H
15
16 #if defined( HAVE_PTHREADS )
17 /**********************************
18  *                                *
19  * definitions for POSIX Threads  *
20  *                                *
21  **********************************/
22
23 #include <pthread.h>
24 #ifdef HAVE_SCHED_H
25 #include <sched.h>
26 #endif
27
28 LDAP_BEGIN_DECL
29
30 typedef pthread_t               ldap_int_thread_t;
31 typedef pthread_mutex_t         ldap_int_thread_mutex_t;
32 typedef pthread_cond_t          ldap_int_thread_cond_t;
33
34 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
35         defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
36         defined( _POSIX_THREADSAFE_FUNCTIONS )
37 #define HAVE_REENTRANT_FUNCTIONS 1
38 #endif
39
40 #if defined( HAVE_PTHREAD_GETCONCURRENCY ) || \
41         defined( HAVE_THR_GETCONCURRENCY )
42 #define LDAP_THREAD_HAVE_GETCONCURRENCY 1
43 #endif
44
45 #if defined( HAVE_PTHREAD_SETCONCURRENCY ) || \
46         defined( HAVE_THR_SETCONCURRENCY )
47 #define LDAP_THREAD_HAVE_SETCONCURRENCY 1
48 #endif
49
50 #if 0 && defined( HAVE_PTHREAD_RWLOCK_DESTROY )
51 #define LDAP_THREAD_HAVE_RDWR 1
52 typedef pthread_rwlock_t ldap_pvt_thread_rdwr_t;
53 #endif
54
55 LDAP_END_DECL
56
57 #elif defined ( HAVE_MACH_CTHREADS )
58 /**********************************
59  *                                *
60  * definitions for Mach CThreads  *
61  *                                *
62  **********************************/
63
64 #include <mach/cthreads.h>
65
66 LDAP_BEGIN_DECL
67
68 typedef cthread_t               ldap_int_thread_t;
69 typedef struct mutex            ldap_int_thread_mutex_t;
70 typedef struct condition        ldap_int_thread_cond_t;
71
72 LDAP_END_DECL
73
74 #elif defined( HAVE_GNU_PTH )
75 /***********************************
76  *                                 *
77  * thread definitions for GNU Pth  *
78  *                                 *
79  ***********************************/
80
81 #define PTH_SYSCALL_SOFT 1
82 #include <pth.h>
83
84 LDAP_BEGIN_DECL
85
86 typedef pth_t           ldap_int_thread_t;
87 typedef pth_mutex_t     ldap_int_thread_mutex_t;
88 typedef pth_cond_t      ldap_int_thread_cond_t;
89
90 #if 0
91 #define LDAP_THREAD_HAVE_RDWR 1
92 typedef pth_rwlock_t ldap_pvt_thread_rdwr_t;
93 #endif
94
95 LDAP_END_DECL
96
97 #elif defined( HAVE_THR )
98 /********************************************
99  *                                          *
100  * thread definitions for Solaris LWP (THR) *
101  *                                          *
102  ********************************************/
103
104 #include <thread.h>
105 #include <synch.h>
106
107 LDAP_BEGIN_DECL
108
109 typedef thread_t                ldap_int_thread_t;
110 typedef mutex_t                 ldap_int_thread_mutex_t;
111 typedef cond_t                  ldap_int_thread_cond_t;
112
113 #define HAVE_REENTRANT_FUNCTIONS 1
114
115 #ifdef HAVE_THR_GETCONCURRENCY
116 #define LDAP_THREAD_HAVE_GETCONCURRENCY 1
117 #endif
118 #ifdef HAVE_THR_SETCONCURRENCY
119 #define LDAP_THREAD_HAVE_SETCONCURRENCY 1
120 #endif
121
122 LDAP_END_DECL
123
124 #elif defined( HAVE_LWP )
125 /*************************************
126  *                                   *
127  * thread definitions for SunOS LWP  *
128  *                                   *
129  *************************************/
130
131 #include <lwp/lwp.h>
132 #include <lwp/stackdep.h>
133 #define LDAP_THREAD_HAVE_SLEEP 1
134
135 LDAP_BEGIN_DECL
136
137 typedef thread_t                ldap_int_thread_t;
138 typedef mon_t                   ldap_int_thread_mutex_t;
139 struct ldap_int_thread_lwp_cv {
140         int             lcv_created;
141         cv_t            lcv_cv;
142 };
143 typedef struct ldap_int_thread_lwp_cv ldap_int_thread_cond_t;
144
145 #define HAVE_REENTRANT_FUNCTIONS 1
146
147 LDAP_END_DECL
148
149 #elif defined(HAVE_NT_THREADS)
150
151 #include <process.h>
152 #include <windows.h>
153
154 LDAP_BEGIN_DECL
155
156 typedef unsigned long   ldap_int_thread_t;
157 typedef HANDLE  ldap_int_thread_mutex_t;
158 typedef HANDLE  ldap_int_thread_cond_t;
159
160 LDAP_END_DECL
161
162 #else
163
164 /***********************************
165  *                                 *
166  * thread definitions for no       *
167  * underlying library support      *
168  *                                 *
169  ***********************************/
170
171 #ifndef NO_THREADS
172 #define NO_THREADS 1
173 #endif
174
175 LDAP_BEGIN_DECL
176
177 typedef int                     ldap_int_thread_t;
178 typedef int                     ldap_int_thread_mutex_t;
179 typedef int                     ldap_int_thread_cond_t;
180
181 #define LDAP_THREAD_HAVE_TPOOL 1
182 typedef int                     ldap_int_thread_pool_t;
183
184 LDAP_END_DECL
185
186 #endif /* no threads support */
187
188 LDAP_BEGIN_DECL
189
190 LDAP_F(int) ldap_int_thread_initialize LDAP_P(( void ));
191 LDAP_F(int) ldap_int_thread_destroy LDAP_P(( void ));
192 LDAP_F(int) ldap_int_thread_pool_startup ( void );
193 LDAP_F(int) ldap_int_thread_pool_shutdown ( void );
194
195 #ifndef LDAP_THREAD_HAVE_TPOOL
196 typedef struct ldap_int_thread_pool_s * ldap_int_thread_pool_t;
197 #endif
198
199 LDAP_END_DECL
200
201 #endif /* _LDAP_INT_THREAD_H */