toku_pthread.c 2.25 KB
Newer Older
1 2
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
3
#include <toku_portability.h>
4 5
#include <windows.h>
#include <toku_pthread.h>
Yoni Fogel's avatar
Yoni Fogel committed
6
#include "toku_assert.h"
7 8 9 10 11 12 13

int
toku_pthread_yield(void) {
    Sleep(0);
    return 0;
}

Yoni Fogel's avatar
Yoni Fogel committed
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
toku_pthread_win32_funcs pthread_win32 = {0};
HMODULE pthread_win32_dll = NULL;


//TODO: add a portability_init/destroy function (call in brt_init)
//TODO: Call in portability_init


int
toku_pthread_win32_init(void) {
    int r = 0;
    pthread_win32_dll = NULL;
    memset(&pthread_win32, 0, sizeof(pthread_win32));

    pthread_win32_dll = LoadLibrary(TEXT("pthreadVC2"));
    if (pthread_win32_dll == NULL)
        r = GetLastError();
    else {
#define LOAD_PTHREAD_FUNC(name) do { \
        pthread_win32.pthread_ ## name = (toku_pthread_win32_ ## name ## _func) GetProcAddress(pthread_win32_dll, "pthread_" #name); \
        assert(pthread_win32.pthread_ ## name != NULL); \
    } while (0)

        LOAD_PTHREAD_FUNC(attr_init);
        LOAD_PTHREAD_FUNC(attr_destroy);
        LOAD_PTHREAD_FUNC(attr_getstacksize);
        LOAD_PTHREAD_FUNC(attr_setstacksize);

        LOAD_PTHREAD_FUNC(mutex_init);
        LOAD_PTHREAD_FUNC(mutex_destroy);
        LOAD_PTHREAD_FUNC(mutex_lock);
        LOAD_PTHREAD_FUNC(mutex_trylock);
        LOAD_PTHREAD_FUNC(mutex_unlock);

        LOAD_PTHREAD_FUNC(cond_init);
        LOAD_PTHREAD_FUNC(cond_destroy);
        LOAD_PTHREAD_FUNC(cond_wait);
        LOAD_PTHREAD_FUNC(cond_timedwait);
        LOAD_PTHREAD_FUNC(cond_signal);
        LOAD_PTHREAD_FUNC(cond_broadcast);

        LOAD_PTHREAD_FUNC(rwlock_init);
        LOAD_PTHREAD_FUNC(rwlock_destroy);
        LOAD_PTHREAD_FUNC(rwlock_rdlock);
        LOAD_PTHREAD_FUNC(rwlock_wrlock);
        LOAD_PTHREAD_FUNC(rwlock_unlock);

        LOAD_PTHREAD_FUNC(create);
        LOAD_PTHREAD_FUNC(join);
        LOAD_PTHREAD_FUNC(self);
64 65 66 67 68

        LOAD_PTHREAD_FUNC(key_create);
        LOAD_PTHREAD_FUNC(key_delete);
        LOAD_PTHREAD_FUNC(getspecific);
        LOAD_PTHREAD_FUNC(setspecific);
Yoni Fogel's avatar
Yoni Fogel committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82
#undef LOAD_PTHREAD_FUNC
    }
    return r;
}

//TODO: Call in brt_destroy
int toku_pthread_win32_destroy(void) {
    assert(pthread_win32_dll != NULL);
    BOOL succ = FreeLibrary(pthread_win32_dll);
    assert(succ);
    return 0;
}