mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-25 14:53:34 +08:00
orb: move SmartLock into global space and use it also for NuttX
This commit is contained in:
@@ -188,6 +188,8 @@ protected:
|
||||
* Each driver instance has its own lock/semaphore.
|
||||
*
|
||||
* Note that we must loop as the wait may be interrupted by a signal.
|
||||
*
|
||||
* Careful: lock() calls cannot be nested!
|
||||
*/
|
||||
void lock()
|
||||
{
|
||||
@@ -202,10 +204,11 @@ protected:
|
||||
sem_post(&_lock);
|
||||
}
|
||||
|
||||
sem_t _lock; /**< lock to protect access to all class members (also for derived classes) */
|
||||
|
||||
private:
|
||||
int _irq;
|
||||
bool _irq_attached;
|
||||
sem_t _lock;
|
||||
|
||||
/** disable copy construction for this and all subclasses */
|
||||
Device(const Device &);
|
||||
|
||||
@@ -196,29 +196,9 @@ protected:
|
||||
px4_sem_post(&_lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* @class Smart locking object that uses the same lock as lock(), but automatically
|
||||
* takes the lock when created and releases the lock when the object goes out of
|
||||
* scope. Use like this:
|
||||
* {
|
||||
* SmartLock smart_lock(*this);
|
||||
* //critical section start
|
||||
* ...
|
||||
* //critical section end
|
||||
* }
|
||||
*/
|
||||
class SmartLock
|
||||
{
|
||||
public:
|
||||
SmartLock(Device &device) : _device(device) { _device.lock(); }
|
||||
~SmartLock() { _device.unlock(); }
|
||||
private:
|
||||
Device &_device;
|
||||
};
|
||||
|
||||
private:
|
||||
px4_sem_t _lock; /**< lock to protect access to all class members (also for derived classes) */
|
||||
|
||||
private:
|
||||
/** disable copy construction for this and all subclasses */
|
||||
Device(const Device &);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user