Mark3 Realtime Kernel
ksemaphore.h
Go to the documentation of this file.
1 /*===========================================================================
2  _____ _____ _____ _____
3  ___| _|__ __|_ |__ __|__ |__ __| __ |__ ______
4 | \ / | || \ || | || |/ / ||___ |
5 | \/ | || \ || \ || \ ||___ |
6 |__/\__/|__|_||__|\__\ __||__|\__\ __||__|\__\ __||______|
7  |_____| |_____| |_____| |_____|
8 
9 --[Mark3 Realtime Platform]--------------------------------------------------
10 
11 Copyright (c) 2012 - 2019 m0slevin, all rights reserved.
12 See license.txt for more information
13 =========================================================================== */
21 #pragma once
22 
23 #include "kerneltypes.h"
24 #include "mark3cfg.h"
25 
26 #include "blocking.h"
27 #include "threadlist.h"
28 
29 namespace Mark3
30 {
31 //---------------------------------------------------------------------------
36 class Semaphore : public BlockingObject
37 {
38 public:
39  void* operator new(size_t sz, void* pv) { return reinterpret_cast<Semaphore*>(pv); };
40  ~Semaphore();
41 
62  void Init(uint16_t u16InitVal_, uint16_t u16MaxVal_);
63 
77  bool Post();
78 
85  void Pend();
86 
97  uint16_t GetCount();
98 
109  bool Pend(uint32_t u32WaitTimeMS_);
110 
120  void WakeMe(Thread* pclChosenOne_);
121 
122 private:
127  uint8_t WakeNext();
128 
137  bool Pend_i(uint32_t u32WaitTimeMS_);
138 
139  uint16_t m_u16Value;
140  uint16_t m_u16MaxValue;
141 };
142 } // namespace Mark3
Basic data type primatives used throughout the OS.
uint8_t WakeNext()
Wake the next thread waiting on the semaphore. Used internally.
Definition: ksemaphore.cpp:78
the Semaphore class provides Binary & Counting semaphore objects, based on BlockingObject base class...
Definition: ksemaphore.h:36
Blocking object base class declarations.
Definition: atomic.cpp:23
uint16_t m_u16MaxValue
Maximum count that can be held by this semaphore.
Definition: ksemaphore.h:140
Mark3 Kernel Configuration This file is used to configure the kernel for your specific application in...
bool Pend_i(uint32_t u32WaitTimeMS_)
Pend_i.
Definition: ksemaphore.cpp:152
The Thread Class. This object providing the fundamental thread control data structures and functions ...
Definition: thread.h:64
void WakeMe(Thread *pclChosenOne_)
Wake a thread blocked on the semaphore. This is an internal function used for implementing timed sema...
Definition: ksemaphore.cpp:68
void Pend()
Decrement the semaphore count. If the count is zero, the calling Thread will block until the semaphor...
Definition: ksemaphore.cpp:194
uint16_t GetCount()
Return the current semaphore counter. This can be usedd by a thread to bypass blocking on a semaphore...
Definition: ksemaphore.cpp:206
bool Post()
Increment the semaphore count. If the semaphore count is zero at the time this is called...
Definition: ksemaphore.cpp:108
The BlockingObject class. Class implementing thread-blocking primatives. used for implementing things...
Definition: blocking.h:65
void Init(uint16_t u16InitVal_, uint16_t u16MaxVal_)
Initialize a semaphore before use. Must be called before attempting post/pend operations on the objec...
Definition: ksemaphore.cpp:94
uint16_t m_u16Value
Current count held by the semaphore.
Definition: ksemaphore.h:139
Thread linked-list declarations.