embkernel
 All Classes Functions Variables Typedefs Groups Pages
RtosSemaphore.cpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
8 #include "RtosSemaphore.hpp"
9 #include "RtosPortable.hpp"
10 
16 RtosSemaphore::RtosSemaphore(int maxCount, int initialCount) :
17  RtosSyncObject(maxCount, initialCount) {
18 
19 }
20 
24 RtosSemaphore::~RtosSemaphore() {
25 
26 }
27 
34  bool result = internalGive(tick, 1);
35  if (result) {
36  internalWakeUpWaitingToTake();
37  }
38  exitCritical();
39  return result;
40 }
41 
47  if (mCurrentCount < mMaxCount) {
48  mCurrentCount++;
49  internalWakeUpWaitingToTake();
50  return true;
51  }
52  return false;
53 }
54 
61  bool result = internalTake(tick, 1);
62  if (result) {
63  internalWakeUpWaitingToGive();
64  }
65  exitCritical();
66  return result;
67 }
68 
74  if (mCurrentCount >= 0) {
75  mCurrentCount--;
76  internalWakeUpWaitingToGive();
77  return true;
78  }
79  return false;
80 }