Cleanup and improvements (#194)
- Lots of changes for migrating C code to C++ - Improved `Lockable` in several ways like adding `withLock()` (+ tests) - Improved `Semaphore` a bit for improved readability, and also added some tests - Upgrade Linux machine in GitHub Actions so that we can compile with a newer GCC - Simplification of WiFi connection - Updated funding options - (and more)
This commit is contained in:
committed by
GitHub
parent
1bb1260ea0
commit
6c67845645
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Thread.h"
|
||||
#include "Lockable.h"
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
@@ -18,7 +18,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 {
|
||||
class Semaphore final : public Lockable {
|
||||
|
||||
private:
|
||||
|
||||
@@ -32,24 +32,39 @@ private:
|
||||
std::unique_ptr<std::remove_pointer_t<QueueHandle_t>, SemaphoreHandleDeleter> handle;
|
||||
|
||||
public:
|
||||
|
||||
using Lockable::lock;
|
||||
|
||||
/**
|
||||
* Cannot be called from IRQ/ISR mode.
|
||||
* @param[in] maxCount The maximum count
|
||||
* @param[in] initialCount The initial count
|
||||
* @param[in] maxAvailable The maximum count
|
||||
* @param[in] initialAvailable The initial count
|
||||
*/
|
||||
Semaphore(uint32_t maxCount, uint32_t initialCount);
|
||||
Semaphore(uint32_t maxAvailable, uint32_t initialAvailable);
|
||||
|
||||
/**
|
||||
* Cannot be called from IRQ/ISR mode.
|
||||
* @param[in] maxAvailable The maximum count
|
||||
*/
|
||||
explicit Semaphore(uint32_t maxAvailable) : Semaphore(maxAvailable, maxAvailable) {};
|
||||
|
||||
/** Cannot be called from IRQ/ISR mode. */
|
||||
~Semaphore();
|
||||
~Semaphore() override;
|
||||
|
||||
Semaphore(Semaphore& other) : handle(std::move(other.handle)) {}
|
||||
|
||||
/** Acquire semaphore */
|
||||
bool acquire(uint32_t timeout) const;
|
||||
bool acquire(TickType_t timeout) const;
|
||||
|
||||
/** Release semaphore */
|
||||
bool release() const;
|
||||
|
||||
/** @return semaphore count */
|
||||
uint32_t getCount() const;
|
||||
bool lock(TickType_t timeout) const override { return acquire(timeout); }
|
||||
|
||||
bool unlock() const override { return release(); }
|
||||
|
||||
/** @return return the amount of times this semaphore can be acquired/locked */
|
||||
uint32_t getAvailable() const;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user