diff --git a/libraries/AP_HAL_Empty/Semaphores.cpp b/libraries/AP_HAL_Empty/Semaphores.cpp index 9e7f38a474..c4f45e2559 100644 --- a/libraries/AP_HAL_Empty/Semaphores.cpp +++ b/libraries/AP_HAL_Empty/Semaphores.cpp @@ -3,38 +3,25 @@ using namespace Empty; -EmptySemaphore::EmptySemaphore() : - _owner(NULL), - _k(NULL) -{} - - -bool EmptySemaphore::get(void* owner) { - if (_owner == NULL) { - _owner = owner; +bool EmptySemaphore::give() { + if (_taken) { + _taken = false; return true; } else { return false; } } -bool EmptySemaphore::release(void* owner) { - if (_owner == NULL || _owner != owner) { - return false; - } else { - _owner = NULL; - if (_k){ - _k(); - _k = NULL; - } +bool EmptySemaphore::take(uint32_t timeout_ms) { + return take_nonblocking(); +} + +bool EmptySemaphore::take_nonblocking() { + /* No syncronisation primitives to garuntee this is correct */ + if (!_taken) { + _taken = true; return true; + } else { + return false; } } - -bool EmptySemaphore::call_on_release(void* caller, AP_HAL::Proc k) { - /* idk what semantics randy was looking for here, honestly. - * seems like a bad idea. */ - _k = k; - return true; -} - diff --git a/libraries/AP_HAL_Empty/Semaphores.h b/libraries/AP_HAL_Empty/Semaphores.h index c60cdc0b0c..9cd17004fe 100644 --- a/libraries/AP_HAL_Empty/Semaphores.h +++ b/libraries/AP_HAL_Empty/Semaphores.h @@ -6,17 +6,12 @@ class Empty::EmptySemaphore : public AP_HAL::Semaphore { public: - EmptySemaphore(); - // get - to claim ownership of the semaphore - bool get(void* owner); - // release - to give up ownership of the semaphore - bool release(void* owner); - // call_on_release - returns true if caller successfully added to the - // queue to be called back - bool call_on_release(void* caller, AP_HAL::Proc k); + EmptySemaphore() : _taken(false) {} + bool give(); + bool take(uint32_t timeout_ms); + bool take_nonblocking(); private: - void* _owner; - AP_HAL::Proc _k; + bool _taken; }; #endif // __AP_HAL_EMPTY_SEMAPHORE_H__