static void test_all(TestBatchRunner *runner) { LockFreeRegistry *registry = LFReg_new(10); StupidHashCharBuf *foo = StupidHashCharBuf_new("foo"); StupidHashCharBuf *bar = StupidHashCharBuf_new("bar"); StupidHashCharBuf *baz = StupidHashCharBuf_new("baz"); StupidHashCharBuf *foo_dupe = StupidHashCharBuf_new("foo"); TEST_TRUE(runner, LFReg_Register(registry, (Obj*)foo, (Obj*)foo), "Register() returns true on success"); TEST_FALSE(runner, LFReg_Register(registry, (Obj*)foo_dupe, (Obj*)foo_dupe), "Can't Register() keys that test equal"); TEST_TRUE(runner, LFReg_Register(registry, (Obj*)bar, (Obj*)bar), "Register() key with the same Hash_Sum but that isn't Equal"); TEST_TRUE(runner, LFReg_Fetch(registry, (Obj*)foo_dupe) == (Obj*)foo, "Fetch()"); TEST_TRUE(runner, LFReg_Fetch(registry, (Obj*)bar) == (Obj*)bar, "Fetch() again"); TEST_TRUE(runner, LFReg_Fetch(registry, (Obj*)baz) == NULL, "Fetch() non-existent key returns NULL"); DECREF(foo_dupe); DECREF(baz); DECREF(bar); DECREF(foo); DECREF(registry); }
void Class_init_registry() { LockFreeRegistry *reg = LFReg_new(256); if (Atomic_cas_ptr((void*volatile*)&Class_registry, NULL, reg)) { return; } else { DECREF(reg); } }