2013-04-16 23:57:53 -04:00
|
|
|
#include <test.h>
|
2013-04-16 23:59:01 -04:00
|
|
|
#include <toku_assert.h>
|
2013-04-16 23:57:53 -04:00
|
|
|
#include <toku_pthread.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2013-04-16 23:58:59 -04:00
|
|
|
static void *f(void *arg) {
|
2013-04-16 23:57:53 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-16 23:59:20 -04:00
|
|
|
int test_main(int argc __attribute__((__unused__)), char *const argv[] __attribute__((__unused__))) {
|
2013-04-16 23:57:53 -04:00
|
|
|
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;
|
|
|
|
}
|