Skip to content

Commit

Permalink
refcounter: remove unexpected behaviour parts
Browse files Browse the repository at this point in the history
* bplus: ref page_copy in compact
  • Loading branch information
indutny committed Jan 26, 2012
1 parent 54ca52f commit 64fefba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/bplus.c
Expand Up @@ -154,8 +154,13 @@ int bp_compact(bp_tree_t* tree) {
free(compacted_name);
if (ret != BP_OK) return ret;

bp__ref((bp__ref_t*) tree);

/* copy all pages starting from root */
ret = bp__page_copy(tree, &compacted, tree->head.page);

bp__unref((bp__ref_t*) tree);

if (ret != BP_OK) return ret;

/* compacted tree already has a head page, free it first */
Expand All @@ -173,7 +178,6 @@ int bp_compact(bp_tree_t* tree) {
(bp__writer_t*) &compacted);

bp__ref_open((bp__ref_t*) tree);

return ret;
}

Expand Down
6 changes: 0 additions & 6 deletions src/refcounter.c
Expand Up @@ -31,12 +31,6 @@ void bp__ref_destroy(bp__ref_t* handle) {

void bp__ref(bp__ref_t* handle) {
SCOPED_LOCK(handle->ref_lock, {
if (handle->ref_state != kOpen) {
bp__mutex_unlock(&handle->ref_lock);
bp__mutex_lock(&handle->ref_state_lock);
bp__mutex_unlock(&handle->ref_state_lock);
bp__mutex_lock(&handle->ref_lock);
}
/*
* pause close requests until handle will have ref == 0
*/
Expand Down
17 changes: 17 additions & 0 deletions test/test-threaded-rw.cc
Expand Up @@ -37,20 +37,37 @@ void* test_writer(void* db_) {
return NULL;
}

void* test_compact(void* db_) {
bp_tree_t* db = (bp_tree_t*) db_;
int ret;

for (int i = 0; i < items; i++) {
usleep(33000);
ret = bp_compact(db);
fprintf(stdout, "%x\n", ret);
assert(ret == BP_OK);
}

return NULL;
}

TEST_START("threaded read/write test", "threaded-rw")

const int n = 10;
pthread_t readers[n];
pthread_t writers[n];
pthread_t compact;

for (int i = 0; i < n; i++) {
assert(pthread_create(&readers[i], NULL, test_reader, (void*) &db) == 0);
assert(pthread_create(&writers[i], NULL, test_writer, (void*) &db) == 0);
}
// assert(pthread_create(&compact, NULL, test_compact, (void*) &db) == 0);

for (int i = 0; i < n; i++) {
assert(pthread_join(readers[i], NULL) == 0);
assert(pthread_join(writers[i], NULL) == 0);
}
// assert(pthread_join(compact, NULL) == 0);

TEST_END("threaded read/write test", "threaded-rw")

0 comments on commit 64fefba

Please sign in to comment.