Semaphores.cpp 470 B

123456789101112131415161718192021222324252627
  1. #include "Semaphores.h"
  2. using namespace Empty;
  3. bool Semaphore::give() {
  4. if (_taken) {
  5. _taken = false;
  6. return true;
  7. } else {
  8. return false;
  9. }
  10. }
  11. bool Semaphore::take(uint32_t timeout_ms) {
  12. return take_nonblocking();
  13. }
  14. bool Semaphore::take_nonblocking() {
  15. /* No syncronisation primitives to garuntee this is correct */
  16. if (!_taken) {
  17. _taken = true;
  18. return true;
  19. } else {
  20. return false;
  21. }
  22. }