previous | start | next

db.h an db.c:

Add an member of type pthread_rwlock_t to the node type Node_t

Modify Node_constructor function to initialize this extra member.

Use a enum for the two lock types (in db.c is ok):

enum lock_type = {dblock_read, dblock_write};

Add a parameter to the search function in db.c for lock_type.

Modify query, add, and xremove functions to call search with the appropriate lock_type value. E.g., query should call with dblock_read.

For fine grain locking, only nodes that are involved in being changed need be locked. As search moves down the tree, how many nodes need to be locked?

Before calling search, query, add, and xremove should lock the head node.

When search returns, query, add, and xremove should unlock node(s) that remain locked, but this depends on which function called search and/or whether the search was successful (found the name).



previous | start | next