mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-11 10:23:59 -04:00
AP_HAL_Empty: implement new Semaphore interface
This commit is contained in:
parent
2d6b649aa4
commit
f178d1bd02
@ -3,38 +3,25 @@
|
|||||||
|
|
||||||
using namespace Empty;
|
using namespace Empty;
|
||||||
|
|
||||||
EmptySemaphore::EmptySemaphore() :
|
bool EmptySemaphore::give() {
|
||||||
_owner(NULL),
|
if (_taken) {
|
||||||
_k(NULL)
|
_taken = false;
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
bool EmptySemaphore::get(void* owner) {
|
|
||||||
if (_owner == NULL) {
|
|
||||||
_owner = owner;
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmptySemaphore::release(void* owner) {
|
bool EmptySemaphore::take(uint32_t timeout_ms) {
|
||||||
if (_owner == NULL || _owner != owner) {
|
return take_nonblocking();
|
||||||
return false;
|
}
|
||||||
} else {
|
|
||||||
_owner = NULL;
|
bool EmptySemaphore::take_nonblocking() {
|
||||||
if (_k){
|
/* No syncronisation primitives to garuntee this is correct */
|
||||||
_k();
|
if (!_taken) {
|
||||||
_k = NULL;
|
_taken = true;
|
||||||
}
|
|
||||||
return 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -6,17 +6,12 @@
|
|||||||
|
|
||||||
class Empty::EmptySemaphore : public AP_HAL::Semaphore {
|
class Empty::EmptySemaphore : public AP_HAL::Semaphore {
|
||||||
public:
|
public:
|
||||||
EmptySemaphore();
|
EmptySemaphore() : _taken(false) {}
|
||||||
// get - to claim ownership of the semaphore
|
bool give();
|
||||||
bool get(void* owner);
|
bool take(uint32_t timeout_ms);
|
||||||
// release - to give up ownership of the semaphore
|
bool take_nonblocking();
|
||||||
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);
|
|
||||||
private:
|
private:
|
||||||
void* _owner;
|
bool _taken;
|
||||||
AP_HAL::Proc _k;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __AP_HAL_EMPTY_SEMAPHORE_H__
|
#endif // __AP_HAL_EMPTY_SEMAPHORE_H__
|
||||||
|
Loading…
Reference in New Issue
Block a user