orb: move SmartLock into global space and use it also for NuttX

This commit is contained in:
Beat Küng
2016-04-29 11:15:16 +02:00
committed by Lorenz Meier
parent 4269db73a0
commit 1ce5d795be
5 changed files with 78 additions and 33 deletions
+4 -1
View File
@@ -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 &);
+1 -21
View File
@@ -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 &);