EE445M RTOS
Taken at the University of Texas Spring 2015
Main Page
Modules
Classes
Files
File List
File Members
semaphorepp.cpp
Go to the documentation of this file.
1
#include "
semaphorepp.hpp
"
2
3
#include "libos/os.h"
4
5
#include "
criticalpp.hpp
"
6
7
semaphore::semaphore
() {
8
9
init
();
10
reset
();
11
}
12
13
semaphore::semaphore
(int16_t initial_value) {
14
15
int32_t status =
StartCritical
();
16
value
= initial_value;
17
EndCritical
(status);
18
init
();
19
}
20
21
void
semaphore::init
() {
22
23
#if TEST_SEMAPHORE == 1
24
total_posts
= 0;
25
#endif
26
}
27
28
void
semaphore::reset
() {
29
30
int32_t status =
StartCritical
();
31
value
= 0;
32
EndCritical
(status);
33
}
34
35
void
semaphore::wait
() {
36
37
while
(
blocked
()) {
38
os_surrender_context();
39
}
40
int32_t status =
StartCritical
();
41
--
value
;
42
EndCritical
(status);
43
}
44
45
void
semaphore::post
() {
46
47
int32_t status =
StartCritical
();
48
++
value
;
49
#if TEST_SEMAPHORE == 1
50
++
total_posts
;
51
#endif
52
EndCritical
(status);
53
}
54
57
bool
semaphore::guard
() {
58
59
uint32_t status =
StartCritical
();
60
bool
ret =
value
> 0;
61
if
(ret) {
62
--
value
;
63
}
64
EndCritical
(status);
65
return
ret;
66
}
67
68
bool
semaphore::blocked
() {
69
70
return
value
<= 0;
71
}
72
73
/* Local Variables: */
74
/* firestarter: (compile "make -k -j32 -C ~/workspace/ee445m-labs/build/") */
75
/* End: */
critical::EndCritical
void EndCritical(uint32_t primask)
Definition:
criticalpp.hpp:14
semaphore::guard
bool guard(void)
Definition:
semaphorepp.cpp:57
semaphore::post
void post(void)
Definition:
semaphorepp.cpp:45
critical::StartCritical
uint32_t StartCritical(void)
Definition:
criticalpp.hpp:9
semaphore::wait
void wait(void)
Definition:
semaphorepp.cpp:35
semaphore::semaphore
semaphore()
Definition:
semaphorepp.cpp:7
semaphore::blocked
bool blocked(void)
Definition:
semaphorepp.cpp:68
semaphore::reset
void reset(void)
Definition:
semaphorepp.cpp:28
semaphore::total_posts
uint32_t total_posts
Definition:
semaphorepp.hpp:21
semaphorepp.hpp
semaphore::init
void init(void)
Definition:
semaphorepp.cpp:21
semaphore::value
int16_t value
Definition:
semaphorepp.hpp:19
criticalpp.hpp
board-progs
autonomous-racer
common
semaphorepp.cpp
Generated on Fri May 8 2015 15:22:13 for EE445M RTOS by
1.8.9.1