Offers inter thread mutex which works closely with thread_t
InterThreadMutex | Offers inter thread mutex which works closely with thread_t |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file InterThreadMutex. |
C-kern/ | Implementation file InterThreadMutex impl. |
Types | |
struct thrmutex_t | Export thrmutex_t into global namespace. |
Functions | |
test | |
unittest_platform_sync_thrmutex | Test thrmutex_t functionality. |
thrmutex_t | Mutual exclusion lock. |
last | Points to last entry in list of waiting threads. |
lockholder | The threads which acquired the lock and is allowed to run. |
lockflag | Lock flag used to protect access to data members. |
lifetime | |
thrmutex_FREE | Static initializer. |
thrmutex_INIT | Static initializer. |
init_thrmutex | Sets mutex to thrmutex_INIT. |
free_thrmutex | Checks that no one is waiting and sets mutex to thrmutex_FREE. |
query | |
isfree_thrmutex | Returns true if mutex equals thrmutex_FREE. |
islocked_thrmutex | Returns true if a thread locked the mutex. |
iswaiting_thrmutex | Returns true if mutex is locked and wait list is not empty. |
lockholder_thrmutex | Returns the thread which locked the mutex. |
synchronize | |
lock_thrmutex | Locks the mutex. |
unlock_thrmutex | Unlocks the mutex. |
safe-synchronize | |
slock_thrmutex | Calls lock_thrmutex and asserts success. |
sunlock_thrmutex | Calls sunlock_thrmutex and asserts success. |
inline implementation | |
Macros | |
init_thrmutex | Implements thrmutex_t.init_thrmutex. |
slock_thrmutex | Implements thrmutex_t.slock_thrmutex. |
sunlock_thrmutex | Implements thrmutex_t.sunlock_thrmutex. |
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.
© 2013 Jörg Seebohn
Header file InterThreadMutex.
Implementation file InterThreadMutex impl.
typedef struct thrmutex_t thrmutex_t
Export thrmutex_t into global namespace.
test | |
unittest_platform_sync_thrmutex | Test thrmutex_t functionality. |
int unittest_platform_sync_thrmutex( void )
Test thrmutex_t functionality.
struct thrmutex_t
Mutual exclusion lock. Used to synchronize access to a data structure shared between multiple threads. If you want to share data between processes use mutex_t. Call <lock_threamutex> before you want to use the data structure. Call <unlock_threadmutex> after you no longer need access to it.
last | Points to last entry in list of waiting threads. |
lockholder | The threads which acquired the lock and is allowed to run. |
lockflag | Lock flag used to protect access to data members. |
lifetime | |
thrmutex_FREE | Static initializer. |
thrmutex_INIT | Static initializer. |
init_thrmutex | Sets mutex to thrmutex_INIT. |
free_thrmutex | Checks that no one is waiting and sets mutex to thrmutex_FREE. |
query | |
isfree_thrmutex | Returns true if mutex equals thrmutex_FREE. |
islocked_thrmutex | Returns true if a thread locked the mutex. |
iswaiting_thrmutex | Returns true if mutex is locked and wait list is not empty. |
lockholder_thrmutex | Returns the thread which locked the mutex. |
synchronize | |
lock_thrmutex | Locks the mutex. |
unlock_thrmutex | Unlocks the mutex. |
safe-synchronize | |
slock_thrmutex | Calls lock_thrmutex and asserts success. |
sunlock_thrmutex | Calls sunlock_thrmutex and asserts success. |
struct thread_t * lockholder
The threads which acquired the lock and is allowed to run. If this value is 0 last is also 0 and the no one has locked the mutex.
#define thrmutex_INIT { 0, 0, 0 }
Static initializer. Used in function init_thrmutex.
void init_thrmutex( /*out*/thrmutex_t * mutex )
Sets mutex to thrmutex_INIT.
int free_thrmutex( thrmutex_t * mutex )
Checks that no one is waiting and sets mutex to thrmutex_FREE. Returns EBUSY and does nothing if anyone holds the lock.
bool isfree_thrmutex( thrmutex_t * mutex )
Returns true if mutex equals thrmutex_FREE.
bool islocked_thrmutex( thrmutex_t * mutex )
Returns true if a thread locked the mutex. If this functions returns true lockholder_thrmutex returns a value != 0.
bool iswaiting_thrmutex( thrmutex_t * mutex )
Returns true if mutex is locked and wait list is not empty. If a thread calls lock_thrmutex but the mutex is already locked it is stored in an internal wait list.
int lock_thrmutex( thrmutex_t * mutex )
Locks the mutex. If the mutex is already locked the caller is stored into an internal wait list as last entry and then it is suspended. If the lockholder calls unlock_thrmutex the first thread on the wait list is resumed and returns from this function. The function returns EDEADLK if the caller already locked the mutex. Recursive calls to lock and unlock are not supported.
void slock_thrmutex( thrmutex_t * mutex )
Calls lock_thrmutex and asserts success.
void sunlock_thrmutex( thrmutex_t * mutex )
Calls sunlock_thrmutex and asserts success.
Macros | |
init_thrmutex | Implements thrmutex_t.init_thrmutex. |
slock_thrmutex | Implements thrmutex_t.slock_thrmutex. |
sunlock_thrmutex | Implements thrmutex_t.sunlock_thrmutex. |
#define init_thrmutex( mutex ) ((void)(*(mutex) = (thrmutex_t) thrmutex_INIT))
Implements thrmutex_t.init_thrmutex.
#define slock_thrmutex( mutex ) (assert(!lock_thrmutex(mutex)))
Implements thrmutex_t.slock_thrmutex.
#define sunlock_thrmutex( mutex ) (assert(!unlock_thrmutex(mutex)))
Implements thrmutex_t.sunlock_thrmutex.
Export thrmutex_t into global namespace.
typedef struct thrmutex_t thrmutex_t
Mutual exclusion lock.
struct thrmutex_t
Test thrmutex_t functionality.
int unittest_platform_sync_thrmutex( void )
Points to last entry in list of waiting threads.
struct slist_node_t * last
The threads which acquired the lock and is allowed to run.
struct thread_t * lockholder
Lock flag used to protect access to data members.
uint8_t lockflag
Static initializer.
#define thrmutex_FREE { 0, 0, 0 }
Static initializer.
#define thrmutex_INIT { 0, 0, 0 }
Sets mutex to thrmutex_INIT.
void init_thrmutex( /*out*/thrmutex_t * mutex )
Checks that no one is waiting and sets mutex to thrmutex_FREE.
int free_thrmutex( thrmutex_t * mutex )
Returns true if mutex equals thrmutex_FREE.
bool isfree_thrmutex( thrmutex_t * mutex )
Returns true if a thread locked the mutex.
bool islocked_thrmutex( thrmutex_t * mutex )
Returns true if mutex is locked and wait list is not empty.
bool iswaiting_thrmutex( thrmutex_t * mutex )
Returns the thread which locked the mutex.
struct thread_t * lockholder_thrmutex( thrmutex_t * mutex )
Locks the mutex.
int lock_thrmutex( thrmutex_t * mutex )
Unlocks the mutex.
int unlock_thrmutex( thrmutex_t * mutex )
Calls lock_thrmutex and asserts success.
void slock_thrmutex( thrmutex_t * mutex )
Calls sunlock_thrmutex and asserts success.
void sunlock_thrmutex( thrmutex_t * mutex )
Implements thrmutex_t.init_thrmutex.
#define init_thrmutex( mutex ) ((void)(*(mutex) = (thrmutex_t) thrmutex_INIT))
Implements thrmutex_t.slock_thrmutex.
#define slock_thrmutex( mutex ) (assert(!lock_thrmutex(mutex)))
Implements thrmutex_t.sunlock_thrmutex.
#define sunlock_thrmutex( mutex ) (assert(!unlock_thrmutex(mutex)))