construct a database-alike table using C

I want to construct such a table in my program(linux C):

it has 3 items:

1 ip/port pair, 2 a FIFO queue pointer, 3 a process id or thread id

my program has two kinds of functions(or modules, whatever): A and B

when function A gets a packet, it will first look up the IP/PORT pair(by comparing the source address of the packet). If there is an item with the IP/PORT pair, A inserts the packet to the corresponding FIFO queue. Otherwise, A create an item (IP/PORT, FIFO queue pointer, null) in the table and put the packet to the corresponding FIFO. The item (IP/PORT, FIFO queue pointer, null) now doesn't have a PID or TID.

when a function B is notified an ip/port pair, it will fork a process or thread and look up the table by the notified IP/PORT pair. If there is no corresponding item, it will create an item (IP/PORT, FIFO queue pointer, pid/tid). Otherwise, it registers the pid(or tid) of forked process(or thread) to that item, namely fill the null field in (IP/PORT, FIFO queue pointer, null). And it immediately fetch all the packets from the FIFO queue.

if A create an item (IP/PORT, FIFO queue pointer, null), the item is created with a timeout value. If the timeout has reached and no process/thread is registered to this item(namely function B doesn't get notified a corresponding IP/PORT). The item should be removed from the table.

Each process/thread forked by B should frequently poll the FIFO queue in its corresponding item(or when A gets a packet, it signals the corresponding thread/process by looking up the table), if there are packets, the process/thread will fetch them, which empty the queue.

indeed, for the table, the challenges and requirements are:

1 there are mutex issues among A and processes/threads spawned by B.
2 table lookup efficiency
3 polling or signalling efficiency
4 removal upon timeout

so my question is: how to construct such a table? can I use light-weight database like sqlite? or are there any similar source code snippets? thanks!
Topic archived. No new replies allowed.