// This may be called from an ISR, in which case we need to defer the close bool FileStore::Close() { switch (usageMode) { case FileUseMode::free: if (!inInterrupt()) { INTERNAL_ERROR; } return false; case FileUseMode::readOnly: case FileUseMode::readWrite: { const irqflags_t flags = cpu_irq_save(); if (openCount > 1) { --openCount; cpu_irq_restore(flags); return true; } else if (inInterrupt()) { closeRequested = true; cpu_irq_restore(flags); return true; } else { cpu_irq_restore(flags); return ForceClose(); } } case FileUseMode::invalidated: default: { const irqflags_t flags = cpu_irq_save(); if (openCount > 1) { --openCount; } else { usageMode = FileUseMode::free; } cpu_irq_restore(flags); return true; } } }
/* Timer interrupt handler */ static void timerInterruptHandler (void) { elapsedTickCount += elapsedTickIncrement; elapsedTickIncrement = getTicksTillNextTimerInterrupt(); if (!inInterrupt()) { inTimerInterrupt = 1; if (!setjmp(interruptContext)) longjmp(mainContext, 1); inTimerInterrupt = 0; } }
/* Idle interrupt handler */ static void idleInterruptHandler (_go32_dpmi_registers *r) { if (!inInterrupt()) { inIdleInterrupt = 1; if (!setjmp(interruptContext)) longjmp(mainContext, 1); inIdleInterrupt = 0; } r->x.cs = origIdleSeginfo.rm_segment; r->x.ip = origIdleSeginfo.rm_offset; _go32_dpmi_simulate_fcall_iret(r); }
// This may be called from an ISR, in which case we need to defer the close bool FileStore::Close() { if (inInterrupt()) { if (!inUse) { return false; } irqflags_t flags = cpu_irq_save(); if (openCount > 1) { --openCount; } else { closeRequested = true; } cpu_irq_restore(flags); return true; } if (!inUse) { platform->Message(GENERIC_MESSAGE, "Error: Attempt to close a non-open file.\n"); return false; } irqflags_t flags = cpu_irq_save(); --openCount; bool leaveOpen = (openCount != 0); cpu_irq_restore(flags); if (leaveOpen) { return true; } bool ok = true; if (writing) { ok = Flush(); } FRESULT fr = f_close(&file); inUse = false; writing = false; closeRequested = false; return ok && fr == FR_OK; }