F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
CountingSemaphore.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/CountingSemaphore.hpp
3 // \brief common function definitions for Os::CountingSemaphore
4 // ======================================================================
5 #ifndef OS_COUNTING_SEMAPHORE_HPP_
6 #define OS_COUNTING_SEMAPHORE_HPP_
8 #include "Os/Os.hpp"
9 
10 namespace Os {
11 
13 
15  public:
16  enum Status {
23  };
24 
26  CountingSemaphoreInterface() = default;
27 
29  virtual ~CountingSemaphoreInterface() = default;
30 
33 
36 
39  virtual Status wait() = 0;
40 
44  virtual Status waitTimeout(const Fw::TimeInterval& interval) = 0;
45 
48  virtual Status tryWait() = 0;
49 
52  virtual Status post() = 0;
53 
56  virtual CountingSemaphoreHandle* getHandle() = 0;
57 
60  U32 initial_count);
61 };
62 
64  public:
65  explicit CountingSemaphore(U32 initial_count);
66 
67  ~CountingSemaphore() final;
68 
69  CountingSemaphore(const CountingSemaphoreInterface& other) = delete;
70 
71  CountingSemaphore(const CountingSemaphore& other) = delete;
72  CountingSemaphore& operator=(const CountingSemaphore& other) = delete;
73  CountingSemaphore(CountingSemaphore&& other) = delete;
75 
76  Status wait() override;
77 
78  Status waitTimeout(const Fw::TimeInterval& interval) override;
79 
80  Status tryWait() override;
81 
82  Status post() override;
83 
85 
86  private:
87  alignas(FW_HANDLE_ALIGNMENT) CountingSemaphoreHandleStorage m_handle_storage;
88  CountingSemaphoreInterface& m_delegate;
89 };
90 } // namespace Os
91 #endif // OS_COUNTING_SEMAPHORE_HPP_
~CountingSemaphore() final
Destructor.
static CountingSemaphoreInterface * getDelegate(CountingSemaphoreHandleStorage &aligned_new_memory, U32 initial_count)
provide a pointer to a CountingSemaphore delegate object
CountingSemaphoreHandle * getHandle() override
return the underlying semaphore handle (implementation specific)
CountingSemaphore(U32 initial_count)
Constructor with initial count.
CountingSemaphoreInterface()=default
default constructor
CountingSemaphore & operator=(const CountingSemaphore &other)=delete
U8 CountingSemaphoreHandleStorage[FW_COUNTING_SEMAPHORE_HANDLE_MAX_SIZE]
Definition: Os.hpp:17
virtual ~CountingSemaphoreInterface()=default
default virtual destructor
Status waitTimeout(const Fw::TimeInterval &interval) override
wait with timeout
Status tryWait() override
non-blocking attempt to decrement the semaphore
CountingSemaphoreInterface & operator=(const CountingSemaphoreInterface &other)=delete
assignment operator is forbidden
virtual Status tryWait()=0
non-blocking attempt to decrement the semaphore
CountingSemaphore does not support operation.
virtual Status waitTimeout(const Fw::TimeInterval &interval)=0
wait on the semaphore with a timeout
virtual Status post()=0
post (increment) the semaphore, potentially waking a waiting thread
Status wait() override
wait (decrement), blocking if count is zero
Status post() override
post (increment) the semaphore, potentially waking a waiting thread
virtual Status wait()=0
wait (decrement) the semaphore, blocking if count is zero
virtual CountingSemaphoreHandle * getHandle()=0
return the underlying semaphore handle (implementation specific)