/** * Recursive lock of the malloc */ void __malloc_lock(struct _reent *ptr) { uint32_t timerenable, interruptenable; uint32_t id, old_owner; // Disable timer and interrupt exception, store TEE and IEE flag temporarily // to restore them later on unlock timerenable = or1k_timer_disable(); interruptenable = or1k_interrupts_disable(); // Now we cannot be disturbed by an interrupt or timer exception id = (uint32_t) ptr; // Our id is the address of the reentrancy data do { do { // Read current lock owner old_owner = or1k_sync_ll(&_malloc_lock_own); // .. and spin while it is locked and we are not the owner } while (old_owner && (old_owner != id)); } while (!or1k_sync_sc(&_malloc_lock_own, id)); // Store the TEE and IEE flags for later restore _malloc_lock_restore_timer = timerenable; _malloc_lock_restore_interrupts = interruptenable; // Increment counter. The lock may be accessed recursively _malloc_lock_cnt++; return; }
void control_wait_response() { // Get current interrupts by disabling temporarily uint32_t restore = or1k_interrupts_disable(); // Enable all interrupts or1k_interrupts_enable(); // Wait until the reply arrived while (ctrl_request.done == 0) { } // Restore previous state of interrupts or1k_interrupts_restore(restore); }
uint32_t or1k_critical_begin() { uint32_t iee = or1k_interrupts_disable(); uint32_t tee = or1k_timer_disable(); return (iee << 1) | tee; }