EE445M RTOS
Taken at the University of Texas Spring 2015
Semaphore

Classes

class  semaphore
 

Functions

 semaphore::semaphore ()
 
 semaphore::semaphore (int16_t initial_value)
 
void semaphore::init (void)
 
void semaphore::post (void)
 
void semaphore::wait (void)
 
void semaphore::take (void)
 
bool semaphore::guard (void)
 
bool semaphore::blocked (void)
 
void semaphore::reset (void)
 

Variables

int16_t semaphore::value
 
uint32_t semaphore::total_posts
 

Detailed Description

Function Documentation

bool semaphore::blocked ( void  )

True if the semaphore is blocked.

Definition at line 68 of file semaphorepp.cpp.

References value.

Referenced by wait().

68  {
69 
70  return value <= 0;
71 }
int16_t value
Definition: semaphorepp.hpp:19

Here is the caller graph for this function:

bool semaphore::guard ( void  )

without the waiting – take if ready, leave if not.

Warning
this decrements the semaphore if the return value is true.

Definition at line 57 of file semaphorepp.cpp.

References critical::EndCritical(), critical::StartCritical(), and value.

Referenced by can_handler(), motor_control(), ping_handler(), shell_handler(), switch_responder(), thread_blink_blue(), thread_blink_green(), and thread_blink_red().

57  {
58 
59  uint32_t status = StartCritical();
60  bool ret = value > 0;
61  if (ret) {
62  --value;
63  }
64  EndCritical(status);
65  return ret;
66 }
void EndCritical(uint32_t primask)
Definition: criticalpp.hpp:14
uint32_t StartCritical(void)
Definition: criticalpp.hpp:9
int16_t value
Definition: semaphorepp.hpp:19

Here is the call graph for this function:

Here is the caller graph for this function:

void semaphore::init ( void  )

Definition at line 21 of file semaphorepp.cpp.

References total_posts.

Referenced by semaphore().

21  {
22 
23 #if TEST_SEMAPHORE == 1
24  total_posts = 0;
25 #endif
26 }
uint32_t total_posts
Definition: semaphorepp.hpp:21

Here is the caller graph for this function:

void semaphore::post ( void  )

Increment the semaphore.

Definition at line 45 of file semaphorepp.cpp.

References critical::EndCritical(), critical::StartCritical(), total_posts, and value.

Referenced by CAN0_Handler(), lswitch::end_debounce(), ping::handle_timer(), shell::motor_start(), shell::motor_stop(), buffer< int32_t, N >::notify(), and ping::start().

45  {
46 
47  int32_t status = StartCritical();
48  ++value;
49 #if TEST_SEMAPHORE == 1
50  ++total_posts;
51 #endif
52  EndCritical(status);
53 }
void EndCritical(uint32_t primask)
Definition: criticalpp.hpp:14
uint32_t StartCritical(void)
Definition: criticalpp.hpp:9
uint32_t total_posts
Definition: semaphorepp.hpp:21
int16_t value
Definition: semaphorepp.hpp:19

Here is the call graph for this function:

Here is the caller graph for this function:

void semaphore::reset ( void  )

Reset the semaphore.

Definition at line 28 of file semaphorepp.cpp.

References critical::EndCritical(), critical::StartCritical(), and value.

Referenced by semaphore(), and ping::stop().

28  {
29 
30  int32_t status = StartCritical();
31  value = 0;
32  EndCritical(status);
33 }
void EndCritical(uint32_t primask)
Definition: criticalpp.hpp:14
uint32_t StartCritical(void)
Definition: criticalpp.hpp:9
int16_t value
Definition: semaphorepp.hpp:19

Here is the call graph for this function:

Here is the caller graph for this function:

semaphore::semaphore ( )

Definition at line 7 of file semaphorepp.cpp.

References init(), and reset().

7  {
8 
9  init();
10  reset();
11 }
void reset(void)
Definition: semaphorepp.cpp:28
void init(void)
Definition: semaphorepp.cpp:21

Here is the call graph for this function:

semaphore::semaphore ( int16_t  initial_value)

Definition at line 13 of file semaphorepp.cpp.

References critical::EndCritical(), init(), critical::StartCritical(), and value.

13  {
14 
15  int32_t status = StartCritical();
16  value = initial_value;
17  EndCritical(status);
18  init();
19 }
void EndCritical(uint32_t primask)
Definition: criticalpp.hpp:14
uint32_t StartCritical(void)
Definition: criticalpp.hpp:9
void init(void)
Definition: semaphorepp.cpp:21
int16_t value
Definition: semaphorepp.hpp:19

Here is the call graph for this function:

void semaphore::take ( void  )

Take the semaphore

void semaphore::wait ( void  )

Wait on a semaphore.

Definition at line 35 of file semaphorepp.cpp.

References blocked(), critical::EndCritical(), critical::StartCritical(), and value.

35  {
36 
37  while(blocked()) {
38  os_surrender_context();
39  }
40  int32_t status = StartCritical();
41  --value;
42  EndCritical(status);
43 }
void EndCritical(uint32_t primask)
Definition: criticalpp.hpp:14
uint32_t StartCritical(void)
Definition: criticalpp.hpp:9
bool blocked(void)
Definition: semaphorepp.cpp:68
int16_t value
Definition: semaphorepp.hpp:19

Here is the call graph for this function:

Variable Documentation

uint32_t semaphore::total_posts
private

Definition at line 21 of file semaphorepp.hpp.

Referenced by init(), and post().

int16_t semaphore::value
private

Definition at line 19 of file semaphorepp.hpp.

Referenced by blocked(), guard(), post(), reset(), semaphore(), and wait().