12 #ifndef INCLUDE_DISTORTOS_SEMAPHORE_HPP_ 13 #define INCLUDE_DISTORTOS_SEMAPHORE_HPP_ 48 constexpr
explicit Semaphore(
const Value value,
const Value maxValue = std::numeric_limits<Value>::max()) :
50 value_{value < maxValue ? value : maxValue},
162 template<
typename Rep,
typename Period>
163 int tryWaitFor(
const std::chrono::duration<Rep, Period> duration)
165 return tryWaitFor(std::chrono::duration_cast<TickClock::duration>(duration));
207 template<
typename Duration>
208 int tryWaitUntil(
const std::chrono::time_point<TickClock, Duration> timePoint)
210 return tryWaitUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint));
261 #endif // INCLUDE_DISTORTOS_SEMAPHORE_HPP_ int tryWait()
Tries to lock the semaphore.
Definition: Semaphore.cpp:48
~Semaphore()=default
Semaphore's destructor.
Semaphore is the basic synchronization primitive.
Definition: Semaphore.hpp:30
int tryWaitFor(const std::chrono::duration< Rep, Period > duration)
Tries to lock the semaphore for given duration of time.
Definition: Semaphore.hpp:163
int tryWaitFor(TickClock::duration duration)
Tries to lock the semaphore for given duration of time.
Definition: Semaphore.cpp:54
int post()
Unlocks the semaphore.
Definition: Semaphore.cpp:30
std::chrono::time_point< TickClock > time_point
basic time_point type of clock
Definition: TickClock.hpp:42
int wait()
Locks the semaphore.
Definition: Semaphore.cpp:72
internal::ThreadList blockedList_
ThreadControlBlock objects blocked on this semaphore.
Definition: Semaphore.hpp:250
Value getValue() const
Gets current value of semaphore.
Definition: Semaphore.hpp:84
int tryWaitInternal()
Internal version of tryWait().
Definition: Semaphore.cpp:89
constexpr Semaphore(const Value value, const Value maxValue=std::numeric_limits< Value >::max())
Semaphore's constructor.
Definition: Semaphore.hpp:48
Value getMaxValue() const
Definition: Semaphore.hpp:71
Value maxValue_
max value of the semaphore
Definition: Semaphore.hpp:256
int tryWaitUntil(TickClock::time_point timePoint)
Tries to lock the semaphore until given time point.
Definition: Semaphore.cpp:59
Top-level namespace of distortos project.
Definition: buttons.hpp:33
sorted intrusive list of threads (thread control blocks)
Definition: ThreadList.hpp:55
Value value_
internal value of the semaphore
Definition: Semaphore.hpp:253
std::chrono::duration< rep, period > duration
basic duration type of clock
Definition: TickClock.hpp:39
int tryWaitUntil(const std::chrono::time_point< TickClock, Duration > timePoint)
Tries to lock the semaphore until given time point.
Definition: Semaphore.hpp:208
unsigned int Value
type used for semaphore's "value"
Definition: Semaphore.hpp:35