Lockable renamed to Lock (#219)
Also changed usage from unique_ptr to class value.
This commit is contained in:
committed by
GitHub
parent
2e86d4774b
commit
55bfb9fe3b
+11
-12
@@ -8,14 +8,14 @@
|
||||
|
||||
namespace tt {
|
||||
|
||||
class ScopedLockableUsage;
|
||||
class ScopedLock;
|
||||
|
||||
/** Represents a lock/mutex */
|
||||
class Lockable {
|
||||
class Lock {
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Lockable() = default;
|
||||
virtual ~Lock() = default;
|
||||
|
||||
virtual bool lock(TickType_t timeout) const = 0;
|
||||
|
||||
@@ -44,30 +44,29 @@ public:
|
||||
void withLock(const std::function<void()>& onLockAcquired, const std::function<void()>& onLockFailed) const { withLock(portMAX_DELAY, onLockAcquired, onLockFailed); }
|
||||
|
||||
[[deprecated("use asScopedLock()")]]
|
||||
std::unique_ptr<ScopedLockableUsage> scoped() const;
|
||||
std::unique_ptr<ScopedLock> scoped() const;
|
||||
|
||||
ScopedLockableUsage asScopedLock() const;
|
||||
ScopedLock asScopedLock() const;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Represents a lockable instance that is scoped to a specific lifecycle.
|
||||
* Once the ScopedLockableUsage is destroyed, unlock() is called automatically.
|
||||
* Once the ScopedLock is destroyed, unlock() is called automatically.
|
||||
*
|
||||
* In other words:
|
||||
* You have to lock() this object manually, but unlock() happens automatically on destruction.
|
||||
*/
|
||||
class ScopedLockableUsage final : public Lockable {
|
||||
class ScopedLock final : public Lock {
|
||||
|
||||
const Lockable& lockable;
|
||||
const Lock& lockable;
|
||||
|
||||
public:
|
||||
|
||||
using Lockable::lock;
|
||||
using Lock::lock;
|
||||
|
||||
explicit ScopedLockableUsage(const Lockable& lockable) : lockable(lockable) {}
|
||||
explicit ScopedLock(const Lock& lockable) : lockable(lockable) {}
|
||||
|
||||
~ScopedLockableUsage() final {
|
||||
~ScopedLock() final {
|
||||
lockable.unlock(); // We don't care whether it succeeded or not
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "Thread.h"
|
||||
#include "RtosCompatSemaphore.h"
|
||||
#include "Check.h"
|
||||
#include "Lockable.h"
|
||||
#include "Lock.h"
|
||||
#include "RtosCompatSemaphore.h"
|
||||
#include "Thread.h"
|
||||
#include "kernel/Kernel.h"
|
||||
#include <memory>
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace tt {
|
||||
* Wrapper for FreeRTOS xSemaphoreCreateMutex and xSemaphoreCreateRecursiveMutex
|
||||
* Cannot be used in IRQ mode (within ISR context)
|
||||
*/
|
||||
class Mutex final : public Lockable {
|
||||
class Mutex final : public Lock {
|
||||
|
||||
public:
|
||||
|
||||
@@ -40,7 +40,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
using Lockable::lock;
|
||||
using Lock::lock;
|
||||
|
||||
explicit Mutex(Type type = Type::Normal);
|
||||
~Mutex() final = default;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Lock.h"
|
||||
#include "kernel/Kernel.h"
|
||||
#include "Lockable.h"
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace tt {
|
||||
* Wrapper for xSemaphoreCreateBinary (max count == 1) and xSemaphoreCreateCounting (max count > 1)
|
||||
* Can be used from IRQ/ISR mode, but cannot be created/destroyed from such a context.
|
||||
*/
|
||||
class Semaphore final : public Lockable {
|
||||
class Semaphore final : public Lock {
|
||||
|
||||
private:
|
||||
|
||||
@@ -34,7 +34,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
using Lockable::lock;
|
||||
using Lock::lock;
|
||||
|
||||
/**
|
||||
* Cannot be called from IRQ/ISR mode.
|
||||
|
||||
Reference in New Issue
Block a user