Sha256: 70f562279fcdbb59a13379d41daf352b2e21c7bf9bbd6ffc6d329c01506205da

Contents?: true

Size: 1.44 KB

Versions: 35

Compression:

Stored size: 1.44 KB

Contents

#ifdef _WIN32
#include <cassert>
#include <windows.h>
#include <process.h>
#include "threads.h"

extern "C"
{
unsigned int __stdcall
startfunc(void * param)
{
    Thread *thr = reinterpret_cast<Thread *>(param);
    thr->doRun();
    return 0;
}
}

Thread::Thread(StartFunc thrfn, void *param)
{
    fn = thrfn;
    fnparam = param;
    uintptr_t rv;
    rv = _beginthreadex(NULL, 0, startfunc, this, 0, NULL);
    assert(rv);
    hThread = (HANDLE)rv;
    initialized = true;
}

void
Thread::join()
{
    WaitForSingleObject(hThread, INFINITE);
}

void
Thread::close()
{
    if (initialized) {
        join();
        CloseHandle(hThread);
        initialized = false;
    }
}

Thread::~Thread()
{
    close();
}

Mutex::Mutex()
{
    InitializeCriticalSection(&cs);
    initialized = true;
}

Mutex::~Mutex()
{
    close();
}

void
Mutex::close()
{
    if (initialized) {
        DeleteCriticalSection(&cs);
        initialized = false;
    }
}

void
Mutex::lock()
{
    EnterCriticalSection(&cs);
}

bool
Mutex::tryLock()
{
    return TryEnterCriticalSection(&cs) == TRUE;
}

void
Mutex::unlock()
{
    LeaveCriticalSection(&cs);
}


Condvar::Condvar()
{
    InitializeConditionVariable(&cv);
    initialized = true;
}

void
Condvar::close()
{
    initialized = false;
}

Condvar::~Condvar()
{
    close();
}

void
Condvar::signal()
{
    WakeConditionVariable(&cv);
}

void
Condvar::wait(Mutex& mutex)
{
    SleepConditionVariableCS(&cv, &mutex.cs, INFINITE);
}
#endif

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
mt-libcouchbase-1.4.03 ext/libcouchbase/tests/ioserver/threads-win32.cc
mt-libcouchbase-1.4.02 ext/libcouchbase/tests/ioserver/threads-win32.cc
mt-libcouchbase-1.4.01 ext/libcouchbase/tests/ioserver/threads-win32.cc
mt-libcouchbase-1.4.0 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.3.2 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.3.0 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.2.8 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.2.7 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.2.6 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.2.5 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.2.4 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.2.3 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.2.2 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.2.1 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.2.0 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.1.1 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.1.0 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.0.4 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.0.3 ext/libcouchbase/tests/ioserver/threads-win32.cc
libcouchbase-1.0.2 ext/libcouchbase/tests/ioserver/threads-win32.cc