CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
trmutex.cxh
1/// @brief Mutex-based task resource
2///
3/// @defgroup taskresource_mutex Mutex
4/// @ingroup taskresource
5/// @{
6///
7/// TRMutex provides mutex-based serialization of task execution. Tasks requiring this resource
8/// will run one at a time, with approximate FIFO ordering.
9///
10/// **Characteristics:**
11/// - Simple hashtable-based wait list
12/// - Approximate FIFO ordering (not strictly guaranteed)
13/// - Good for moderate numbers of waiting tasks
14/// - Can be locked by non-task code (call wakeup() after releasing)
15///
16/// **When to use:**
17/// - Moderate contention levels (dozens of tasks)
18/// - Ordering is helpful but not critical
19/// - Simple exclusive access pattern
20///
21/// **Alternatives:**
22/// - Use TRFifo for strict FIFO ordering or large numbers of waiters
23/// - Use TRLifo for stack ordering (most recent first)
24/// @}
25#include "taskresource.cxh"
26#include <cx/thread/mutex.h>
27
28class ComplexTask;
29
30/// @addtogroup taskresource_mutex
31/// @{
32/// Simple mutex-based resource with approximate FIFO ordering.
33class TRMutex extends TaskResource {
34 Mutex mtx; ///< The actual mutex providing exclusive access
35
36 /// Manually release a task from wait list.
37 /// Call this after releasing mtx if locked from non-task code.
38 void wakeup();
39
40 Mutex _wlmtx;
41 hashtable:object:none _waitlist; ///< Tasks waiting for this resource
42
43 /// Create a new mutex-based resource.
44 /// @return New TRMutex instance
45 factory create();
46}
47
48/// @}