~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/pthread_xt.h

Merge PBXT.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2005 PrimeBase Technologies GmbH
 
2
 *
 
3
 * PrimeBase XT
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 *
 
19
 * 2006-03-22   Paul McCullagh
 
20
 *
 
21
 * H&G2JCtL
 
22
 *
 
23
 * This file contains windows specific code.
 
24
 */
 
25
 
 
26
#ifndef __win_xt_h__
 
27
#define __win_xt_h__
 
28
 
 
29
#ifdef XT_WIN
 
30
#include <windef.h>
 
31
#include <my_pthread.h>
 
32
#else
 
33
#include <pthread.h>
 
34
#endif
 
35
 
 
36
#include "locklist_xt.h"
 
37
 
 
38
#ifdef DEBUG
 
39
//#define DEBUG_LOCKING
 
40
#endif
 
41
 
 
42
#define xt_cond_struct                  _opaque_pthread_cond_t
 
43
#define xt_cond_type                    pthread_cond_t
 
44
 
 
45
#define xt_cond_wait                    pthread_cond_wait
 
46
#define xt_cond_wakeall                 pthread_cond_broadcast
 
47
 
 
48
#ifdef  __cplusplus
 
49
extern "C" {
 
50
#endif
 
51
void    xt_p_init_threading(void);
 
52
int             xt_p_set_normal_priority(pthread_t thr);
 
53
int             xt_p_set_low_priority(pthread_t thr);
 
54
int             xt_p_set_high_priority(pthread_t thr);
 
55
#ifdef  __cplusplus
 
56
}
 
57
#endif
 
58
 
 
59
#ifdef XT_WIN
 
60
 
 
61
#ifdef  __cplusplus
 
62
extern "C" {
 
63
#endif
 
64
 
 
65
typedef LPVOID pthread_key_t;
 
66
 
 
67
typedef struct xt_mutex_struct {
 
68
        CRITICAL_SECTION        mt_cs;
 
69
#ifdef XT_THREAD_LOCK_INFO
 
70
        const char                 *mt_name;
 
71
        XTThreadLockInfoRec mt_lock_info;
 
72
#endif
 
73
} xt_mutex_type;
 
74
 
 
75
typedef struct xt_rwlock_struct {
 
76
  xt_mutex_type                 rw_ex_lock;
 
77
  xt_mutex_type                 rw_sh_lock;
 
78
  pthread_cond_t                rw_sh_cond;
 
79
  int                                   rw_sh_count;
 
80
  int                                   rw_ex_count;
 
81
  int                                   rw_sh_complete_count;
 
82
  int                                   rw_magic;
 
83
#ifdef XT_THREAD_LOCK_INFO
 
84
        const char                 *rw_name;
 
85
        XTThreadLockInfoRec rw_lock_info;
 
86
#endif
 
87
} xt_rwlock_type;
 
88
 
 
89
#ifdef XT_THREAD_LOCK_INFO
 
90
int xt_p_mutex_init(xt_mutex_type *mutex, const pthread_mutexattr_t *attr, const char *name);
 
91
#else
 
92
int xt_p_mutex_init(xt_mutex_type *mutex, const pthread_mutexattr_t *attr);
 
93
#endif
 
94
int xt_p_mutex_destroy(xt_mutex_type *mutex);
 
95
int xt_p_mutex_lock(xt_mutex_type *mx);
 
96
int xt_p_mutex_unlock(xt_mutex_type *mx);
 
97
int xt_p_mutex_trylock(xt_mutex_type *mutex);
 
98
 
 
99
#ifdef XT_THREAD_LOCK_INFO
 
100
int xt_p_rwlock_init(xt_rwlock_type *rwlock, const pthread_condattr_t *attr, const char *name);
 
101
#else
 
102
int xt_p_rwlock_init(xt_rwlock_type *rwlock, const pthread_condattr_t *attr);
 
103
#endif
 
104
int             xt_p_rwlock_destroy(xt_rwlock_type *rwlock);
 
105
int             xt_p_rwlock_rdlock(xt_rwlock_type *mx);
 
106
int             xt_p_rwlock_wrlock(xt_rwlock_type *mx);
 
107
xtBool  xt_p_rwlock_try_wrlock(xt_rwlock_type *rwl);
 
108
int             xt_p_rwlock_unlock(xt_rwlock_type *mx);
 
109
 
 
110
int             xt_p_cond_wait(xt_cond_type *cond, xt_mutex_type *mutex);
 
111
int             xt_p_cond_timedwait(xt_cond_type *cond, xt_mutex_type *mutex, struct timespec *abstime);
 
112
 
 
113
int xt_p_join(pthread_t thread, void **value);
 
114
 
 
115
#ifdef  __cplusplus
 
116
}
 
117
#endif
 
118
 
 
119
#ifdef XT_THREAD_LOCK_INFO
 
120
#define xt_p_rwlock_init_with_name(a,b,c)   xt_p_rwlock_init(a,b,c)
 
121
#define xt_p_rwlock_init_with_autoname(a,b) xt_p_rwlock_init_with_name(a,b,LOCKLIST_ARG_SUFFIX(a))
 
122
#else
 
123
#define xt_p_rwlock_init_with_name(a,b,c)   xt_p_rwlock_init(a,b,c)
 
124
#define xt_p_rwlock_init_with_autoname(a,b) xt_p_rwlock_init(a,b)
 
125
#endif
 
126
 
 
127
#define xt_slock_rwlock_ns              xt_p_rwlock_rdlock
 
128
#define xt_xlock_rwlock_ns              xt_p_rwlock_wrlock
 
129
#define xt_xlock_try_rwlock_ns  xt_p_rwlock_try_wrlock
 
130
#define xt_unlock_rwlock_ns             xt_p_rwlock_unlock
 
131
 
 
132
#ifdef XT_THREAD_LOCK_INFO
 
133
#define xt_p_mutex_init_with_name(a,b,c)   xt_p_mutex_init(a,b,c)
 
134
#define xt_p_mutex_init_with_autoname(a,b) xt_p_mutex_init_with_name(a,b,LOCKLIST_ARG_SUFFIX(a))
 
135
#else
 
136
#define xt_p_mutex_init_with_name(a,b,c)   xt_p_mutex_init(a,b)
 
137
#define xt_p_mutex_init_with_autoname(a,b) xt_p_mutex_init(a,b)
 
138
#endif
 
139
#define xt_lock_mutex_ns                xt_p_mutex_lock
 
140
#define xt_unlock_mutex_ns              xt_p_mutex_unlock
 
141
#define xt_mutex_trylock                xt_p_mutex_trylock
 
142
 
 
143
#else // XT_WIN
 
144
 
 
145
/* Finger weg! */
 
146
#ifdef pthread_mutex_t
 
147
#undef pthread_mutex_t
 
148
#endif
 
149
#ifdef pthread_rwlock_t
 
150
#undef pthread_rwlock_t
 
151
#endif
 
152
#ifdef pthread_mutex_init
 
153
#undef pthread_mutex_init
 
154
#endif
 
155
#ifdef pthread_mutex_destroy
 
156
#undef pthread_mutex_destroy
 
157
#endif
 
158
#ifdef pthread_mutex_lock
 
159
#undef pthread_mutex_lock
 
160
#endif
 
161
#ifdef pthread_mutex_unlock
 
162
#undef pthread_mutex_unlock
 
163
#endif
 
164
#ifdef pthread_cond_wait
 
165
#undef pthread_cond_wait
 
166
#endif
 
167
#ifdef pthread_cond_broadcast
 
168
#undef pthread_cond_broadcast
 
169
#endif
 
170
#ifdef pthread_mutex_trylock
 
171
#undef pthread_mutex_trylock
 
172
#endif
 
173
 
 
174
/*
 
175
 * -----------------------------------------------------------------------
 
176
 * Reedefinition of pthread locking, for debugging
 
177
 */
 
178
 
 
179
struct XTThread;
 
180
 
 
181
 
 
182
#ifdef XT_THREAD_LOCK_INFO
 
183
 
 
184
#define xt_p_mutex_init_with_name(a,b,c)   xt_p_mutex_init(a,b,c)
 
185
#define xt_p_mutex_init_with_autoname(a,b) xt_p_mutex_init_with_name(a,b,LOCKLIST_ARG_SUFFIX(a))
 
186
 
 
187
#define xt_p_rwlock_init_with_name(a,b,c)   xt_p_rwlock_init(a,b,c)
 
188
#define xt_p_rwlock_init_with_autoname(a,b) xt_p_rwlock_init_with_name(a,b,LOCKLIST_ARG_SUFFIX(a))
 
189
 
 
190
#else
 
191
 
 
192
#define xt_p_mutex_init_with_name(a,b,c)   xt_p_mutex_init(a,b)
 
193
#define xt_p_mutex_init_with_autoname(a,b) xt_p_mutex_init(a,b)
 
194
 
 
195
#define xt_p_rwlock_init_with_name(a,b,c)   xt_p_rwlock_init(a,b)
 
196
#define xt_p_rwlock_init_with_autoname(a,b) xt_p_rwlock_init_with_name(a,b)
 
197
 
 
198
#endif
 
199
 
 
200
#ifdef DEBUG_LOCKING
 
201
 
 
202
#ifdef  __cplusplus
 
203
extern "C" {
 
204
#endif
 
205
 
 
206
typedef struct xt_mutex_struct {
 
207
        unsigned short                          mu_init;
 
208
        unsigned short                          mu_trace;
 
209
        unsigned int                            mu_line;
 
210
        const char                                      *mu_file;
 
211
        struct XTThread                         *mu_locker;
 
212
        pthread_mutex_t                         mu_plock;
 
213
#ifdef XT_THREAD_LOCK_INFO
 
214
        const char                                      *mu_name;
 
215
        XTThreadLockInfoRec             mu_lock_info;
 
216
#endif
 
217
} xt_mutex_type;
 
218
 
 
219
typedef struct xt_rwlock_struct {
 
220
        u_int                                           rw_init;
 
221
        volatile u_int                          rw_readers;
 
222
        struct XTThread                         *rw_locker;
 
223
        pthread_rwlock_t                        rw_plock;
 
224
#ifdef XT_THREAD_LOCK_INFO
 
225
        const char                                      *rw_name;
 
226
        XTThreadLockInfoRec             rw_lock_info;
 
227
#endif
 
228
} xt_rwlock_type;
 
229
 
 
230
int             xt_p_rwlock_rdlock(xt_rwlock_type *mx);
 
231
int             xt_p_rwlock_wrlock(xt_rwlock_type *mx);
 
232
xtBool  xt_p_rwlock_try_wrlock(xt_rwlock_type *mx);
 
233
int             xt_p_rwlock_unlock(xt_rwlock_type *mx);
 
234
 
 
235
int xt_p_mutex_lock(xt_mutex_type *mx, u_int line, const char *file);
 
236
int xt_p_mutex_unlock(xt_mutex_type *mx);
 
237
int xt_p_mutex_trylock(xt_mutex_type *mutex);
 
238
int xt_p_mutex_destroy(xt_mutex_type *mutex);
 
239
#ifdef XT_THREAD_LOCK_INFO
 
240
int xt_p_mutex_init(xt_mutex_type *mutex, const pthread_mutexattr_t *attr, const char *name);
 
241
#else
 
242
int xt_p_mutex_init(xt_mutex_type *mutex, const pthread_mutexattr_t *attr);
 
243
#endif
 
244
int xt_p_rwlock_destroy(xt_rwlock_type * rwlock);
 
245
#ifdef XT_THREAD_LOCK_INFO
 
246
int xt_p_rwlock_init(xt_rwlock_type *rwlock, const pthread_rwlockattr_t *attr, const char *name);
 
247
#else
 
248
int xt_p_rwlock_init(xt_rwlock_type *rwlock, const pthread_rwlockattr_t *attr);
 
249
#endif
 
250
int xt_p_cond_wait(xt_cond_type *cond, xt_mutex_type *mutex);
 
251
int xt_p_cond_timedwait(xt_cond_type *cond, xt_mutex_type *mutex, const struct timespec *abstime);
 
252
 
 
253
#ifdef  __cplusplus
 
254
}
 
255
#endif
 
256
 
 
257
#define xt_slock_rwlock_ns                      xt_p_rwlock_rdlock
 
258
#define xt_xlock_rwlock_ns                      xt_p_rwlock_wrlock
 
259
#define xt_xlock_try_rwlock_ns          xt_p_rwlock_try_wrlock
 
260
#define xt_unlock_rwlock_ns                     xt_p_rwlock_unlock
 
261
 
 
262
#define xt_lock_mutex_ns(x)                     xt_p_mutex_lock(x, __LINE__, __FILE__)
 
263
#define xt_unlock_mutex_ns                      xt_p_mutex_unlock
 
264
#define xt_mutex_trylock                        xt_p_mutex_trylock
 
265
 
 
266
#else // DEBUG_LOCKING
 
267
 
 
268
#define xt_rwlock_struct                        _opaque_pthread_rwlock_t
 
269
#define xt_mutex_struct                         _opaque_pthread_mutex_t
 
270
 
 
271
#define xt_rwlock_type                          pthread_rwlock_t
 
272
#define xt_mutex_type                           pthread_mutex_t
 
273
 
 
274
#define xt_slock_rwlock_ns                      pthread_rwlock_rdlock
 
275
#define xt_xlock_rwlock_ns                      pthread_rwlock_wrlock
 
276
#define xt_xlock_try_rwlock_ns(x)       (pthread_rwlock_trywrlock(x) == 0)
 
277
#define xt_unlock_rwlock_ns                     pthread_rwlock_unlock
 
278
 
 
279
#define xt_lock_mutex_ns                        pthread_mutex_lock
 
280
#define xt_unlock_mutex_ns                      pthread_mutex_unlock
 
281
#define xt_mutex_trylock                        pthread_mutex_trylock
 
282
 
 
283
#define xt_p_mutex_trylock                      pthread_mutex_trylock
 
284
#define xt_p_mutex_destroy                      pthread_mutex_destroy
 
285
#define xt_p_mutex_init                         pthread_mutex_init
 
286
#define xt_p_rwlock_destroy                     pthread_rwlock_destroy
 
287
#define xt_p_rwlock_init                        pthread_rwlock_init
 
288
#define xt_p_cond_wait                          pthread_cond_wait
 
289
#define xt_p_cond_timedwait                     pthread_cond_timedwait
 
290
 
 
291
#endif // DEBUG_LOCKING
 
292
 
 
293
#define xt_p_join                               pthread_join
 
294
 
 
295
#endif // XT_WIN
 
296
 
 
297
#endif