Created
October 3, 2013 16:23
-
-
Save itsff/6812653 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct my_element | |
{ | |
int my_element_data; | |
/* Placement of container-specific node data can be easily modified for locality | |
optimization */ | |
struct container__slist_node slist_node; | |
/* A single element can be linked into multiple containers */ | |
struct container__hash_node hash_node; | |
}; | |
void | |
InsertElement (...) | |
{ | |
struct my_element* el; | |
/* Allocate elements using any mechanism desired */ | |
el = malloc(sizeof(struct my_element)); | |
el->my_element_data = 42; | |
/* Perform locking only during the insertion, allowing potentially costly allocations and | |
initializations to occur outside the lock */ | |
pthread_mutex_lock(&my_slist_lock); | |
Container_AddSListHead(&el->slist_node, &my_slist); | |
pthread_mutex_unlock(&my_slist_lock); | |
/* Easily allow external libraries to operate on the container */ | |
ExternalLibUpdate(&el->hash_node, &my_hash); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment