Mark3 Realtime Kernel
mutex.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 =========================================================================== */
49 #pragma once
50 
51 #include "kerneltypes.h"
52 #include "mark3cfg.h"
53 
54 #include "blocking.h"
55 
56 namespace Mark3
57 {
58 //---------------------------------------------------------------------------
63 class Mutex : public BlockingObject
64 {
65 public:
66  void* operator new(size_t sz, void* pv) { return reinterpret_cast<Mutex*>(pv); };
67  ~Mutex();
68 
76  void Init(bool bRecursive_ = true);
77 
94  void Claim();
95 
105  bool Claim(uint32_t u32WaitTimeMS_);
106 
118  void WakeMe(Thread* pclOwner_);
119 
139  void Release();
140 
141 private:
147  uint8_t WakeNext();
148 
156  bool Claim_i(uint32_t u32WaitTimeMS_);
157 
158  uint8_t m_u8Recurse;
159  bool m_bReady;
163 };
164 } // namespace Mark3
Basic data type primatives used throughout the OS.
Thread * m_pclOwner
Pointer to the thread that owns the mutex (when claimed)
Definition: mutex.h:162
PORT_PRIO_TYPE m_uMaxPri
Maximum priority of thread in queue, used for priority inheritence.
Definition: mutex.h:161
uint8_t WakeNext()
WakeNext.
Definition: mutex.cpp:73
void Release()
Release Release the mutex. When the mutex is released, another object can enter the mutex-protected r...
Definition: mutex.cpp:197
#define PORT_PRIO_TYPE
Type used for bitmap in the PriorityMap class.
Definition: portcfg.h:73
void Claim()
Claim Claim the mutex. When the mutex is claimed, no other thread can claim a region protected by the...
Definition: mutex.cpp:185
Blocking object base class declarations.
uint8_t m_u8Recurse
The recursive lock-count when a mutex is claimed multiple times by the same owner.
Definition: mutex.h:158
Definition: atomic.cpp:23
Mark3 Kernel Configuration This file is used to configure the kernel for your specific application in...
The Mutex Class. Class providing Mutual-exclusion locks, based on BlockingObject. ...
Definition: mutex.h:63
bool Claim_i(uint32_t u32WaitTimeMS_)
Claim_i Abstracts out timed/non-timed mutex claim operations.
Definition: mutex.cpp:108
The Thread Class. This object providing the fundamental thread control data structures and functions ...
Definition: thread.h:64
void Init(bool bRecursive_=true)
Init Initialize a mutex object for use - must call this function before using the object...
Definition: mutex.cpp:93
void WakeMe(Thread *pclOwner_)
WakeMe Wake a thread blocked on the mutex. This is an internal function used for implementing timed m...
Definition: mutex.cpp:65
The BlockingObject class. Class implementing thread-blocking primatives. used for implementing things...
Definition: blocking.h:65
bool m_bRecursive
Whether or not the lock is recursive.
Definition: mutex.h:160
bool m_bReady
State of the mutex - true = ready, false = claimed.
Definition: mutex.h:159