Rework lock_core / timers (#378)
- Add recursive_mutex - Make all locking primitives and sleep use common overridable wait/notify support to allow RTOS implementations to replace WFE/SEV with something more appropriate - Add busy_wait_ms
This commit is contained in:
@ -34,13 +34,15 @@ static stdio_driver_t *filter;
|
||||
auto_init_mutex(print_mutex);
|
||||
|
||||
bool stdout_serialize_begin(void) {
|
||||
uint core_num = get_core_num();
|
||||
lock_owner_id_t caller = lock_get_caller_owner_id();
|
||||
// not using lock_owner_id_t to avoid backwards incompatibility change to mutex_try_enter API
|
||||
static_assert(sizeof(lock_owner_id_t) <= 4, "");
|
||||
uint32_t owner;
|
||||
if (!mutex_try_enter(&print_mutex, &owner)) {
|
||||
if (owner == core_num) {
|
||||
if (owner == (uint32_t)caller) {
|
||||
return false;
|
||||
}
|
||||
// other core owns the mutex, so lets wait
|
||||
// we are not a nested call, so lets wait
|
||||
mutex_enter_blocking(&print_mutex);
|
||||
}
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user