SensESP 3.0.0-beta.6
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::SemaphoreValue< T > Class Template Reference

A value container wrapped in a semaphore. More...

#include <sensesp/system/semaphore_value.h>

Inheritance diagram for sensesp::SemaphoreValue< T >:
[legend]

Public Member Functions

 SemaphoreValue ()
 
bool wait (T &destination, unsigned int max_duration_ms)
 Wait for the value to be updated.
 
bool take (unsigned int max_duration_ms)
 Take the semaphore, ignoring the value.
 
void set (const T &new_value) override
 
void clear ()
 
- Public Member Functions inherited from sensesp::ValueConsumer< T >
virtual void set_input (const T &new_value)
 
void connect_from (ValueProducer< T > *producer)
 

Protected Attributes

value_
 
SemaphoreHandle_t semaphore_
 

Additional Inherited Members

- Public Types inherited from sensesp::ValueConsumer< T >
using input_type = T
 

Detailed Description

template<typename T>
class sensesp::SemaphoreValue< T >

A value container wrapped in a semaphore.

SemaphoreValue is primarily useful for synchronizing access to a value. It is a regular ValueConsumer that can receive values from a ValueProducer. The value is wrapped in a semaphore which can be waited on. This allows a thread to wait until the value is updated, making SemaphoreValue useful for synchronizing threads.

SemaphoreValue is similar to TaskQueueProducer, but it is not a queue and does not poll or emit the values.

Definition at line 24 of file semaphore_value.h.

Constructor & Destructor Documentation

◆ SemaphoreValue()

template<typename T >
sensesp::SemaphoreValue< T >::SemaphoreValue ( )
inline

Definition at line 26 of file semaphore_value.h.

Member Function Documentation

◆ clear()

template<typename T >
void sensesp::SemaphoreValue< T >::clear ( )
inline

Definition at line 59 of file semaphore_value.h.

◆ set()

template<typename T >
void sensesp::SemaphoreValue< T >::set ( const T & new_value)
inlineoverridevirtual

Used to set an input of this consumer. It is called automatically by a ValueProducer but can also be called manually.

Parameters
new_valuethe value of the input

Reimplemented from sensesp::ValueConsumer< T >.

Definition at line 54 of file semaphore_value.h.

◆ take()

template<typename T >
bool sensesp::SemaphoreValue< T >::take ( unsigned int max_duration_ms)
inline

Take the semaphore, ignoring the value.

Definition at line 49 of file semaphore_value.h.

◆ wait()

template<typename T >
bool sensesp::SemaphoreValue< T >::wait ( T & destination,
unsigned int max_duration_ms )
inline

Wait for the value to be updated.

This method blocks until the value is updated.

Definition at line 36 of file semaphore_value.h.

Member Data Documentation

◆ semaphore_

template<typename T >
SemaphoreHandle_t sensesp::SemaphoreValue< T >::semaphore_
protected

Definition at line 63 of file semaphore_value.h.

◆ value_

template<typename T >
T sensesp::SemaphoreValue< T >::value_
protected

Definition at line 62 of file semaphore_value.h.


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