Skip to content

Instantly share code, notes, and snippets.

@tophyr
Created September 21, 2012 22:55
Show Gist options
  • Save tophyr/3764382 to your computer and use it in GitHub Desktop.
Save tophyr/3764382 to your computer and use it in GitHub Desktop.
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;
}
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