CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
trfifo.cxh
1/// @brief FIFO-ordered task resource
2///
3/// @defgroup taskresource_fifo FIFO
4/// @ingroup taskresource
5/// @{
6///
7/// TRFifo provides strictly ordered FIFO (First In, First Out) serialization of task execution.
8/// Tasks are guaranteed to run in exactly the order they registered with the resource.
9///
10/// **Characteristics:**
11/// - Linked list implementation scales efficiently to many waiters
12/// - Strict FIFO ordering guaranteed
13/// - Only one task runs at a time (serialized)
14/// - No possibility for tasks to "cut in line"
15///
16/// **When to use:**
17/// - Need guaranteed execution order
18/// - Large number of waiting tasks
19/// - Processing queue-like workloads
20/// - Serializing access to order-dependent resources
21///
22/// **Example use case:**
23/// Serializing writes to a file or database where order matters.
24/// @}
25#include "taskresource.cxh"
26#include <cx/thread/mutex.h>
27
28class ComplexTask;
29
30/// @addtogroup taskresource_fifo
31/// @{
32/// Linked list node for FIFO queue.
33struct TRFifoNode;
34
35typedef struct TRFifoNode {
36 TRFifoNode *next; ///< Next node in queue
37 ComplexTask *task; ///< Task waiting in queue
38} TRFifoNode;
39
40/// Strictly ordered FIFO resource for serialized task execution.
41class TRFifo extends TaskResource {
42 Mutex _fifomtx;
43 ComplexTask *cur; ///< Currently running task
44 TRFifoNode *head; ///< Head of wait queue
45 TRFifoNode *tail; ///< Tail of wait queue
46
47 /// Create a new FIFO-ordered resource.
48 /// @return New TRFifo instance
49 factory create();
50}
51
52/// @}