Re-implement Core2 and other improvements (#141)
- Create real drivers instead of wrapping M5Unified/M5GFX - Display HAL improvements (better default base class behaviour) - Fixed bug with LVGL statusbar service locking (would hang indefinitely waiting for mutex, causing WDT issues) - Fixes for `Critical.h` - Fixes and improvements for `Dispatcher` and `DispatcherThread`
This commit is contained in:
committed by
GitHub
parent
50bd6e8bf6
commit
9581978fc7
@@ -6,6 +6,7 @@ namespace tt {
|
||||
|
||||
#define TAG "Dispatcher"
|
||||
#define BACKPRESSURE_WARNING_COUNT 100
|
||||
#define WAIT_FLAG 1
|
||||
|
||||
Dispatcher::Dispatcher() :
|
||||
mutex(Mutex::TypeNormal)
|
||||
@@ -22,13 +23,12 @@ void Dispatcher::dispatch(Callback callback, std::shared_ptr<void> context) {
|
||||
// Mutate
|
||||
if (mutex.lock(1000 / portTICK_PERIOD_MS)) {
|
||||
queue.push(std::move(message));
|
||||
TT_LOG_I(TAG, "dispatch");
|
||||
if (queue.size() == BACKPRESSURE_WARNING_COUNT) {
|
||||
TT_LOG_W(TAG, "Backpressure: You're not consuming fast enough (100 queued)");
|
||||
}
|
||||
mutex.unlock();
|
||||
tt_check(mutex.unlock());
|
||||
// Signal
|
||||
eventFlag.set(1);
|
||||
eventFlag.set(WAIT_FLAG);
|
||||
} else {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
}
|
||||
@@ -37,15 +37,15 @@ void Dispatcher::dispatch(Callback callback, std::shared_ptr<void> context) {
|
||||
uint32_t Dispatcher::consume(uint32_t timeout_ticks) {
|
||||
// Wait for signal and clear
|
||||
TickType_t start_ticks = kernel::getTicks();
|
||||
if (eventFlag.wait(1, TtFlagWaitAny, timeout_ticks) == TtStatusErrorTimeout) {
|
||||
if (eventFlag.wait(WAIT_FLAG, TtFlagWaitAny, timeout_ticks) == WAIT_FLAG) {
|
||||
eventFlag.clear(WAIT_FLAG);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
TickType_t ticks_remaining = TT_MAX(timeout_ticks - (kernel::getTicks() - start_ticks), 0);
|
||||
|
||||
eventFlag.clear(1);
|
||||
|
||||
TT_LOG_I(TAG, "Dispatcher continuing");
|
||||
TT_LOG_I(TAG, "Dispatcher continuing (%d ticks)", (int)ticks_remaining);
|
||||
|
||||
// Mutate
|
||||
bool processing = true;
|
||||
@@ -53,16 +53,15 @@ uint32_t Dispatcher::consume(uint32_t timeout_ticks) {
|
||||
do {
|
||||
if (mutex.lock(ticks_remaining / portTICK_PERIOD_MS)) {
|
||||
if (!queue.empty()) {
|
||||
TT_LOG_I(TAG, "Dispatcher popping from queue");
|
||||
auto item = queue.front();
|
||||
queue.pop();
|
||||
consumed++;
|
||||
processing = !queue.empty();
|
||||
// Don't keep lock as callback might be slow
|
||||
|
||||
tt_check(mutex.unlock());
|
||||
item->callback(item->context);
|
||||
} else {
|
||||
processing = false;
|
||||
tt_check(mutex.unlock());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user