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 -*- */ /* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#ifndef TOKU_RWLOCK_H
#define TOKU_RWLOCK_H
//Use case: //Use case:
// A read lock is acquired by threads that get and pin an entry in the // 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 // cachetable. A write lock is acquired by the writer thread when an entry
...@@ -120,3 +123,6 @@ static inline int rwlock_writers(RWLOCK rwlock) { ...@@ -120,3 +123,6 @@ static inline int rwlock_writers(RWLOCK rwlock) {
static inline int rwlock_users(RWLOCK rwlock) { static inline int rwlock_users(RWLOCK rwlock) {
return rwlock->reader + rwlock->want_read + rwlock->writer + rwlock->want_write; return rwlock->reader + rwlock->want_read + rwlock->writer + rwlock->want_write;
} }
#endif
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
.DEFAULT_GOAL=install .DEFAULT_GOAL=install
TOKUROOT=../ TOKUROOT=../
INCLUDEDIRS=-I. INCLUDEDIRS=-I. -I$(TOKUROOT)newbrt
SKIP_LIBPORTABILITYRULE=1 SKIP_LIBPORTABILITYRULE=1
include $(TOKUROOT)toku_include/Makefile.include include $(TOKUROOT)toku_include/Makefile.include
......
#include <toku_portability.h>
#include <windows.h> #include <windows.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
...@@ -7,46 +8,55 @@ int ...@@ -7,46 +8,55 @@ int
toku_pthread_rwlock_init(toku_pthread_rwlock_t *restrict rwlock, const toku_pthread_rwlockattr_t *restrict attr) { toku_pthread_rwlock_init(toku_pthread_rwlock_t *restrict rwlock, const toku_pthread_rwlockattr_t *restrict attr) {
assert(attr == NULL); assert(attr == NULL);
// assert(!rwlock->initialized); // assert(!rwlock->initialized);
InitializeSRWLock(&rwlock->rwlock); int r = toku_pthread_mutex_init(&rwlock->mutex, NULL);
rwlock->initialized = TRUE; if (r==0) {
return 0; rwlock_init(&rwlock->rwlock);
rwlock->initialized = TRUE;
}
return r;
} }
int int
toku_pthread_rwlock_destroy(toku_pthread_rwlock_t *rwlock) { toku_pthread_rwlock_destroy(toku_pthread_rwlock_t *rwlock) {
assert(rwlock->initialized); assert(rwlock->initialized);
rwlock->initialized = FALSE; int r = toku_pthread_mutex_destroy(&rwlock->mutex);
//Windows does not have a cleanup function for SRWLocks. if (r==0) {
//You just stop using them. rwlock_destroy(&rwlock->rwlock);
return 0; rwlock->initialized = FALSE;
}
return r;
} }
int int
toku_pthread_rwlock_rdlock(toku_pthread_rwlock_t *rwlock) { toku_pthread_rwlock_rdlock(toku_pthread_rwlock_t *rwlock) {
assert(rwlock->initialized); assert(rwlock->initialized);
AcquireSRWLockShared(&rwlock->rwlock); int r = toku_pthread_mutex_lock(&rwlock->mutex);
return 0; if (r==0) rwlock_read_lock(&rwlock->rwlock, &rwlock->mutex);
return r;
} }
int int
toku_pthread_rwlock_rdunlock(toku_pthread_rwlock_t *rwlock) { toku_pthread_rwlock_rdunlock(toku_pthread_rwlock_t *rwlock) {
assert(rwlock->initialized); assert(rwlock->initialized);
ReleaseSRWLockShared(&rwlock->rwlock); int r = toku_pthread_mutex_lock(&rwlock->mutex);
return 0; if (r==0) rwlock_read_unlock(&rwlock->rwlock);
return r;
} }
int int
toku_pthread_rwlock_wrlock(toku_pthread_rwlock_t *rwlock) { toku_pthread_rwlock_wrlock(toku_pthread_rwlock_t *rwlock) {
assert(rwlock->initialized); assert(rwlock->initialized);
AcquireSRWLockExclusive(&rwlock->rwlock); int r = toku_pthread_mutex_lock(&rwlock->mutex);
return 0; if (r==0) rwlock_write_lock(&rwlock->rwlock, &rwlock->mutex);
return r;
} }
int int
toku_pthread_rwlock_wrunlock(toku_pthread_rwlock_t *rwlock) { toku_pthread_rwlock_wrunlock(toku_pthread_rwlock_t *rwlock) {
assert(rwlock->initialized); assert(rwlock->initialized);
ReleaseSRWLockExclusive(&rwlock->rwlock); int r = toku_pthread_mutex_unlock(&rwlock->mutex);
return 0; if (r==0) rwlock_write_unlock(&rwlock->rwlock);
return r;
} }
int int
......
...@@ -23,11 +23,6 @@ typedef struct toku_pthread { ...@@ -23,11 +23,6 @@ typedef struct toku_pthread {
typedef struct toku_pthread_rwlockattr *toku_pthread_rwlockattr_t; 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_mutexattr *toku_pthread_mutexattr_t;
typedef struct toku_pthread_mutex { typedef struct toku_pthread_mutex {
...@@ -35,6 +30,8 @@ typedef struct toku_pthread_mutex { ...@@ -35,6 +30,8 @@ typedef struct toku_pthread_mutex {
BOOL initialized; BOOL initialized;
} toku_pthread_mutex_t; } toku_pthread_mutex_t;
typedef struct toku_pthread_rwlock toku_pthread_rwlock_t;
#define TOKU_PTHREAD_MUTEX_INITIALIZER { 0, 0 } #define TOKU_PTHREAD_MUTEX_INITIALIZER { 0, 0 }
typedef struct toku_pthread_condattr *toku_pthread_condattr_t; typedef struct toku_pthread_condattr *toku_pthread_condattr_t;
...@@ -94,6 +91,15 @@ int toku_pthread_cond_signal(toku_pthread_cond_t *cond); ...@@ -94,6 +91,15 @@ int toku_pthread_cond_signal(toku_pthread_cond_t *cond);
int toku_pthread_cond_broadcast(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) #if defined(__cplusplus)
}; };
#endif #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