µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
Condition variables

C API condition variable definitions. More...

Classes

struct  os_condvar_attr_s
 Condition variable attributes. More...
 
struct  os_condvar_s
 Condition variable object storage. More...
 

Typedefs

typedef struct os_condvar_attr_s os_condvar_attr_t
 Condition variable attributes.
 
typedef struct os_condvar_s os_condvar_t
 Condition variable object storage.
 

Condition Variable Attributes Functions

void os_condvar_attr_init (os_condvar_attr_t *attr)
 Initialise the condition variable attributes.
 

Condition Variable Creation Functions

void os_condvar_construct (os_condvar_t *condvar, const char *name, const os_condvar_attr_t *attr)
 Construct a statically allocated condition variable object instance.
 
void os_condvar_destruct (os_condvar_t *condvar)
 Destruct the statically allocated condition variable object instance.
 
os_condvar_tos_condvar_new (const char *name, const os_condvar_attr_t *attr)
 Allocate a condition variable object instance and construct it.
 
void os_condvar_delete (os_condvar_t *condvar)
 Destruct the condition variable object instance and deallocate it.
 

Condition Variable Functions

const char * os_condvar_get_name (os_condvar_t *condvar)
 Get the condition variable name.
 
os_result_t os_condvar_signal (os_condvar_t *condvar)
 Notify one thread waiting for a condition variable.
 
os_result_t os_condvar_broadcast (os_condvar_t *condvar)
 Notify all threads waiting for a condition variable.
 
os_result_t os_condvar_wait (os_condvar_t *condvar, os_mutex_t *mutex)
 Wait for a condition variable to be notified.
 
os_result_t os_condvar_timed_wait (os_condvar_t *condvar, os_mutex_t *mutex, os_clock_duration_t timeout)
 Timed wait for a condition variable to be notified.
 

Compatibility Macros

#define os_condvar_create   os_condvar_construct
 
#define os_condvar_destroy   os_condvar_destruct
 

Detailed Description

For the complete definition, see
RTOS C++ API
Examples
int
os_main (int argc, char* argv[])
{
{
os_condvar_construct (&cv1, "cv1", NULL);
// TODO: test os_condvar_wait()
name = os_condvar_get_name (&cv1);
}
}
os_result_t os_condvar_signal(os_condvar_t *condvar)
Notify one thread waiting for a condition variable.
void os_condvar_construct(os_condvar_t *condvar, const char *name, const os_condvar_attr_t *attr)
Construct a statically allocated condition variable object instance.
void os_condvar_destruct(os_condvar_t *condvar)
Destruct the statically allocated condition variable object instance.
const char * os_condvar_get_name(os_condvar_t *condvar)
Get the condition variable name.
os_result_t os_condvar_broadcast(os_condvar_t *condvar)
Notify all threads waiting for a condition variable.
int os_main(int argc, char *argv[])
Application entry point, running on the main thread context.
Condition variable object storage.

Macro Definition Documentation

◆ os_condvar_create

#define os_condvar_create   os_condvar_construct

Definition at line 1652 of file os-c-api.h.

◆ os_condvar_destroy

#define os_condvar_destroy   os_condvar_destruct

Definition at line 1653 of file os-c-api.h.

Typedef Documentation

◆ os_condvar_attr_t

Initialise this structure with os_condvar_attr_init() and then set any of the individual members directly.

See also
os::rtos::condition_variable::attributes

◆ os_condvar_t

typedef struct os_condvar_s os_condvar_t

This C structure has the same size as the C++ os::rtos::condition_variable object and must be initialised with os_condvar_create().

Later on a pointer to it can be used both in C and C++ to refer to the timer object instance.

The members of this structure are hidden and should not be used directly, but only through specific functions.

See also
os::rtos::condition_variable

Function Documentation

◆ os_condvar_attr_init()

void os_condvar_attr_init ( os_condvar_attr_t attr)
Parameters
[in]attrPointer to condition variable attributes object instance.
Returns
Nothing.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::condition_variable::attributes

Definition at line 1962 of file os-c-wrapper.cpp.

1963{
1964 assert (attr != nullptr);
1965 new (attr) condition_variable::attributes ();
1966}
Condition variable attributes.
Definition os-condvar.h:55

◆ os_condvar_broadcast()

os_result_t os_condvar_broadcast ( os_condvar_t condvar)
Parameters
[in]condvarPointer to condition variable object instance.
Return values
os_okAll waiting threads signalled.
EPERMCannot be invoked from an Interrupt Service Routines.
Errors
The function shall not fail with an error code of EINTR.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::condition_variable::broadcast()

Definition at line 2082 of file os-c-wrapper.cpp.

2083{
2084 assert (condvar != nullptr);
2085 return (os_result_t)(reinterpret_cast<condition_variable&> (*condvar))
2086 .broadcast ();
2087}
POSIX compliant condition variable.
Definition os-condvar.h:45
uint32_t os_result_t
Type of values returned by RTOS functions.
Definition os-c-decls.h:94

◆ os_condvar_construct()

void os_condvar_construct ( os_condvar_t condvar,
const char *  name,
const os_condvar_attr_t attr 
)
Parameters
[in]condvarPointer to condition variable object instance storage.
[in]namePointer to name (may be NULL).
[in]attrPointer to attributes (may be NULL).
Errors
The constructor shall fail if:
  • EAGAIN - The system lacked the necessary resources (other than memory) to create the condition variable.
  • ENOMEM - Insufficient memory exists to initialise the condition variable.
The constructor shall not fail with an error code of EINTR.
Returns
Nothing.
Note
Must be paired with os_condvar_destruct().
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::condition_variable

Definition at line 1977 of file os-c-wrapper.cpp.

1979{
1980 assert (condvar != nullptr);
1981 if (attr == nullptr)
1982 {
1984 }
1985 new (condvar)
1987}
static const attributes initializer
Default condition variable initialiser.
Definition os-condvar.h:107
Condition variable attributes.

References os::rtos::condition_variable::initializer.

◆ os_condvar_delete()

void os_condvar_delete ( os_condvar_t condvar)
Parameters
[in]condvarPointer to dynamically allocated condition variable object instance.
Returns
Nothing.

Destruct the condition variable and deallocate the dynamically allocated space using the RTOS system allocator.

Note
Equivalent of C++ delete ptr_condvar.
Must be paired with os_condvar_new().
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::condition_variable

Definition at line 2042 of file os-c-wrapper.cpp.

2043{
2044 assert (condvar != nullptr);
2045 delete reinterpret_cast<condition_variable*> (condvar);
2046}

◆ os_condvar_destruct()

void os_condvar_destruct ( os_condvar_t condvar)
Parameters
[in]condvarPointer to condition variable object instance.
Returns
Nothing.
Note
Must be paired with os_condvar_construct().
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::condition_variable

Definition at line 1998 of file os-c-wrapper.cpp.

1999{
2000 assert (condvar != nullptr);
2001 (reinterpret_cast<condition_variable&> (*condvar)).~condition_variable ();
2002}

◆ os_condvar_get_name()

const char * os_condvar_get_name ( os_condvar_t condvar)
Parameters
[in]condvarPointer to condition variable object instance.
Returns
Null terminated string.
Note
Can be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::condition_variable::name()

Definition at line 2055 of file os-c-wrapper.cpp.

2056{
2057 assert (condvar != nullptr);
2058 return (reinterpret_cast<condition_variable&> (*condvar)).name ();
2059}

◆ os_condvar_new()

os_condvar_t * os_condvar_new ( const char *  name,
const os_condvar_attr_t attr 
)
Parameters
[in]namePointer to name (may be NULL).
[in]attrPointer to attributes (may be NULL).
Errors
The constructor shall fail if:
  • EAGAIN - The system lacked the necessary resources (other than memory) to create the condition variable.
  • ENOMEM - Insufficient memory exists to initialise the condition variable.
The constructor shall not fail with an error code of EINTR.
Returns
Pointer to new condition variable object instance.

Dynamically allocate the condition variable object instance using the RTOS system allocator and construct it.

Note
Equivalent of C++ new condition_variable(...).
Must be paired with os_condvar_delete().
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::condition_variable

Definition at line 2018 of file os-c-wrapper.cpp.

2019{
2020 if (attr == nullptr)
2021 {
2023 }
2024 return reinterpret_cast<os_condvar_t*> (new condition_variable (
2025 name, (const condition_variable::attributes&)*attr));
2026}

References os::rtos::condition_variable::initializer.

◆ os_condvar_signal()

os_result_t os_condvar_signal ( os_condvar_t condvar)
Parameters
[in]condvarPointer to condition variable object instance.
Return values
os_okThe thread was signalled.
EPERMCannot be invoked from an Interrupt Service Routines.
Errors
The function shall not fail with an error code of EINTR.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::condition_variable::signal()

Definition at line 2068 of file os-c-wrapper.cpp.

2069{
2070 assert (condvar != nullptr);
2071 return (os_result_t)(reinterpret_cast<condition_variable&> (*condvar))
2072 .signal ();
2073}

◆ os_condvar_timed_wait()

os_result_t os_condvar_timed_wait ( os_condvar_t condvar,
os_mutex_t mutex,
os_clock_duration_t  timeout 
)
Parameters
[in]condvarPointer to condition variable object instance.
[in]mutexPointer to the associated mutex.
[in]timeoutTimeout to wait.
Return values
os_okThe condition change was signalled.
EPERMCannot be invoked from an Interrupt Service Routines, or the mutex type is mutex::type::errorcheck or the mutex is a robust mutex, and the current thread does not own the mutex.
ENOTRECOVERABLEThe state protected by the mutex is not recoverable.
EOWNERDEADThe mutex is a robust mutex and the process containing the previous owning thread terminated while holding the mutex lock. The mutex lock shall be acquired by the calling thread and it is up to the new owner to make the state consistent.
ETIMEDOUTThe timeout has passed.
Errors
The function shall not fail with an error code of EINTR.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::condition_variable::timed_wait()

Definition at line 2110 of file os-c-wrapper.cpp.

2112{
2113 assert (condvar != nullptr);
2114 return (os_result_t)(reinterpret_cast<condition_variable&> (*condvar))
2115 .timed_wait (reinterpret_cast<rtos::mutex&> (*mutex), timeout);
2116}
POSIX compliant mutex.
Definition os-mutex.h:52

◆ os_condvar_wait()

os_result_t os_condvar_wait ( os_condvar_t condvar,
os_mutex_t mutex 
)
Parameters
[in]condvarPointer to condition variable object instance.
[in]mutexPointer to the associated mutex.
Return values
os_okThe condition change was signalled.
EPERMCannot be invoked from an Interrupt Service Routines, or the mutex type is mutex::type::errorcheck or the mutex is a robust mutex, and the current thread does not own the mutex.
ENOTRECOVERABLEThe state protected by the mutex is not recoverable.
EOWNERDEADThe mutex is a robust mutex and the process containing the previous owning thread terminated while holding the mutex lock. The mutex lock shall be acquired by the calling thread and it is up to the new owner to make the state consistent.
Errors
The function shall not fail with an error code of EINTR.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::condition_variable::wait()

Definition at line 2096 of file os-c-wrapper.cpp.

2097{
2098 assert (condvar != nullptr);
2099 return (os_result_t)(reinterpret_cast<condition_variable&> (*condvar))
2100 .wait (reinterpret_cast<rtos::mutex&> (*mutex));
2101}
pid_t wait(int *stat_loc)

References wait().