]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_thread.h
Add thread pool routines.
[openldap] / include / ldap_pvt_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_pvt_thread.h - ldap threads header file NG */
12
13 #ifndef _LDAP_PVT_THREAD_H
14 #define _LDAP_PVT_THREAD_H
15
16 #include "ldap_cdefs.h"
17 #include "ldap_int_thread.h"
18
19 LDAP_BEGIN_DECL
20
21 typedef ldap_int_thread_t ldap_pvt_thread_t;
22 typedef ldap_int_thread_mutex_t ldap_pvt_thread_mutex_t;
23 typedef ldap_int_thread_cond_t ldap_pvt_thread_cond_t;
24
25
26 LIBLDAP_F( int )
27 ldap_pvt_thread_initialize LDAP_P(( void ));
28
29 LIBLDAP_F( int )
30 ldap_pvt_thread_destroy LDAP_P(( void ));
31
32 LIBLDAP_F( unsigned int )
33 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
34
35 LIBLDAP_F( int )
36 ldap_pvt_thread_get_concurrency LDAP_P(( void ));
37
38 #ifndef LDAP_THREAD_CONCURRENCY
39         /* three concurrent threads should be enough */
40 #define LDAP_THREAD_CONCURRENCY 3
41 #endif
42 LIBLDAP_F( int )
43 ldap_pvt_thread_set_concurrency LDAP_P(( int ));
44
45 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
46 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
47
48 LIBLDAP_F( int ) 
49 ldap_pvt_thread_create LDAP_P((
50         ldap_pvt_thread_t * thread, 
51         int     detach,
52         void *(*start_routine)( void * ), 
53         void *arg));
54
55 LIBLDAP_F( void ) 
56 ldap_pvt_thread_exit LDAP_P(( void *retval ));
57
58 LIBLDAP_F( int )
59 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
60
61 LIBLDAP_F( int )
62 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
63
64 LIBLDAP_F( int )
65 ldap_pvt_thread_yield LDAP_P(( void ));
66
67 LIBLDAP_F( int )
68 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
69
70 LIBLDAP_F( int )
71 ldap_pvt_thread_cond_destroy LDAP_P(( ldap_pvt_thread_cond_t *cond ));
72
73 LIBLDAP_F( int )
74 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
75
76 LIBLDAP_F( int )
77 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
78
79 LIBLDAP_F( int )
80 ldap_pvt_thread_cond_wait LDAP_P((
81         ldap_pvt_thread_cond_t *cond, 
82         ldap_pvt_thread_mutex_t *mutex ));
83
84 LIBLDAP_F( int )
85 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
86
87 LIBLDAP_F( int )
88 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
89
90 LIBLDAP_F( int )
91 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
92
93 LIBLDAP_F( int )
94 ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
95
96 LIBLDAP_F( int )
97 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
98
99 #ifndef LDAP_THREAD_HAVE_RDWR
100 typedef struct ldap_pvt_thread_rdwr_var {
101         ldap_pvt_thread_mutex_t ltrw_mutex;     
102         ldap_pvt_thread_cond_t ltrw_read;       /* wait for read */
103         ldap_pvt_thread_cond_t ltrw_write;      /* wait for write */
104         int ltrw_valid;
105 #define LDAP_PVT_THREAD_RDWR_VALID 0x0bad
106         int ltrw_r_active;
107         int ltrw_w_active;
108         int ltrw_r_wait;
109         int ltrw_w_wait;
110 } ldap_pvt_thread_rdwr_t;
111 #endif
112
113 LIBLDAP_F( int )
114 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
115
116 LIBLDAP_F( int )
117 ldap_pvt_thread_rdwr_destroy LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
118
119 LIBLDAP_F( int )
120 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
121
122 LIBLDAP_F( int )
123 ldap_pvt_thread_rdwr_rtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
124
125 LIBLDAP_F( int )
126 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
127
128 LIBLDAP_F( int )
129 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
130
131 LIBLDAP_F( int )
132 ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
133
134 LIBLDAP_F( int )
135 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
136
137 #ifdef LDAP_DEBUG
138 LIBLDAP_F( int )
139 ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
140
141 LIBLDAP_F( int )
142 ldap_pvt_thread_rdwr_writers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
143
144 LIBLDAP_F( int )
145 ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
146 #endif /* LDAP_DEBUG */
147
148 #define LDAP_PVT_THREAD_EINVAL EINVAL
149 #define LDAP_PVT_THREAD_EBUSY EINVAL
150
151
152 typedef struct t_ldap_pvt_thread_pool *ldap_pvt_thread_pool_t;
153
154
155 LIBLDAP_F( int )
156 ldap_pvt_thread_pool_initialize LDAP_P((
157                                                 ldap_pvt_thread_pool_t *pool_out,
158                                                 int max_concurrency,
159                                                 int max_pending ));
160
161 LIBLDAP_F( int )
162 ldap_pvt_thread_pool_submit LDAP_P((
163                                                 ldap_pvt_thread_pool_t pool,
164                                                 void *(*start_routine)( void * ),
165                                                 void *arg ));
166
167 LIBLDAP_F( int )
168 ldap_pvt_thread_pool_backload LDAP_P((
169                                                 ldap_pvt_thread_pool_t pool ));
170
171 LIBLDAP_F( int )
172 ldap_pvt_thread_pool_destroy LDAP_P((
173                                                 ldap_pvt_thread_pool_t pool,
174                                                 int run_pending ));
175
176
177 LDAP_END_DECL
178
179 #endif /* _LDAP_THREAD_H */