static int wait_event_time(void *p) { MidiEvent *ev = (MidiEvent *)p; int rc, ch; for(;;){ if(ev->time - (current_tick()*play_mode->rate+30)/60 < 0) break; trace_loop(); YieldToAnyThread(); rc = check_apply_control(); if(RC_IS_SKIP_FILE(rc)){ prescan = 0; for(ch = 0; ch < MAX_CHANNELS; ch++){ if(note_channel[ch] != NULL){ NADisposeNoteChannel(gNoteAllocator, note_channel[ch]); note_channel[ch] = NULL; } channel[ch].bank_lsb = 0; channel[ch].bank_msb = 0; } trace_flush(); return rc; } } return RC_NONE; }
static int ctl_read(int32* /*valp*/) { int ret; //if( gCursorIsWatch ){ gCursorIsWatch=false; InitCursor(); } if( gQuit ) DoQuit(); /* Quit Apple event occured */ if( mac_rc ){ret=mac_rc; mac_rc=0; return ret;} if( !gBusy || UserWantsControl()){ YieldToAnyThread(); } return RC_NONE; }
void flext::Sleep(double s) { if(s <= 0) return; #if FLEXT_OS == FLEXT_OS_WIN #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x400 #if 0 LARGE_INTEGER liDueTime; liDueTime.QuadPart = (LONGLONG)(-1.e7*s); // Create a waitable timer. HANDLE hTimer = CreateWaitableTimer(NULL,TRUE,NULL); if(hTimer) { if(SetWaitableTimer(hTimer,&liDueTime,0,NULL,NULL,0)) // Wait for the timer. WaitForSingleObject(hTimer,INFINITE); // != WAIT_OBJECT_0) else ::Sleep((long)(s*1000.)); CloseHandle(hTimer); } else #else LARGE_INTEGER cnt; if(perffrq && QueryPerformanceCounter(&cnt)) { LONGLONG dst = (LONGLONG)(cnt.QuadPart+perffrq*s); for(;;) { SwitchToThread(); // while waiting switch to another thread QueryPerformanceCounter(&cnt); if(cnt.QuadPart > dst) break; } } else #endif #endif // last resort.... ::Sleep((long)(s*1000.)); #elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX || FLEXT_OSAPI == FLEXT_OSAPI_MAC_MACH // POSIX usleep((long)(s*1000000.)); #elif FLEXT_OS == FLEXT_OS_MAC // that's just for OS9 & Carbon! UnsignedWide tick; Microseconds(&tick); double target = tick.hi*((double)(1L<<((sizeof tick.lo)*4))*(double)(1L<<((sizeof tick.lo)*4)))+tick.lo+s*1.e6; for(;;) { // this is just a loop running until the time has passed - stone age (but we yield at least) Microseconds(&tick); if(target <= tick.hi*((double)(1L<<((sizeof tick.lo)*4))*(double)(1L<<((sizeof tick.lo)*4)))+tick.lo) break; YieldToAnyThread(); // yielding surely reduces the timing precision (but we're civilized) } #else #error Not implemented #endif }
void MainEventLoop(void) { gMouseRgn = NewRgn(); while (!gDone) { YieldToAnyThread(); /* download thread */ MainEventLoopPass(); } if (gMouseRgn) DisposeRgn(gMouseRgn); gMouseRgn = (RgnHandle) 0; Shutdown(); }
void wxThread::Sleep(unsigned long milliseconds) { UnsignedWide start, now; Microseconds(&start); double mssleep = milliseconds * 1000 ; double msstart, msnow ; msstart = (start.hi * 4294967296.0 + start.lo) ; do { YieldToAnyThread(); Microseconds(&now); msnow = (now.hi * 4294967296.0 + now.lo) ; } while( msnow - msstart < mssleep ); }
pascal void OTInetEventHandler(void*s, OTEventCode event, OTResult result, void *cookie) { int wakeUp = true ; GSocket* sock = (GSocket*) s ; if ( event == kOTSyncIdleEvent ) { YieldToAnyThread() ; return ; } if ( s ) { wxMacAddEvent( sock->m_mac_events , _GSocket_Internal_Proc , event , s , wakeUp ) ; } return; }
/*-----------------------------------------------------------* * Inflation *-----------------------------------------------------------*/ OSErr ExtractCoreFile(short srcVRefNum, long srcDirID, short tgtVRefNum, long tgtDirID) { OSErr err = noErr; StringPtr coreFile = 0; UInt32 endTicks; short fullPathLen = 0; Handle fullPathH = 0; Ptr fullPathStr = 0; PRInt32 rv = 0; void *hZip = 0, *hFind = 0; /* if there's a core file... */ HLock(gControls->cfg->coreFile); if (*gControls->cfg->coreFile != NULL) { /* make local copy and unlock handle */ coreFile = CToPascal(*gControls->cfg->coreFile); if (!coreFile) { err = memFullErr; goto cleanup; } } else return fnfErr; HUnlock(gControls->cfg->coreFile); ERR_CHECK_RET(GetFullPath(srcVRefNum, srcDirID, coreFile, &fullPathLen, &fullPathH), err); /* --- o p e n a r c h i v e --- */ /* extract the full path string from the handle so we can NULL terminate */ HLock(fullPathH); fullPathStr = NewPtrClear(fullPathLen+1); strncat(fullPathStr, *fullPathH, fullPathLen); *(fullPathStr+fullPathLen) = '\0'; rv = ZIP_OpenArchive( fullPathStr, &hZip ); HUnlock(fullPathH); if (rv!=ZIP_OK) goto cleanup; /* initialize the search */ hFind = ZIP_FindInit( hZip, NULL ); /* null to match all files in archive */ /* --- i n f l a t e a l l f i l e s --- */ err = InflateFiles(hZip, hFind, tgtVRefNum, tgtDirID); if (err!=noErr) goto cleanup; /* XXX review later: this check may be pointless */ /* --- c l o s e a r c h i v e --- */ cleanup: //if (hFind) // rv = ZIP_FindFree( hFind ); #ifdef MIW_DEBUG if (rv!=ZIP_OK) SysBeep(10); #endif if (hZip) rv = ZIP_CloseArchive( &hZip ); #ifdef MIW_DEBUG if (rv!=ZIP_OK) SysBeep(10); #endif if (coreFile) DisposePtr((Ptr)coreFile); if (fullPathH) DisposeHandle(fullPathH); if (fullPathStr) DisposePtr(fullPathStr); /* pause till frag registry is updated */ endTicks = TickCount() + 60; while (TickCount() < endTicks) { YieldToAnyThread(); } return err; }