Commit c4b12449 authored by Yoni Fogel's avatar Yoni Fogel

Closes #1790 Merge from 2.0.1 into main. Also add tests to freebsd.

svn merge --accept=postpone -r 12459:12461 ../../mysql.branches/2.0.1/tokudb/

git-svn-id: file:///svn/toku/tokudb@12462 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0c84b972
../../linux/tests/test-pthread-rwlock-rdlock.c
\ No newline at end of file
../../linux/tests/test-pthread-rwlock-rwr.c
\ No newline at end of file
../../windows/tests/test-pthread-rwlock-rdlock.c
\ No newline at end of file
../../windows/tests/test-pthread-rwlock-rwr.c
\ No newline at end of file
......@@ -71,9 +71,6 @@ static inline void rwlock_read_lock(RWLOCK rwlock, toku_pthread_mutex_t *mutex)
}
// TODO: #1398 Get rid of this hack.
#ifdef BRT_LEVEL_STRADDLE_CALLBACK_LOGIC_NOT_READY
// preferentially obtain a read lock (ignore request for write lock)
// expects: mutex is locked
......@@ -83,7 +80,6 @@ static inline void rwlock_prefer_read_lock(RWLOCK rwlock, toku_pthread_mutex_t *
else
rwlock_read_lock(rwlock, mutex);
}
#endif
// release a read lock
......
#include <toku_assert.h>
#include <test.h>
#include <toku_pthread.h>
#include <stdio.h>
#include <unistd.h>
int test_main(int argc, char *argv[]) {
int r;
toku_pthread_rwlock_t rwlock;
r = toku_pthread_rwlock_init(&rwlock, NULL); assert(r == 0);
r = toku_pthread_rwlock_rdlock(&rwlock); assert(r == 0);
r = toku_pthread_rwlock_rdlock(&rwlock); assert(r == 0);
r = toku_pthread_rwlock_rdunlock(&rwlock); assert(r == 0);
r = toku_pthread_rwlock_rdunlock(&rwlock); assert(r == 0);
r = toku_pthread_rwlock_destroy(&rwlock); assert(r == 0);
return 0;
}
#include <toku_assert.h>
#include <test.h>
#include <toku_pthread.h>
#include <stdio.h>
#include <unistd.h>
void *f(void *arg) {
int r;
toku_pthread_rwlock_t *mylock = arg;
printf("%s:%d\n", __FUNCTION__, __LINE__); fflush(stdout);
r = toku_pthread_rwlock_wrlock(mylock); assert(r == 0);
printf("%s:%d\n", __FUNCTION__, __LINE__); fflush(stdout);
r = toku_pthread_rwlock_wrunlock(mylock); assert(r == 0);
printf("%s:%d\n", __FUNCTION__, __LINE__); fflush(stdout);
return arg;
}
int test_main(int argc, char *argv[]) {
int r;
toku_pthread_rwlock_t rwlock;
toku_pthread_t tid;
void *retptr;
r = toku_pthread_rwlock_init(&rwlock, NULL); assert(r == 0);
printf("%s:%d\n", __FUNCTION__, __LINE__); fflush(stdout);
r = toku_pthread_rwlock_rdlock(&rwlock); assert(r == 0);
r = toku_pthread_create(&tid, NULL, f, &rwlock); assert(r == 0);
printf("%s:%d\n", __FUNCTION__, __LINE__); fflush(stdout);
sleep(10);
printf("%s:%d\n", __FUNCTION__, __LINE__); fflush(stdout);
r = toku_pthread_rwlock_rdlock(&rwlock); assert(r == 0);
printf("%s:%d\n", __FUNCTION__, __LINE__); fflush(stdout);
r = toku_pthread_rwlock_rdunlock(&rwlock); assert(r == 0);
printf("%s:%d\n", __FUNCTION__, __LINE__); fflush(stdout);
r = toku_pthread_rwlock_rdunlock(&rwlock); assert(r == 0);
printf("%s:%d\n", __FUNCTION__, __LINE__); fflush(stdout);
r = toku_pthread_join(tid, &retptr); assert(r == 0);
r = toku_pthread_rwlock_destroy(&rwlock); assert(r == 0);
return 0;
}
......@@ -8,6 +8,7 @@ extern "C" {
#include "pthread.h"
#include <toku_time.h>
#define USE_PTHREADS_WIN32_RWLOCKS 0
int toku_pthread_win32_init(void);
int toku_pthread_win32_destroy(void);
......@@ -17,8 +18,18 @@ 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;
#if USE_PTHREADS_WIN32_RWLOCKS
typedef pthread_rwlock_t toku_pthread_rwlock_t;
typedef pthread_rwlockattr_t toku_pthread_rwlockattr_t;
#else
#include <rwlock.h>
typedef struct toku_pthread_rwlock_struct {
struct rwlock rwlock;
toku_pthread_mutex_t mutex;
} toku_pthread_rwlock_t;
typedef struct toku_pthread_rwlockattr_struct {
} toku_pthread_rwlockattr_t;
#endif
//typedef struct timespec toku_timespec_t; //Already defined in toku_time.h
......@@ -79,36 +90,6 @@ typedef struct toku_pthread_win32_funcs_struct {
extern toku_pthread_win32_funcs pthread_win32;
static inline int
toku_pthread_rwlock_init(toku_pthread_rwlock_t *__restrict rwlock, const toku_pthread_rwlockattr_t *__restrict attr) {
return pthread_win32.pthread_rwlock_init(rwlock, attr);
}
static inline int
toku_pthread_rwlock_destroy(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_destroy(rwlock);
}
static inline int
toku_pthread_rwlock_rdlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_rdlock(rwlock);
}
static inline int
toku_pthread_rwlock_rdunlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_unlock(rwlock);
}
static inline int
toku_pthread_rwlock_wrlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_wrlock(rwlock);
}
static inline int
toku_pthread_rwlock_wrunlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_unlock(rwlock);
}
int toku_pthread_yield(void);
......@@ -201,6 +182,102 @@ int toku_pthread_cond_broadcast(toku_pthread_cond_t *cond) {
return pthread_win32.pthread_cond_broadcast(cond);
}
#if USE_PTHREADS_WIN32_RWLOCKS
static inline int
toku_pthread_rwlock_init(toku_pthread_rwlock_t *__restrict rwlock, const toku_pthread_rwlockattr_t *__restrict attr) {
return pthread_win32.pthread_rwlock_init(rwlock, attr);
}
static inline int
toku_pthread_rwlock_destroy(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_destroy(rwlock);
}
static inline int
toku_pthread_rwlock_rdlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_rdlock(rwlock);
}
static inline int
toku_pthread_rwlock_rdunlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_unlock(rwlock);
}
static inline int
toku_pthread_rwlock_wrlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_wrlock(rwlock);
}
static inline int
toku_pthread_rwlock_wrunlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_unlock(rwlock);
}
#else
static inline int
toku_pthread_rwlock_init(toku_pthread_rwlock_t *__restrict rwlock, const toku_pthread_rwlockattr_t *__restrict attr) {
int r = 0;
if (attr!=NULL) r = EINVAL;
if (r==0)
r = toku_pthread_mutex_init(&rwlock->mutex, NULL);
if (r==0)
rwlock_init(&rwlock->rwlock);
return r;
}
static inline int
toku_pthread_rwlock_destroy(toku_pthread_rwlock_t *rwlock) {
int r = 0;
rwlock_destroy(&rwlock->rwlock);
r = toku_pthread_mutex_destroy(&rwlock->mutex);
return r;
}
static inline int
toku_pthread_rwlock_rdlock(toku_pthread_rwlock_t *rwlock) {
int r = 0;
r = toku_pthread_mutex_lock(&rwlock->mutex);
assert(r==0);
//We depend on recursive read locks.
rwlock_prefer_read_lock(&rwlock->rwlock, &rwlock->mutex);
r = toku_pthread_mutex_unlock(&rwlock->mutex);
assert(r==0);
return r;
}
static inline int
toku_pthread_rwlock_rdunlock(toku_pthread_rwlock_t *rwlock) {
int r = 0;
r = toku_pthread_mutex_lock(&rwlock->mutex);
assert(r==0);
rwlock_read_unlock(&rwlock->rwlock);
r = toku_pthread_mutex_unlock(&rwlock->mutex);
assert(r==0);
return r;
}
static inline int
toku_pthread_rwlock_wrlock(toku_pthread_rwlock_t *rwlock) {
int r = 0;
r = toku_pthread_mutex_lock(&rwlock->mutex);
assert(r==0);
rwlock_write_lock(&rwlock->rwlock, &rwlock->mutex);
r = toku_pthread_mutex_unlock(&rwlock->mutex);
assert(r==0);
return r;
}
static inline int
toku_pthread_rwlock_wrunlock(toku_pthread_rwlock_t *rwlock) {
int r = 0;
r = toku_pthread_mutex_lock(&rwlock->mutex);
assert(r==0);
rwlock_write_unlock(&rwlock->rwlock);
r = toku_pthread_mutex_unlock(&rwlock->mutex);
assert(r==0);
return r;
}
#endif
int
initialize_pthread_functions();
......
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