Skip to content

Commit

Permalink
Merge pull request #3539 from pbalcer/obj-threadsafe-obj-init
Browse files Browse the repository at this point in the history
obj: make obj_pool_init threadsafe
  • Loading branch information
marcinslusarz authored Jan 30, 2019
2 parents 712458c + adc456f commit e140590
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/libpmemobj/obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,31 @@ obj_ctl_init_and_load(PMEMobjpool *pop)
*
* This is invoked on a first call to pmemobj_open() or pmemobj_create().
* Memory is released in library destructor.
*
* This function needs to be threadsafe.
*/
static void
obj_pool_init(void)
{
LOG(3, NULL);

if (pools_ht)
return;
struct critnib *c;

pools_ht = critnib_new();
if (pools_ht == NULL)
FATAL("!critnib_new for pools_ht");
if (pools_ht == NULL) {
c = critnib_new();
if (c == NULL)
FATAL("!critnib_new for pools_ht");
if (!util_bool_compare_and_swap64(&pools_ht, NULL, c))
critnib_delete(c);
}

pools_tree = critnib_new();
if (pools_tree == NULL)
FATAL("!critnib_new for pools_tree");
if (pools_tree == NULL) {
c = critnib_new();
if (c == NULL)
FATAL("!critnib_new for pools_tree");
if (!util_bool_compare_and_swap64(&pools_tree, NULL, c))
critnib_delete(c);
}
}

/*
Expand Down

0 comments on commit e140590

Please sign in to comment.