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,24 +68,15 @@ ck_rwlock_write_downgrade(ck_rwlock_t *rw)
} }
CK_CC_INLINE static bool 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 (ck_pr_fas_uint(&rw->writer, 1) != 0)
if (++steps >= factor) return false;
return false;
ck_pr_stall();
}
while (ck_pr_load_uint(&rw->n_readers) != 0) {
if (++steps >= factor) {
ck_rwlock_write_unlock(rw);
return false;
}
ck_pr_stall(); if (ck_pr_load_uint(&rw->n_readers) != 0) {
ck_rwlock_write_unlock(rw);
return false;
} }
ck_pr_fence_store(); ck_pr_fence_store();
@ -107,27 +98,19 @@ ck_rwlock_write_lock(ck_rwlock_t *rw)
} }
CK_CC_INLINE static bool 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)
return false;
ck_pr_stall();
}
ck_pr_inc_uint(&rw->n_readers); if (ck_pr_load_uint(&rw->writer) != 0)
if (ck_pr_load_uint(&rw->writer) == 0) return false;
break;
ck_pr_dec_uint(&rw->n_readers);
if (++steps >= factor) ck_pr_inc_uint(&rw->n_readers);
return false; if (ck_pr_load_uint(&rw->writer) == 0)
} goto leave;
ck_pr_dec_uint(&rw->n_readers);
return false;
leave:
ck_pr_fence_load(); ck_pr_fence_load();
return true; return true;
} }
@ -236,7 +219,7 @@ CK_CC_INLINE static bool
ck_rwlock_recursive_read_trylock(ck_rwlock_recursive_t *rw) 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 CK_CC_INLINE static void

@ -11,4 +11,4 @@ clean:
rm -rf *.dSYM *~ *.o $(OBJECTS) rm -rf *.dSYM *~ *.o $(OBJECTS)
include ../../../build/regressions.build 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" #include "../../common.h"
#ifndef ITERATE #ifndef ITERATE
#define ITERATE 5000000 #define ITERATE 1000000
#endif #endif
static struct affinity a; static struct affinity a;
@ -64,22 +64,13 @@ thread_recursive(void *null CK_CC_UNUSED)
} }
while (i--) { while (i--) {
if ((i % 10000) == 0) { while (ck_rwlock_recursive_write_trylock(&r_lock, t) == false)
while (ck_rwlock_recursive_write_trylock(&r_lock, t) == false) ck_pr_stall();
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); 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); l = ck_pr_load_uint(&locked);
if (l != 0) { 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);
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); ck_rwlock_recursive_read_lock(&r_lock);
{ {
l = ck_pr_load_uint(&locked); 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);
ck_rwlock_recursive_read_unlock(&r_lock);
} }
return (NULL); return (NULL);

Loading…
Cancel
Save