AIStatefulTask ‐ Asynchronous, Stateful Task Scheduler library.

Threads-like task objects evolving through user-defined states.

Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
AIStatefulTaskMutex Class Reference

Detailed Description

A task mutex.

Prevent different tasks from concurrently entering the same critical area.

Consider an object that is shared between tasks, but may not be simultaneously accessed by two different threads.

For example,

// Required memory management. utils::MemoryPagePool mpp(0x8000); // A task mutex. AIStatefulTaskMutex m;

Then multiple running tasks could use this to prevent concurrent access:

... case MyTask_wait_for_lock: set_state(MyTask_locked); if (!m.lock(this, 1)) { wait(1); break; } [[fallthrough]]; case MyTask_locked: { statefultask::AdoptLock lock(m); do_work(); lock.unlock(); // Optional ... code that does not require the lock... }

#include <AIStatefulTaskMutex.h>

Public Member Functions

 AIStatefulTaskMutex ()
 Construct an unlocked AIStatefulTaskMutex.
Node const * lock (AIStatefulTask *task, condition_type condition)
 Try to obtain ownership for owner (recursive locking allowed). More...
void unlock ()
 Undo one (succcessful) call to lock.
Node const * lock_blocking (AIStatefulTask *task)

Static Public Member Functions

static constexpr size_t node_size ()
 Returns the size of the nodes that will be allocated from s_node_memory_resource.
static void init (utils::MemoryPagePool *mpp_ptr)
 This must be called once before using a AIStatefulTaskMutex.

Static Public Attributes

static utils::NodeMemoryResource s_node_memory_resource
 Memory resource to allocate Node's from.


class AIStatefulTask

Member Function Documentation

◆ lock()

Node const * AIStatefulTaskMutex::lock ( AIStatefulTask task,
condition_type  condition 

Try to obtain ownership for owner (recursive locking allowed).

A handle pointer upon success and nullptr upon failure to obtain ownership.

The returned handle must be passed to is_self_locked.

The documentation for this class was generated from the following files: