2024-12-01 19:35:24 +00:00
|
|
|
//| Copyright: (C) 2020-2024 Kevin Larke <contact AT larke DOT org>
|
|
|
|
//| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
|
2020-03-04 19:05:54 +00:00
|
|
|
#ifndef cwMutex_H
|
|
|
|
#define cwMutex_H
|
|
|
|
|
|
|
|
namespace cw
|
|
|
|
{
|
|
|
|
namespace mutex
|
|
|
|
{
|
|
|
|
typedef handle<struct mutex_str> handle_t;
|
|
|
|
|
|
|
|
rc_t create( handle_t& h );
|
|
|
|
rc_t destroy( handle_t& h );
|
|
|
|
|
|
|
|
rc_t tryLock( handle_t h, bool& lockFlRef );
|
2022-12-12 17:19:56 +00:00
|
|
|
rc_t lock( handle_t h, unsigned timeout_milliseconds );
|
2020-03-04 19:05:54 +00:00
|
|
|
rc_t lock( handle_t h );
|
|
|
|
rc_t unlock( handle_t h );
|
|
|
|
|
2024-09-13 19:10:14 +00:00
|
|
|
// Set timeOutMs to 0 to wait forever.
|
|
|
|
//
|
2021-01-20 18:07:36 +00:00
|
|
|
// Set 'lockThenWaitFl' if the function should lock the mutex prior to waiting.
|
|
|
|
// If 'lockThenWaitFl' is false then the function assumes the mutex is already locked
|
|
|
|
// and directly waits. If 'lockThenWaitFl' is set and the mutex is not already locked
|
|
|
|
// then the result is undefined.
|
2021-01-22 14:33:23 +00:00
|
|
|
//
|
|
|
|
// Note that this function does NOT check for 'spurious wakeups' - when
|
|
|
|
// the condition var. returns (w/ the mutex locked) even though it was
|
|
|
|
// not acutally signals. If it matters to the application then it must
|
|
|
|
// provide this logic.
|
2020-03-04 19:05:54 +00:00
|
|
|
rc_t waitOnCondVar( handle_t h, bool lockThenWaitFl, unsigned timeOutMs );
|
|
|
|
|
2021-01-20 18:07:36 +00:00
|
|
|
rc_t signalCondVar( handle_t h);
|
2020-03-04 19:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|