Allows threads of a single process to wait for a certain condition.
If the condition is true a call to <trywakeup_waitlist> wakes up the first thread in the waiting list. Before it is woken up its task arguments are set to the values given as arguments in the function <trywakeup_waitlist>.
Waitlist | Allows threads of a single process to wait for a certain condition. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file of Waitlist. |
C-kern/ | Linux specific implementation file Waitlist Linuximpl. |
Types | |
struct waitlist_t | Exports waitlist_t. |
Functions | |
test | |
unittest_platform_sync_waitlist | Tests waitlist functionality. |
waitlist_t | Allows threads of a single process to wait for a certain condition. |
last | The root pointer of the list of waiting threads. |
nr_waiting | The number of threads waiting. |
lockflag | Lock flag used to protect access to data members. |
lifetime | |
waitlist_FREE | Static initializer. |
init_waitlist | Inits a waiting list. |
free_waitlist | Wakes up all waiting threads and frees all resources. |
query | |
isempty_waitlist | Returns true if no thread is waiting else false. |
nrwaiting_waitlist | Returns the number of threads waiting on this list. |
synchronize | |
wait_waitlist | Suspends the calling thread until some other calls trywakeup_waitlist. |
trywakeup_waitlist | Tries to wake up the first waiting thread. |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2011 Jörg Seebohn
Header file of Waitlist.
Linux specific implementation file Waitlist Linuximpl.
typedef struct waitlist_t waitlist_t
Exports waitlist_t.
test | |
unittest_platform_sync_waitlist | Tests waitlist functionality. |
struct waitlist_t
Allows threads of a single process to wait for a certain condition. Similar to semaphore_t. The difference is that a thread’s »command« parameter is set to a specific value. Therefore a woken up thread knows what to do next.
This object is thread safe.
last | The root pointer of the list of waiting threads. |
nr_waiting | The number of threads waiting. |
lockflag | Lock flag used to protect access to data members. |
lifetime | |
waitlist_FREE | Static initializer. |
init_waitlist | Inits a waiting list. |
free_waitlist | Wakes up all waiting threads and frees all resources. |
query | |
isempty_waitlist | Returns true if no thread is waiting else false. |
nrwaiting_waitlist | Returns the number of threads waiting on this list. |
synchronize | |
wait_waitlist | Suspends the calling thread until some other calls trywakeup_waitlist. |
trywakeup_waitlist | Tries to wake up the first waiting thread. |
#define waitlist_FREE { 0, 0, 0 }
Static initializer. After initialization it is safe to call free_waitlist.
int free_waitlist( waitlist_t * wlist )
Wakes up all waiting threads and frees all resources. Make sure that no more other thread is trying to call wait_waitlist if free_waitlist is processing or was already called.
bool isempty_waitlist( waitlist_t * wlist )
Returns true if no thread is waiting else false. Before testing the lock on the list is acquired.
But in case more than one thread calls trywakeup_waitlist you can not be sure that trywakeup_waitlist does not return EAGAIN even if isempty_waitlist returns false.
size_t nrwaiting_waitlist( waitlist_t * wlist )
Returns the number of threads waiting on this list. Before testing the lock on the list is acquired.
But in case more than one thread calls trywakeup_waitlist you can not be sure that trywakeup_waitlist does not return EAGAIN even if nrwaiting_waitlist returns a value greater 0.
int wait_waitlist( waitlist_t * wlist )
Suspends the calling thread until some other calls trywakeup_waitlist. The waiting threads are woken up in FIFO order. The calling thread enters itself as last in the waiting list and then it suspends itself. See also <suspend_thread>.
int trywakeup_waitlist( waitlist_t * wlist, int (*main_task)(void * main_arg), void * main_arg )
Tries to wake up the first waiting thread. If the list is empty EAGAIN is returned and no error is logged. If the list is not empty the first waiting thread gets its main_task and main_arg set. Thie first thread is removed from the list and then resumed.
Exports waitlist_t.
typedef struct waitlist_t waitlist_t
Allows threads of a single process to wait for a certain condition.
struct waitlist_t
Tests waitlist functionality.
int unittest_platform_sync_waitlist( void )
The root pointer of the list of waiting threads.
struct slist_node_t * last
The number of threads waiting.
size_t nr_waiting
Lock flag used to protect access to data members.
uint8_t lockflag
Static initializer.
#define waitlist_FREE { 0, 0, 0 }
Inits a waiting list.
int init_waitlist( /*out*/waitlist_t * wlist )
Wakes up all waiting threads and frees all resources.
int free_waitlist( waitlist_t * wlist )
Returns true if no thread is waiting else false.
bool isempty_waitlist( waitlist_t * wlist )
Returns the number of threads waiting on this list.
size_t nrwaiting_waitlist( waitlist_t * wlist )
Suspends the calling thread until some other calls trywakeup_waitlist.
int wait_waitlist( waitlist_t * wlist )
Tries to wake up the first waiting thread.
int trywakeup_waitlist( waitlist_t * wlist, int (*main_task)(void * main_arg), void * main_arg )