bool RCUList::search(int key, int *valuep) { bool result = FALSE; Element *current; rcuLock.readLock(); current = head; for (current = head; current != NULL; current = current->next) { if (current->key == key) { *valuep = current->value; result = TRUE; break; } } rcuLock.readUnlock(); return result; } void RCUList::insert(int key, int value) { Element *item; // One write at a time. rcuLock.writeLock(); // Initialize item. item = (Element*) malloc(sizeof(Element)); item->key = key; item->value = value; item->next = head; // Atomically update list. rcuLock.publish(&head, item); // Allow other writes // to proceed. rcuLock.writeUnlock(); // Wait until no reader // has old version. rcuLock.synchronize(); } bool RCUList::remove(int key) { bool found = FALSE; Element *prev, *current; // One write at a time. rcuLock.WriteLock(); for (prev = NULL, current = head; current != NULL; prev = current, current = current->next) { if (current->key == key) { found = TRUE; // Publish update to readers if (prev == NULL) { rcuLock.publish(&head, current->next); } else { rcuLock.publish(&(prev->next), current->next); } break; } } // Allow other writes to proceed. rcuLock.writeUnlock(); // Wait until no reader has old version. if (found) { rcuLock.synchronize(); free(current); } return found; }