Lockable renamed to Lock (#219)

Also changed usage from unique_ptr to class value.
This commit is contained in:
Ken Van Hoeylandt
2025-02-12 22:28:22 +01:00
committed by GitHub
parent 2e86d4774b
commit 55bfb9fe3b
40 changed files with 257 additions and 263 deletions
@@ -29,7 +29,7 @@ private:
public:
explicit SdCardDevice(MountBehaviour mountBehaviour) : mountBehaviour(mountBehaviour) {}
virtual ~SdCardDevice() override = default;
~SdCardDevice() override = default;
Type getType() const final { return Type::SdCard; };
@@ -39,7 +39,7 @@ public:
/** Return empty string when not mounted or the mount path if mounted */
virtual std::string getMountPath() const = 0;
virtual std::shared_ptr<Lockable> getLockable() const = 0;
virtual Lock& getLock() const = 0;
virtual MountBehaviour getMountBehaviour() const { return mountBehaviour; }
bool isMounted() const { return getState() == State::Mounted; }
@@ -55,10 +55,9 @@ std::shared_ptr<SdCardDevice> _Nullable find(const std::string& path);
template<typename ReturnType>
inline ReturnType withSdCardLock(const std::string& path, std::function<ReturnType()> fn) {
auto sdcard = find(path);
std::unique_ptr<ScopedLockableUsage> scoped_lockable;
if (sdcard != nullptr) {
scoped_lockable = sdcard->getLockable()->scoped();
scoped_lockable->lock(portMAX_DELAY);
auto scoped_lockable = sdcard->getLock().asScopedLock();
scoped_lockable.lock(portMAX_DELAY);
}
return fn();
@@ -26,7 +26,7 @@ public:
gpio_num_t spiPinWp,
gpio_num_t spiPinInt,
MountBehaviour mountBehaviourAtBoot,
std::shared_ptr<Lockable> lockable = std::make_shared<Mutex>(),
std::shared_ptr<Lock> lockable = std::make_shared<Mutex>(),
std::vector<gpio_num_t> csPinWorkAround = std::vector<gpio_num_t>(),
spi_host_device_t spiHost = SPI2_HOST,
int spiFrequencyKhz = SDMMC_FREQ_DEFAULT
@@ -49,7 +49,7 @@ public:
gpio_num_t spiPinWp; // Write-protect
gpio_num_t spiPinInt; // Interrupt
SdCardDevice::MountBehaviour mountBehaviourAtBoot;
std::shared_ptr<Lockable> _Nullable lockable;
std::shared_ptr<Lock> _Nullable lockable;
std::vector<gpio_num_t> csPinWorkAround;
spi_host_device_t spiHost;
bool formatOnMountFailed = false;
@@ -80,7 +80,7 @@ public:
bool unmount() final;
std::string getMountPath() const final { return mountPath; }
std::shared_ptr<Lockable> getLockable() const final { return config->lockable; }
Lock& getLock() const final { return *config->lockable; }
State getState() const override;