Commit 60f7d6ef authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1640 Reported toku_pthread_rwlocks to windows XP (merge from #1510)

git-svn-id: file:///svn/toku/tokudb@11028 c7de825b-a66e-492c-adef-691d508d4ae1
parent 631fe49f
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#ifndef TOKU_RWLOCK_H
#define TOKU_RWLOCK_H
//Use case:
// A read lock is acquired by threads that get and pin an entry in the
// cachetable. A write lock is acquired by the writer thread when an entry
......@@ -120,3 +123,6 @@ static inline int rwlock_writers(RWLOCK rwlock) {
static inline int rwlock_users(RWLOCK rwlock) {
return rwlock->reader + rwlock->want_read + rwlock->writer + rwlock->want_write;
}
#endif
......@@ -2,7 +2,7 @@
.DEFAULT_GOAL=install
TOKUROOT=../
INCLUDEDIRS=-I.
INCLUDEDIRS=-I. -I$(TOKUROOT)newbrt
SKIP_LIBPORTABILITYRULE=1
include $(TOKUROOT)toku_include/Makefile.include
......
#include <toku_portability.h>
#include <windows.h>
#include <assert.h>
#include <errno.h>
......@@ -7,46 +8,55 @@ int
toku_pthread_rwlock_init(toku_pthread_rwlock_t *restrict rwlock, const toku_pthread_rwlockattr_t *restrict attr) {
assert(attr == NULL);
// assert(!rwlock->initialized);
InitializeSRWLock(&rwlock->rwlock);
int r = toku_pthread_mutex_init(&rwlock->mutex, NULL);
if (r==0) {
rwlock_init(&rwlock->rwlock);
rwlock->initialized = TRUE;
return 0;
}
return r;
}
int
toku_pthread_rwlock_destroy(toku_pthread_rwlock_t *rwlock) {
assert(rwlock->initialized);
int r = toku_pthread_mutex_destroy(&rwlock->mutex);
if (r==0) {
rwlock_destroy(&rwlock->rwlock);
rwlock->initialized = FALSE;
//Windows does not have a cleanup function for SRWLocks.
//You just stop using them.
return 0;
}
return r;
}
int
toku_pthread_rwlock_rdlock(toku_pthread_rwlock_t *rwlock) {
assert(rwlock->initialized);
AcquireSRWLockShared(&rwlock->rwlock);
return 0;
int r = toku_pthread_mutex_lock(&rwlock->mutex);
if (r==0) rwlock_read_lock(&rwlock->rwlock, &rwlock->mutex);
return r;
}
int
toku_pthread_rwlock_rdunlock(toku_pthread_rwlock_t *rwlock) {
assert(rwlock->initialized);
ReleaseSRWLockShared(&rwlock->rwlock);
return 0;
int r = toku_pthread_mutex_lock(&rwlock->mutex);
if (r==0) rwlock_read_unlock(&rwlock->rwlock);
return r;
}
int
toku_pthread_rwlock_wrlock(toku_pthread_rwlock_t *rwlock) {
assert(rwlock->initialized);
AcquireSRWLockExclusive(&rwlock->rwlock);
return 0;
int r = toku_pthread_mutex_lock(&rwlock->mutex);
if (r==0) rwlock_write_lock(&rwlock->rwlock, &rwlock->mutex);
return r;
}
int
toku_pthread_rwlock_wrunlock(toku_pthread_rwlock_t *rwlock) {
assert(rwlock->initialized);
ReleaseSRWLockExclusive(&rwlock->rwlock);
return 0;
int r = toku_pthread_mutex_unlock(&rwlock->mutex);
if (r==0) rwlock_write_unlock(&rwlock->rwlock);
return r;
}
int
......
......@@ -23,11 +23,6 @@ typedef struct toku_pthread {
typedef struct toku_pthread_rwlockattr *toku_pthread_rwlockattr_t;
typedef struct toku_pthread_rwlock {
SRWLOCK rwlock;
BOOL initialized;
} toku_pthread_rwlock_t;
typedef struct toku_pthread_mutexattr *toku_pthread_mutexattr_t;
typedef struct toku_pthread_mutex {
......@@ -35,6 +30,8 @@ typedef struct toku_pthread_mutex {
BOOL initialized;
} toku_pthread_mutex_t;
typedef struct toku_pthread_rwlock toku_pthread_rwlock_t;
#define TOKU_PTHREAD_MUTEX_INITIALIZER { 0, 0 }
typedef struct toku_pthread_condattr *toku_pthread_condattr_t;
......@@ -94,6 +91,15 @@ int toku_pthread_cond_signal(toku_pthread_cond_t *cond);
int toku_pthread_cond_broadcast(toku_pthread_cond_t *cond);
#include <toku_assert.h>
#include "rwlock.h"
struct toku_pthread_rwlock {
struct rwlock rwlock;
toku_pthread_mutex_t mutex;
BOOL initialized;
};
#if defined(__cplusplus)
};
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment