void delete_nodes_with_no_hazards() { // first claims the entire list of nodes to be reclaimed; // ensures that this is the only thread trying to reclaim // this particular set of nodes; other threads are now free // to add futher nodes to the list or event try to reclaim // them without impacting the operation of this thread. data_to_reclaim* current = nodes_to_reclaim.exchange(nullptr); while (current) { data_to_reclaim* const next = current->next; // check each node in turn to see if there are any outstanding // hazard pointers. if (!outstanding_hazard_pointers_for(current->data)) { // if there aren't, delete the entry delete current; } else { // otherwise, just add the item back on the list for // reclaiming later add_to_reclaim_list(current); } current=next; } }
// travel through the reclaim list, check if it is hazardous to delete a node // if not delete it // This portion is computation intensive and needs to be optimized. void delete_nodes_with_no_hazards() { data_to_reclaim *current = nodes_to_reclaim.exchange(nullptr); while (current) { data_to_reclaim *const next = current->next; if (!outstanding_hazard_pointers_for(current->data)) { // not a hazard pointer, delete node delete current; } else { // chain to another list to delete later add_to_reclaim_list(current); } current = next; } }
void reclaim_later(T *data) { add_to_reclaim_list(new data_to_reclaim(data)); }