2012-12-17 15:07:26 -04:00
|
|
|
|
2013-01-02 03:22:07 -04:00
|
|
|
#include "Semaphores.h"
|
2012-12-17 15:07:26 -04:00
|
|
|
|
|
|
|
using namespace Empty;
|
|
|
|
|
2015-12-07 14:53:55 -04:00
|
|
|
bool Semaphore::give() {
|
2013-01-02 20:44:23 -04:00
|
|
|
if (_taken) {
|
|
|
|
_taken = false;
|
2012-12-17 15:07:26 -04:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 14:53:55 -04:00
|
|
|
bool Semaphore::take(uint32_t timeout_ms) {
|
2013-01-02 20:44:23 -04:00
|
|
|
return take_nonblocking();
|
2012-12-17 15:07:26 -04:00
|
|
|
}
|
|
|
|
|
2015-12-07 14:53:55 -04:00
|
|
|
bool Semaphore::take_nonblocking() {
|
2013-01-02 20:44:23 -04:00
|
|
|
/* No syncronisation primitives to garuntee this is correct */
|
|
|
|
if (!_taken) {
|
|
|
|
_taken = true;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-17 15:07:26 -04:00
|
|
|
}
|