Add a list_shift() function to the common linked list code.

git-svn-id: file:///home/svn/framework3/trunk@10052 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Stephen Fewer 2010-08-19 11:25:11 +00:00
parent 7d560e9c18
commit fd0b96ee9d
2 changed files with 29 additions and 3 deletions

View File

@ -2,9 +2,9 @@
/*
* An implementation of a simple thread safe double linked list structure. Can be used as either
* a stack (via pop/push) or an array (via get/add/insert/remove). If performing a group of
* actions on a list based on results from list actions, acquire the list lock before the group
* of actions and release lock when done.
* a stack (via pop/push), a queue (via push/shift) or an array (via get/add/insert/remove). If
* performing a group of actions on a list based on results from list actions, acquire the list
* lock before the group of actions and release lock when done.
*/
/*
@ -308,5 +308,29 @@ LPVOID list_pop( LIST * list )
lock_release( list->lock );
return data;
}
/*
* Pop a data value off the start of the list.
*/
LPVOID list_shift( LIST * list )
{
LPVOID data = NULL;
if( list == NULL )
return NULL;
lock_acquire( list->lock );
if( list->start != NULL )
{
data = list->start->data;
list_remove_node( list, list->start );
}
lock_release( list->lock );
return data;
}

View File

@ -38,6 +38,8 @@ BOOL list_push( LIST * list, LPVOID data );
LPVOID list_pop( LIST * list );
LPVOID list_shift( LIST * list );
/*****************************************************************************************/
#endif