ck_rwlock: Drop factor argument to trylock API.

Remove read-side recursion tests, it is an unsupported
feature to begin with.
ck_pring
Samy Al Bahra 13 years ago
parent 512bbc050b
commit 314ce3ad81

@ -68,26 +68,17 @@ ck_rwlock_write_downgrade(ck_rwlock_t *rw)
}
CK_CC_INLINE static bool
ck_rwlock_write_trylock(ck_rwlock_t *rw, unsigned int factor)
ck_rwlock_write_trylock(ck_rwlock_t *rw)
{
unsigned int steps = 0;
while (ck_pr_fas_uint(&rw->writer, 1) != 0) {
if (++steps >= factor)
if (ck_pr_fas_uint(&rw->writer, 1) != 0)
return false;
ck_pr_stall();
}
while (ck_pr_load_uint(&rw->n_readers) != 0) {
if (++steps >= factor) {
if (ck_pr_load_uint(&rw->n_readers) != 0) {
ck_rwlock_write_unlock(rw);
return false;
}
ck_pr_stall();
}
ck_pr_fence_store();
return true;
}
@ -107,27 +98,19 @@ ck_rwlock_write_lock(ck_rwlock_t *rw)
}
CK_CC_INLINE static bool
ck_rwlock_read_trylock(ck_rwlock_t *rw, unsigned int factor)
ck_rwlock_read_trylock(ck_rwlock_t *rw)
{
unsigned int steps = 0;
for (;;) {
while (ck_pr_load_uint(&rw->writer) != 0) {
if (++steps >= factor)
if (ck_pr_load_uint(&rw->writer) != 0)
return false;
ck_pr_stall();
}
ck_pr_inc_uint(&rw->n_readers);
if (ck_pr_load_uint(&rw->writer) == 0)
break;
goto leave;
ck_pr_dec_uint(&rw->n_readers);
if (++steps >= factor)
return false;
}
leave:
ck_pr_fence_load();
return true;
}
@ -236,7 +219,7 @@ CK_CC_INLINE static bool
ck_rwlock_recursive_read_trylock(ck_rwlock_recursive_t *rw)
{
return ck_rwlock_read_trylock(&rw->rw, 1);
return ck_rwlock_read_trylock(&rw->rw);
}
CK_CC_INLINE static void

@ -11,4 +11,4 @@ clean:
rm -rf *.dSYM *~ *.o $(OBJECTS)
include ../../../build/regressions.build
CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE
CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE -g3 -O0

@ -41,7 +41,7 @@
#include "../../common.h"
#ifndef ITERATE
#define ITERATE 5000000
#define ITERATE 1000000
#endif
static struct affinity a;
@ -64,22 +64,13 @@ thread_recursive(void *null CK_CC_UNUSED)
}
while (i--) {
if ((i % 10000) == 0) {
while (ck_rwlock_recursive_write_trylock(&r_lock, t) == false)
ck_pr_stall();
} else {
ck_rwlock_recursive_write_lock(&r_lock, t);
}
ck_rwlock_recursive_write_lock(&r_lock, t);
ck_rwlock_recursive_write_lock(&r_lock, t);
ck_rwlock_recursive_write_lock(&r_lock, t);
if (ck_rwlock_recursive_write_trylock(&r_lock, t) == false) {
fprintf(stderr, "ERROR: write_trylock failed.\n");
exit(EXIT_FAILURE);
}
{
l = ck_pr_load_uint(&locked);
if (l != 0) {
@ -121,16 +112,7 @@ thread_recursive(void *null CK_CC_UNUSED)
ck_rwlock_recursive_write_unlock(&r_lock);
ck_rwlock_recursive_write_unlock(&r_lock);
ck_rwlock_recursive_write_unlock(&r_lock);
ck_rwlock_recursive_write_unlock(&r_lock);
if ((i % 10000) == 0) {
while (ck_rwlock_recursive_read_trylock(&r_lock) == false)
ck_pr_stall();
} else {
ck_rwlock_recursive_read_lock(&r_lock);
}
ck_rwlock_recursive_read_lock(&r_lock);
ck_rwlock_recursive_read_lock(&r_lock);
{
l = ck_pr_load_uint(&locked);
@ -140,8 +122,6 @@ thread_recursive(void *null CK_CC_UNUSED)
}
}
ck_rwlock_recursive_read_unlock(&r_lock);
ck_rwlock_recursive_read_unlock(&r_lock);
ck_rwlock_recursive_read_unlock(&r_lock);
}
return (NULL);

Loading…
Cancel
Save