int ThrIdle( unsigned seconds ) { u_int cStamp ; u_int iStamp ; u_int work ; int mask ; int priority ; mask = SigBlock() ; priority = ThrRunningThread->priority ; ThrRunningThread->priority = MAX_PRIORITY ; cStamp = SigClockTimes ; iStamp = thrIdleTimes ; SigUnBlock( mask ) ; ThrSleep( seconds ) ; mask = SigBlock() ; work = SigClockTimes ; if ( cStamp > work ) cStamp = work + (~0 - cStamp) ; else cStamp = work - cStamp ; if ( iStamp > thrIdleTimes ) iStamp = thrIdleTimes + (~0 - iStamp) ; else iStamp = thrIdleTimes - iStamp ; ThrRunningThread->priority = priority ; thrYield() ; SigUnBlock( mask ) ; return( (iStamp * 100) / cStamp ) ; }
void testFileIo(const wchar_t *name) { handle_t file; unsigned i; size_t len; fileop_t op; uint64_t offset; file = FsOpen(name, FILE_READ); if (file == NULL) { wprintf(L"Failed to open %s\n", name); return; } op.event = EvtCreate(false); for (i = 0; i < 16; i++) { offset = 0; wprintf(L"\x1b[%um", (i % 8) + 30); while (true) { status_t ret; ret = FsReadAsync(file, key, offset, sizeof(key), &op); if (ret > 0) break; else if (ret == SIOPENDING) { ThrWaitHandle(op.event); ret = op.result; } len = op.bytes; if (len == 0) break; if (len < sizeof(key)) key[len] = '\0'; len = mbstowcs(str, key, _countof(key) - 1); if (len == -1) wprintf(L"invalid multibyte sequence\n"); else _cputws(str, len); offset += op.bytes; } ThrSleep(5000); } HndClose(op.event); HndClose(file); }
int ConCursorThread(void *param) { while (true) { LmuxAcquire(&lmux_consoles); if (current != NULL) { LmuxAcquire(¤t->lmux); ConDrawCursor(current, !current->cursor_visible); LmuxRelease(¤t->lmux); } LmuxRelease(&lmux_consoles); ThrSleep(250); } }