Struct cmb_condition
Defined in File cmb_condition.h
Struct Documentation
-
struct cmb_condition
A condition variable class that allows a process to wait for an arbitrary condition to become true and be reactivated at that point. It does not assign any resource, just signals that the condition is fulfilled. The application provides the demand predicate function to be evaluated.
Public Functions
-
struct cmb_condition *cmb_condition_create(void)
Allocate memory for a condition variable.
- Returns:
Pointer to an allocated condition variable.
-
void cmb_condition_initialize(struct cmb_condition *cvp, const char *name)
Make an allocated condition variable ready for use.
- Parameters:
cvp – Pointer to an allocated condition variable.
name – A null-terminated string naming the condition variable.
-
void cmb_condition_destroy(struct cmb_condition *cvp)
Deallocates memory for a condition variable.
- Parameters:
cvp – Pointer to an allocated condition variable.
-
int64_t cmb_condition_wait(struct cmb_condition *cvp, cmb_condition_demand_func *dmnd, const void *ctx)
Make the current process wait for the given demand to be satisfied, expressed as a predicate function that returns a boolean answer based on whatever state.
- Parameters:
cvp – Pointer to a condition variable.
dmnd – The demand predicate function.
ctx – The context argument to the demand predicate function.
- Returns:
CMB_PROCESS_SUCCESSif successful, otherwise the signal received when interrupted.
-
uint64_t cmb_condition_signal(struct cmb_condition *cvp)
Re-evaluate the demand predicate for all waiting processes and reactivate those that evaluate as
true.- Parameters:
cvp – Pointer to a condition variable.
- Returns:
Number of waiting processes reactivated
-
bool cmb_condition_cancel(struct cmb_condition *cvp, struct cmb_process *pp)
Remove the process from the priority queue and resume it with a
CMB_PROCESS_CANCELLEDsignal.- Parameters:
cvp – Pointer to a condition variable.
pp – Pointer to a process, presumably waiting for the condition
- Returns:
trueif the found,falseif not.
-
bool cmb_condition_remove(struct cmb_condition *cvp, const struct cmb_process *pp)
Remove the process from the priority queue without resuming it. Used e.g., when stopping a process and cancelling its appointments.
- Parameters:
cvp – Pointer to a condition variable.
pp – Pointer to a process, presumably waiting for the condition
- Returns:
trueif the found,falseif not.
Public Members
-
struct cmi_resourcebase base
The parent class, providing name and initialization
-
struct cmb_resourceguard guard
Providing the queueing mechanics
Public Static Functions
-
static inline void cmb_condition_subscribe(struct cmb_condition *cvp, struct cmb_resourceguard *rgp)
Subscribe this condition variable to signals from the other resource guard.
- Parameters:
cvp – Pointer to a condition variable.
rgp – Pointer to a resource guard.
-
static inline bool cmb_condition_unsubscribe(struct cmb_condition *cvp, struct cmb_resourceguard *rgp)
Unsubscribe this condition variable to signals from the other resource guard.
- Parameters:
cvp – Pointer to a condition variable.
rgp – Pointer to a resource guard.
- Returns:
trueif the found,falseif not.
-
struct cmb_condition *cmb_condition_create(void)