Created
September 21, 2012 22:55
-
-
Save tophyr/3764382 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
void filter(list_item *item, int (*passes)(list_item *item)) | |
{ | |
pthread_mutex_lock(&list_lock); | |
while (item != NULL) | |
{ | |
if (!passes(item)) | |
_remove_internal(item); | |
item = item->next; | |
} | |
pthread_mutex_unlock(&list_lock); | |
} | |
void remove(list_item *item) | |
{ | |
pthread_mutex_lock(&list_lock); | |
_remove_internal(item); | |
pthread_mutex_unlock(&list_lock); | |
} | |
void _remove_internal(list_item *item) | |
{ | |
if (item->prev != NULL) | |
item->prev->next = item->next; | |
if (item->next != NULL) | |
item->next->prev = item->prev; | |
} |
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
void filter(list_item *item, int (*passes)(list_item *item)) | |
{ | |
pthread_mutex_lock(&list_lock); | |
while (item != NULL) | |
{ | |
if (!passes(item)) | |
remove(item); | |
item = item->next; | |
} | |
pthread_mutex_unlock(&list_lock); | |
} | |
void remove(list_item *item) | |
{ | |
pthread_mutex_lock(&list_lock); | |
if (item->prev != NULL) | |
item->prev->next = item->next; | |
if (item->next != NULL) | |
item->next->prev = item->prev; | |
pthread_mutex_unlock(&list_lock); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment