Lazily allocate state for multi-writer instances
Multiple writers for a single instance is pretty rare, so it makes sense to lazily allocate the tables for keeping track of them. The more elegant solution would be to have a single lock-free table. Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
parent
0e888eb2ec
commit
260f8cd86b
1 changed files with 7 additions and 4 deletions
|
@ -192,30 +192,33 @@ static int lwreg_equals (const void *va, const void *vb)
|
|||
|
||||
static void lwregs_init (struct lwregs *rt)
|
||||
{
|
||||
rt->regs = ddsrt_ehh_new (sizeof (struct lwreg), 1, lwreg_hash, lwreg_equals);
|
||||
rt->regs = NULL;
|
||||
}
|
||||
|
||||
static void lwregs_fini (struct lwregs *rt)
|
||||
{
|
||||
if (rt->regs)
|
||||
ddsrt_ehh_free (rt->regs);
|
||||
}
|
||||
|
||||
static int lwregs_contains (struct lwregs *rt, uint64_t iid, uint64_t wr_iid)
|
||||
{
|
||||
struct lwreg dummy = { .iid = iid, .wr_iid = wr_iid };
|
||||
return ddsrt_ehh_lookup (rt->regs, &dummy) != NULL;
|
||||
return rt->regs != NULL && ddsrt_ehh_lookup (rt->regs, &dummy) != NULL;
|
||||
}
|
||||
|
||||
static int lwregs_add (struct lwregs *rt, uint64_t iid, uint64_t wr_iid)
|
||||
{
|
||||
struct lwreg dummy = { .iid = iid, .wr_iid = wr_iid };
|
||||
if (rt->regs == NULL)
|
||||
rt->regs = ddsrt_ehh_new (sizeof (struct lwreg), 1, lwreg_hash, lwreg_equals);
|
||||
return ddsrt_ehh_add (rt->regs, &dummy);
|
||||
}
|
||||
|
||||
static int lwregs_delete (struct lwregs *rt, uint64_t iid, uint64_t wr_iid)
|
||||
{
|
||||
struct lwreg dummy = { .iid = iid, .wr_iid = wr_iid };
|
||||
return ddsrt_ehh_remove (rt->regs, &dummy);
|
||||
return rt->regs != NULL && ddsrt_ehh_remove (rt->regs, &dummy);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue