Update to ESP-IDF v5.4 and fix warnings (#193)
- Update to ESP-IDF v5.4 - Fixed a lot of new and existing warnings - Fix issue with incorrect `EventFlag` usage in Dispatcher
This commit is contained in:
committed by
GitHub
parent
fa54eaa58a
commit
1bb1260ea0
@@ -6,7 +6,7 @@ namespace tt {
|
||||
|
||||
#define TAG "dispatcher"
|
||||
#define BACKPRESSURE_WARNING_COUNT ((EventBits_t)100)
|
||||
#define WAIT_FLAG ((EventBits_t)1)
|
||||
#define WAIT_FLAG ((EventBits_t)1U)
|
||||
|
||||
Dispatcher::~Dispatcher() {
|
||||
// Wait for Mutex usage
|
||||
@@ -31,38 +31,33 @@ void Dispatcher::dispatch(Function function, std::shared_ptr<void> context) {
|
||||
}
|
||||
|
||||
uint32_t Dispatcher::consume(TickType_t timeout) {
|
||||
// Wait for signal and clear
|
||||
TickType_t start_ticks = kernel::getTicks();
|
||||
if (eventFlag.wait(WAIT_FLAG, EventFlag::WaitAny, timeout)) {
|
||||
eventFlag.clear(WAIT_FLAG);
|
||||
} else {
|
||||
// Wait for signal
|
||||
uint32_t result = eventFlag.wait(WAIT_FLAG, EventFlag::WaitAny, timeout);
|
||||
if (result & EventFlag::Error) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
TickType_t ticks_remaining = TT_MAX(timeout - (kernel::getTicks() - start_ticks), 0);
|
||||
|
||||
TT_LOG_I(TAG, "Dispatcher continuing (%d ticks)", (int)ticks_remaining);
|
||||
eventFlag.clear(WAIT_FLAG);
|
||||
|
||||
// Mutate
|
||||
bool processing = true;
|
||||
uint32_t consumed = 0;
|
||||
do {
|
||||
if (mutex.lock(ticks_remaining / portTICK_PERIOD_MS)) {
|
||||
if (mutex.lock(10)) {
|
||||
if (!queue.empty()) {
|
||||
auto item = queue.front();
|
||||
queue.pop();
|
||||
consumed++;
|
||||
processing = !queue.empty();
|
||||
// Don't keep lock as callback might be slow
|
||||
tt_check(mutex.unlock());
|
||||
mutex.unlock();
|
||||
item->function(item->context);
|
||||
} else {
|
||||
processing = false;
|
||||
tt_check(mutex.unlock());
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
} else {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
}
|
||||
|
||||
} while (processing);
|
||||
|
||||
@@ -54,7 +54,8 @@ public:
|
||||
void dispatch(Function function, std::shared_ptr<void> context);
|
||||
|
||||
/**
|
||||
* Consume a dispatched function (if any)
|
||||
* Consume 1 or more dispatched function (if any) until the queue is empty.
|
||||
* @warning The timeout is only the wait time before consuming the message! It is not a limit to the total execution time when calling this method.
|
||||
* @param[in] timeout the ticks to wait for a message
|
||||
* @return the amount of messages that were consumed
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user