toku_pthread.h 8.15 KB
Newer Older
1 2 3
#ifndef _TOKU_PTHREAD_H
#define _TOKU_PTHREAD_H

4
#if defined(__cplusplus)
5 6 7
extern "C" {
#endif

8
#include "pthread.h"
Yoni Fogel's avatar
Yoni Fogel committed
9
#include <toku_time.h>
10

Yoni Fogel's avatar
Yoni Fogel committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
int toku_pthread_win32_init(void);
int toku_pthread_win32_destroy(void);

typedef pthread_attr_t          toku_pthread_attr_t;
typedef pthread_t               toku_pthread_t;
typedef pthread_mutexattr_t     toku_pthread_mutexattr_t;
typedef pthread_mutex_t         toku_pthread_mutex_t;
typedef pthread_condattr_t      toku_pthread_condattr_t;
typedef pthread_cond_t          toku_pthread_cond_t;
typedef pthread_rwlock_t        toku_pthread_rwlock_t;
typedef pthread_rwlockattr_t    toku_pthread_rwlockattr_t;
//typedef struct timespec         toku_timespec_t; //Already defined in toku_time.h


typedef int (__cdecl *toku_pthread_win32_rwlock_init_func) (pthread_rwlock_t *lock, const pthread_rwlockattr_t *attr);
typedef int (__cdecl *toku_pthread_win32_rwlock_destroy_func) (pthread_rwlock_t *lock);
typedef int (__cdecl *toku_pthread_win32_rwlock_rdlock_func) (pthread_rwlock_t *rwlock);
typedef int (__cdecl *toku_pthread_win32_rwlock_wrlock_func) (pthread_rwlock_t *rwlock);
typedef int (__cdecl *toku_pthread_win32_rwlock_unlock_func) (pthread_rwlock_t *rwlock);
typedef int (__cdecl *toku_pthread_win32_attr_init_func) (pthread_attr_t *attr);
typedef int (__cdecl *toku_pthread_win32_attr_destroy_func) (pthread_attr_t *attr);
typedef int (__cdecl *toku_pthread_win32_attr_getstacksize_func)(pthread_attr_t *attr, size_t *stacksize);
typedef int (__cdecl *toku_pthread_win32_attr_setstacksize_func)(pthread_attr_t *attr, size_t *stacksize);
typedef int (__cdecl *toku_pthread_win32_create_func) (pthread_t *thread, const pthread_attr_t *attr, void *(*start_function)(void *), void *arg);
typedef int (__cdecl *toku_pthread_win32_join_func) (pthread_t thread, void **value_ptr);
typedef pthread_t (__cdecl *toku_pthread_win32_self_func)(void);
typedef int (__cdecl *toku_pthread_win32_mutex_init_func) (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
typedef int (__cdecl *toku_pthread_win32_mutex_destroy_func) (pthread_mutex_t *mutex);
typedef int (__cdecl *toku_pthread_win32_mutex_lock_func) (pthread_mutex_t *mutex);
typedef int (__cdecl *toku_pthread_win32_mutex_trylock_func) (pthread_mutex_t *mutex);
typedef int (__cdecl *toku_pthread_win32_mutex_unlock_func) (pthread_mutex_t *mutex);
typedef int (__cdecl *toku_pthread_win32_cond_init_func) (pthread_cond_t *cond, const pthread_condattr_t *attr);
typedef int (__cdecl *toku_pthread_win32_cond_destroy_func) (pthread_cond_t *cond);
typedef int (__cdecl *toku_pthread_win32_cond_wait_func) (pthread_cond_t *cond, pthread_mutex_t *mutex);
typedef int (__cdecl *toku_pthread_win32_cond_timedwait_func) (pthread_cond_t *cond, pthread_mutex_t *mutex, toku_timespec_t *wakeup_at);
typedef int (__cdecl *toku_pthread_win32_cond_signal_func) (pthread_cond_t *cond);
typedef int (__cdecl *toku_pthread_win32_cond_broadcast_func) (pthread_cond_t *cond);

typedef struct toku_pthread_win32_funcs_struct {
    toku_pthread_win32_attr_init_func         pthread_attr_init;
    toku_pthread_win32_attr_destroy_func      pthread_attr_destroy;
    toku_pthread_win32_attr_getstacksize_func pthread_attr_getstacksize;
    toku_pthread_win32_attr_setstacksize_func pthread_attr_setstacksize;

    toku_pthread_win32_mutex_init_func        pthread_mutex_init;
    toku_pthread_win32_mutex_destroy_func     pthread_mutex_destroy;
    toku_pthread_win32_mutex_lock_func        pthread_mutex_lock;
    toku_pthread_win32_mutex_trylock_func     pthread_mutex_trylock;
    toku_pthread_win32_mutex_unlock_func      pthread_mutex_unlock;

    toku_pthread_win32_cond_init_func         pthread_cond_init;
    toku_pthread_win32_cond_destroy_func      pthread_cond_destroy;
    toku_pthread_win32_cond_wait_func         pthread_cond_wait;
    toku_pthread_win32_cond_timedwait_func    pthread_cond_timedwait;
    toku_pthread_win32_cond_signal_func       pthread_cond_signal;
    toku_pthread_win32_cond_broadcast_func    pthread_cond_broadcast;

    toku_pthread_win32_rwlock_init_func       pthread_rwlock_init;
    toku_pthread_win32_rwlock_destroy_func    pthread_rwlock_destroy;
    toku_pthread_win32_rwlock_rdlock_func     pthread_rwlock_rdlock;
    toku_pthread_win32_rwlock_wrlock_func     pthread_rwlock_wrlock;
    toku_pthread_win32_rwlock_unlock_func     pthread_rwlock_unlock;

    toku_pthread_win32_create_func            pthread_create;
    toku_pthread_win32_join_func              pthread_join;
    toku_pthread_win32_self_func              pthread_self;
} toku_pthread_win32_funcs;

extern toku_pthread_win32_funcs pthread_win32;

81 82 83

static inline int
toku_pthread_rwlock_init(toku_pthread_rwlock_t *__restrict rwlock, const toku_pthread_rwlockattr_t *__restrict attr) {
Yoni Fogel's avatar
Yoni Fogel committed
84
    return pthread_win32.pthread_rwlock_init(rwlock, attr);
85 86 87 88
}

static inline int
toku_pthread_rwlock_destroy(toku_pthread_rwlock_t *rwlock) {
Yoni Fogel's avatar
Yoni Fogel committed
89
    return pthread_win32.pthread_rwlock_destroy(rwlock);
90 91 92 93
}

static inline int
toku_pthread_rwlock_rdlock(toku_pthread_rwlock_t *rwlock) {
Yoni Fogel's avatar
Yoni Fogel committed
94
    return pthread_win32.pthread_rwlock_rdlock(rwlock);
95 96 97 98
}

static inline int
toku_pthread_rwlock_rdunlock(toku_pthread_rwlock_t *rwlock) {
Yoni Fogel's avatar
Yoni Fogel committed
99
    return pthread_win32.pthread_rwlock_unlock(rwlock);
100 101 102 103
}

static inline int
toku_pthread_rwlock_wrlock(toku_pthread_rwlock_t *rwlock) {
Yoni Fogel's avatar
Yoni Fogel committed
104
    return pthread_win32.pthread_rwlock_wrlock(rwlock);
105 106 107 108
}

static inline int
toku_pthread_rwlock_wrunlock(toku_pthread_rwlock_t *rwlock) {
Yoni Fogel's avatar
Yoni Fogel committed
109
    return pthread_win32.pthread_rwlock_unlock(rwlock);
110
}
111 112 113

int toku_pthread_yield(void);

Yoni Fogel's avatar
Yoni Fogel committed
114

115 116
static inline
int toku_pthread_attr_init(toku_pthread_attr_t *attr) {
Yoni Fogel's avatar
Yoni Fogel committed
117
    return pthread_win32.pthread_attr_init(attr);
118 119 120 121
}

static inline
int toku_pthread_attr_destroy(toku_pthread_attr_t *attr) {
Yoni Fogel's avatar
Yoni Fogel committed
122
    return pthread_win32.pthread_attr_destroy(attr);
123 124 125 126
}

static inline
int toku_pthread_attr_getstacksize(toku_pthread_attr_t *attr, size_t *stacksize) {
Yoni Fogel's avatar
Yoni Fogel committed
127
    return pthread_win32.pthread_attr_getstacksize(attr, stacksize);
128 129 130 131
}

static inline
int toku_pthread_attr_setstacksize(toku_pthread_attr_t *attr, size_t stacksize) {
Yoni Fogel's avatar
Yoni Fogel committed
132
    return pthread_win32.pthread_attr_setstacksize(attr, stacksize);
133 134 135 136
}

static inline
int toku_pthread_create(toku_pthread_t *thread, const toku_pthread_attr_t *attr, void *(*start_function)(void *), void *arg) {
Yoni Fogel's avatar
Yoni Fogel committed
137
    return pthread_win32.pthread_create(thread, attr, start_function, arg);
138 139 140 141
}

static inline
int toku_pthread_join(toku_pthread_t thread, void **value_ptr) {
Yoni Fogel's avatar
Yoni Fogel committed
142
    return pthread_win32.pthread_join(thread, value_ptr);
143 144 145 146
}

static inline
toku_pthread_t toku_pthread_self(void) {
Yoni Fogel's avatar
Yoni Fogel committed
147
    return pthread_win32.pthread_self();
148 149 150 151 152 153
}

#define TOKU_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER

static inline
int toku_pthread_mutex_init(toku_pthread_mutex_t *mutex, const toku_pthread_mutexattr_t *attr) {
Yoni Fogel's avatar
Yoni Fogel committed
154
    return pthread_win32.pthread_mutex_init(mutex, attr);
155 156 157 158
}

static inline
int toku_pthread_mutex_destroy(toku_pthread_mutex_t *mutex) {
Yoni Fogel's avatar
Yoni Fogel committed
159
    return pthread_win32.pthread_mutex_destroy(mutex);
160 161 162 163
}

static inline
int toku_pthread_mutex_lock(toku_pthread_mutex_t *mutex) {
Yoni Fogel's avatar
Yoni Fogel committed
164
    return pthread_win32.pthread_mutex_lock(mutex);
165
}
166 167 168

int toku_pthread_mutex_trylock(toku_pthread_mutex_t *mutex);

169 170
static inline
int toku_pthread_mutex_unlock(toku_pthread_mutex_t *mutex) {
Yoni Fogel's avatar
Yoni Fogel committed
171
    return pthread_win32.pthread_mutex_unlock(mutex);
172 173 174 175
}

static inline
int toku_pthread_cond_init(toku_pthread_cond_t *cond, const toku_pthread_condattr_t *attr) {
Yoni Fogel's avatar
Yoni Fogel committed
176
    return pthread_win32.pthread_cond_init(cond, attr);
177 178 179 180
}

static inline 
int toku_pthread_cond_destroy(toku_pthread_cond_t *cond) {
Yoni Fogel's avatar
Yoni Fogel committed
181
    return pthread_win32.pthread_cond_destroy(cond);
182 183 184 185
}

static inline
int toku_pthread_cond_wait(toku_pthread_cond_t *cond, toku_pthread_mutex_t *mutex) {
Yoni Fogel's avatar
Yoni Fogel committed
186
    return pthread_win32.pthread_cond_wait(cond, mutex);
187 188 189 190
}

static inline
int toku_pthread_cond_timedwait(toku_pthread_cond_t *cond, toku_pthread_mutex_t *mutex, toku_timespec_t *wakeup_at) {
Yoni Fogel's avatar
Yoni Fogel committed
191
    return pthread_win32.pthread_cond_timedwait(cond, mutex, wakeup_at);
192 193 194 195
}

static inline
int toku_pthread_cond_signal(toku_pthread_cond_t *cond) {
Yoni Fogel's avatar
Yoni Fogel committed
196
    return pthread_win32.pthread_cond_signal(cond);
197 198 199 200
}

static inline
int toku_pthread_cond_broadcast(toku_pthread_cond_t *cond) {
Yoni Fogel's avatar
Yoni Fogel committed
201
    return pthread_win32.pthread_cond_broadcast(cond);
202
}
203

Yoni Fogel's avatar
Yoni Fogel committed
204 205 206 207 208
int
initialize_pthread_functions();

int
pthread_functions_free();
209 210


211
#if defined(__cplusplus)
212 213 214 215
};
#endif

#endif