long interrupted(unsigned long tickIncrement) { /*WxWin and Macintosh version*/ #if (0) WHERE("interrupted"); #endif /*0*/ if (INTERRUPT == INTNOTSET && tickIncrement > 0 && timetocheck(tickIncrement)) { myYield(); } return (INTERRUPT); } /*interrupted()*/
DWORD WINAPI WaitForMultipleObjects(DWORD count, const HANDLE *handles, Bool wait_all, DWORD timeout) { unsigned int wait_count = 1; unsigned int wait_delta = 0; switch (timeout) { case 0 : wait_delta = 1; break; // trick - one "while" case INFINITE : wait_delta = 0; break; // trick - infinite "while" default: printf("\n\n INTERNAL ERROR - WaitForMultipleObjects(...) timeout(%u) != 0 or INFINITE\n\n",(unsigned)timeout); abort(); } myEnter(); if (wait_all) { while(wait_count) { bool found_all = true; for(DWORD i=0; i<count; i++) { NWindows::NSynchronization::CBaseHandle* hitem = (NWindows::NSynchronization::CBaseHandle*)handles[i]; switch (hitem->type) { case NWindows::NSynchronization::CBaseHandle::EVENT : if (hitem->u.event._state == false) { found_all = false; } break; case NWindows::NSynchronization::CBaseHandle::SEMAPHORE : if (hitem->u.sema.count == 0) { found_all = false; } break; default: printf("\n\n INTERNAL ERROR - WaitForMultipleObjects(...,true) with unknown type (%d)\n\n",hitem->type); abort(); } } if (found_all) { for(DWORD i=0; i<count; i++) { NWindows::NSynchronization::CBaseHandle* hitem = (NWindows::NSynchronization::CBaseHandle*)handles[i]; switch (hitem->type) { case NWindows::NSynchronization::CBaseHandle::EVENT : if (hitem->u.event._manual_reset == false) { hitem->u.event._state = false; } break; case NWindows::NSynchronization::CBaseHandle::SEMAPHORE : hitem->u.sema.count--; break; default: printf("\n\n INTERNAL ERROR - WaitForMultipleObjects(...,true) with unknown type (%d)\n\n",hitem->type); abort(); } } myLeave(); return WAIT_OBJECT_0; } else { wait_count -= wait_delta; if (wait_count) myYield(); } } } else { while(wait_count) { for(DWORD i=0; i<count; i++) { NWindows::NSynchronization::CBaseHandle* hitem = (NWindows::NSynchronization::CBaseHandle*)handles[i]; switch (hitem->type) { case NWindows::NSynchronization::CBaseHandle::EVENT : if (hitem->u.event._state == true) { if (hitem->u.event._manual_reset == false) { hitem->u.event._state = false; } myLeave(); return WAIT_OBJECT_0+i; } break; case NWindows::NSynchronization::CBaseHandle::SEMAPHORE : if (hitem->u.sema.count > 0) { hitem->u.sema.count--; myLeave(); return WAIT_OBJECT_0+i; } break; default: printf("\n\n INTERNAL ERROR - WaitForMultipleObjects(...,true) with unknown type (%d)\n\n",hitem->type); abort(); } } wait_count -= wait_delta; if (wait_count) myYield(); } } myLeave(); return WAIT_TIMEOUT; }