/****************************************************************\ * Routine to stop semaphore example. * *--------------------------------------------------------------* * * * Name: BeginStop(pfAutoMode) * * * * Purpose: Posts stop event semaphore to signal threads to * * die. Also posts event to stop Auto mode if * * necessary. Then waits for threads to complete, * * Creates thread StopSemaphore which posts stop * * event and waits for child threads. * * * * Usage: Called in file usercmd.c when the user selects * * Stop from the semaphore menu. * * * * Method: Execs thread to do waits so that message thread * * doesn't hang. * * Returns: * * * \****************************************************************/ VOID BeginStop (PULONG pfAutoMode) { ULONG rc; TID tidLocal; rc = DosPostEventSem(hevStop); if (rc) { SemError("DosPostEventSem",rc); return; } if (*pfAutoMode) { rc = DosPostEventSem(hevStopAuto); if (rc) { SemError("DosPostEventSem",rc); } } rc = DosCreateThread((PTID)&tidLocal, (PFNTHREAD)StopSemaphore, (ULONG)pfAutoMode,(ULONG)0,(ULONG) STACKSIZE); if (rc) { SemError("DosCreateThread",rc); } return; }
/****************************************************************\ * Routine to signal consumer to release resource. * *--------------------------------------------------------------* * * * Name: SignalUserEvent(pfAutoMode) * * * * Purpose: Posts user event semaphore to signal thread to * * release resource. Also posts event to stop * * Auto mode if *pfAutoMode is true. * * * * Usage: Called in file usercmd.c when the user selects * * Event from the semaphore menu. * * * * Method: Turns off Auto mode, if present by posting auto * * semaphore. User event is then posted. * * * * Returns: * * * \****************************************************************/ VOID SignalUserEvent(PULONG pfAutoMode) { ULONG rc; /* If sample is in auto mode turn auto mode off. */ if (*pfAutoMode) { rc = DosPostEventSem(hevStopAuto); if (rc) { SemError("DosPostEventSem Stop Auto",rc); } /* Wait for auto mode thread to die, so we don't end up with multiple copies of it later. */ rc = DosWaitThread(&tidAutoThread,0L); if (rc) { SemError("DosWaitThread",rc); } *pfAutoMode = FALSE; DosCloseEventSem (hevStopAuto); } /* If Auto mode haas already posted the event this is OK so we will not check error codes here. */ DosPostEventSem(aSquares[rand() % MAXRESOURCES].hev); return; }
int GetClipText(ClipData *cd) { int rc; ULONG PostCount; char *mem; rc = DosOpenMutexSem(SEM_PREFIX "CLIPSYN", &hmtxSyn); if (rc != 0) return -1; rc = DosOpenEventSem(SEM_PREFIX "CLIPGET", &hevGet); if (rc != 0) return -1; /* rc = DosOpenEventSem(SEM_PREFIX "CLIPPUT", &hevPut);*/ /* if (rc != 0) return -1;*/ rc = DosOpenEventSem(SEM_PREFIX "CLIPEND", &hevEnd); if (rc != 0) return -1; DosRequestMutexSem(hmtxSyn, SEM_INDEFINITE_WAIT); DosResetEventSem(hevEnd, &PostCount); DosPostEventSem(hevGet); DosWaitEventSem(hevEnd, SEM_INDEFINITE_WAIT); if (0 == DosGetNamedSharedMem((void **)&mem, MEM_PREFIX "CLIPDATA", PAG_READ | PAG_WRITE)) { cd->fLen = *(ULONG*)mem; cd->fChar = strdup(mem + 4); DosFreeMem(mem); } else { cd->fLen = 0; cd->fChar = 0; } DosPostEventSem(hevGet); DosReleaseMutexSem(hmtxSyn); /* DosCloseEventSem(hevPut);*/ DosCloseEventSem(hevGet); DosCloseEventSem(hevEnd); DosCloseMutexSem(hmtxSyn); return 0; }
void APIENTRY ReadLoopThread() { THREAD *pstThd = pstThread; CONFIG *pCfg = &pstThd->stCfg; THREADCTRL *pThread = &pstThd->stThread; BOOL bReadComplete; CHAR *pString; APIRET rc; BOOL bSkipRead = FALSE; char szMessage[80]; ULONG ulStringLength; ULONG ulPostCount; // DosSetPriority(PRTYS_THREAD,PRTYC_FOREGROUNDSERVER,-28L,0); DosSetPriority(PRTYS_THREAD,PRTYC_REGULAR,-10L,0); ulStringLength = pCfg->wReadStringLength; DosAllocMem((PPVOID)&pString,10010,(PAG_COMMIT | PAG_WRITE | PAG_READ)); while (!pThread->bStopThread) { if (ulStringLength != pCfg->wReadStringLength) { DosFreeMem(pString); ulStringLength = pCfg->wReadStringLength; DosAllocMem((PPVOID)&pString,(ulStringLength + 10),(PAG_COMMIT | PAG_WRITE | PAG_READ)); } if (pCfg->bHalfDuplex) { while ((rc = DosWaitEventSem(hevStartReadSem,10000)) != 0) if (rc == ERROR_SEM_TIMEOUT) { ErrorNotify(pstThd,"Read start semaphore timed out"); bSkipRead = TRUE; } else { sprintf(szMessage,"Read start semaphore error - rc = %u",rc); ErrorNotify(pstThd,szMessage); } DosResetEventSem(hevStartReadSem,&ulPostCount); } if (bSkipRead) bSkipRead = FALSE; else { if (!pCfg->bReadCharacters) bReadComplete = ReadString(pstThd,pString); else bReadComplete = ReadCharacters(pstThd,pString); if (bReadComplete) DosPostEventSem(hevStartWriteSem); } } DosFreeMem(pString); DosPostEventSem(hevKillReadThreadSem); DosExit(EXIT_THREAD,0); }
void _PR_MD_POST_SEM(_MDSemaphore *md) { int rv; rv = DosPostEventSem(md->sem); PR_ASSERT(rv == NO_ERROR); }
static void APIENTRY begin_thread_helper( thread_args *td ) /*********************************************************/ { thread_fn *rtn; void *arg; EXCEPTIONREGISTRATIONRECORD xcpt; thread_data *tdata; rtn = td->rtn; arg = td->argument; tdata = __alloca( __ThreadDataSize ); memset( tdata, 0, __ThreadDataSize ); // tdata->__allocated = 0; tdata->__data_size = __ThreadDataSize; if( !__Is_DLL ) { if( !__OS2AddThread( *_threadid, tdata ) ) return; } DosPostEventSem( td->event ); _fpreset(); __XCPTHANDLER = &xcpt; __sig_init_rtn(); (*rtn)( arg ); _endthread(); }
/*! \internal Adds an adopted thread to the list of threads that Qt watches to make sure the thread data is properly cleaned up. This function starts the watcher thread if necessary. */ static void qt_watch_adopted_thread(const TID adoptedTID, QThread *qthread) { QMutexLocker lock(&qt_adopted_thread_watcher_mutex); qt_adopted_thread_tids.append(adoptedTID); qt_adopted_qthreads.append(qthread); // Start watcher thread if it is not already running. if (qt_adopted_thread_watcher_tid == 0) { APIRET rc = DosCreateEventSem(NULL, &qt_adopted_thread_wakeup, DCE_AUTORESET, FALSE); if (rc != NO_ERROR) { qWarning("qt_watch_adopted_thread: DosCreateEventSem returned %lu", rc); return; } int tid = (TID)_beginthread(qt_adopted_thread_watcher_function, NULL, 0, NULL); if (tid == -1) qErrnoWarning(errno, "qt_watch_adopted_thread: _beginthread failed"); else qt_adopted_thread_watcher_tid = (TID) tid; } else { DosPostEventSem(qt_adopted_thread_wakeup); } }
int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){ ThreadContext *c= s->thread_opaque; int i; assert(s == c->avctx); assert(count <= s->thread_count); /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */ for(i=0; i<count; i++){ c[i].arg= (char*)arg + i*size; c[i].func= func; c[i].ret= 12345; DosPostEventSem(c[i].work_sem); // ReleaseSemaphore(c[i].work_sem, 1, 0); } for(i=0; i<count; i++){ DosWaitEventSem(c[i].done_sem,SEM_INDEFINITE_WAIT); // WaitForSingleObject(c[i].done_sem, INFINITE); c[i].func= NULL; if(ret) ret[i]= c[i].ret; } return 0; }
void DrvMountDrivesThread( void * hev) { ULONG rc; HMODULE hmod = 0; pRediscover_PRMs pfn = 0; char * pErr = 0; char szErr[16]; rc = DosLoadModule( szErr, sizeof(szErr), "LVM", &hmod); if (rc) pErr = "DosLoadModule"; else { rc = DosQueryProcAddr( hmod, 0, "Rediscover_PRMs", (PFN*)&pfn); if (rc) pErr = "DosQueryProcAddr"; else { pfn( &rc); if (rc) pErr = "Rediscover_PRMs"; } rc = DosFreeModule( hmod); if (rc && !pErr) pErr = "DosFreeModule"; } if (pErr) printf( "DrvMountDrivesThread - %s - rc= %lx\n", pErr, rc); rc = DosPostEventSem( (HEV)hev); if (rc) printf( "DrvMountDrivesThread - DosPostEventSem - rc= %lx\n", rc); return; }
SOM_Scope BOOL SOMLINK WPSamFolder_wpSaveState (WPSamF *somSelf) { BOOL bRC = TRUE; WPSamFData *somThis = WPSamFGetData (somSelf); WPSamFMethodDebug ("WPSamF","WPSamFolder_wpSaveState"); bRC &= parent_wpSaveState (somSelf); _ulChiffreKey = (ULONG) _wpQueryHandle (somSelf); bRC &= _wpSaveLong (somSelf, CLASSNAME, KEY_ZEITPUNKT2, _ulZeitpunkt2 ^ (_ulChiffreKey + 0x87654321)); bRC &= _wpSaveLong (somSelf, CLASSNAME, KEY_ZEITPUNKT1, _ulZeitpunkt1 ^ (_ulChiffreKey + _ulZeitpunkt2)); bRC &= _wpSaveLong (somSelf, CLASSNAME, KEY_FLAG, _ulFlag); if (bRC == FALSE) { DebugE (D_SOM, "_wpSaveState", "Failed!"); MessageBox (IDS_SAVESTATEFAILED, MBTITLE_ERROR, MB_ENTER | MB_ERROR); } if (_wpIsCurrentDesktop (somSelf)) { DosPostEventSem(hevPrfResetLock); DebugE (D_SOM, "_wpSaveState", "PrfReset unlocked"); } return (bRC); }
void APIENTRY LoopThread() { THREAD *pstThd = pstThread; CONFIG *pCfg = &pstThd->stCfg; THREADCTRL *pThread = &pstThd->stThread; int iError; CHAR szMessage[81]; DCB stComDCB; // DosSetPriority(PRTYS_THREAD,PRTYC_FOREGROUNDSERVER,-32L,0); DosSetPriority(PRTYS_THREAD,PRTYC_REGULAR,-14L,0); while (!pThread->bStopThread) { switch (pCfg->wSimulateType) { case TERMINAL: GetDCB(&stIOctlInst,pstThd->hCom,&stComDCB); stComDCB.Flags3 &= ~F3_RTO_MASK; stComDCB.Flags3 |= F3_WAIT_SOMETHING; stComDCB.ReadTimeout = 100; SendDCB(&stIOctlInst,pstThd->hCom,&stComDCB); TerminalRead(pstThd); break; case STRING_TRANSFER: DoStringTransfer(pstThd); break; } } DosPostEventSem(hevKillThreadSem); DosExit(EXIT_THREAD,0); }
static void _cairo_os2_surface_release_source_image (void *abstract_surface, cairo_image_surface_t *image, void *image_extra) { cairo_os2_surface_t *local_os2_surface; local_os2_surface = (cairo_os2_surface_t *) abstract_surface; if ((!local_os2_surface) || (local_os2_surface->base.backend != &cairo_os2_surface_backend)) { /* Invalid parameter (wrong surface)! */ return; } /* Decrease Lend counter! */ DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT); if (local_os2_surface->pixel_array_lend_count > 0) local_os2_surface->pixel_array_lend_count--; DosPostEventSem (local_os2_surface->hev_pixel_array_came_back); DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); return; }
unsigned pthread_alarm(unsigned sec) { int ret = 0; pthread_t self = pthread_self(); if (sec == 0) { /* cancel pending alarm */ self->alarm_timeout = 0; if (self->alarm_timer) DosStopTimer(self->alarm_timer); if (self->alarm_event) DosPostEventSem(self->alarm_event); } else if (sec > 0) { if (self->alarm_timer && self->alarm_thread) { DosStopTimer(self->alarm_timer); } else { DosCreateEventSem(NULL,&self->alarm_event,DC_SEM_SHARED,FALSE); pthread_create(&self->alarm_thread,NULL,_alarm_thread,(void *)self); } DosAsyncTimer(sec * 1000L,(HSEM)self->alarm_event,&self->alarm_timer); self->alarm_timeout = sec; } else { ret = EINVAL; errno = EINVAL; } return (ret); }
unsigned long Event::Post ( ) { if ( Handle == 0 ) return ( (unsigned long) 0xFFFFFFFF ) ; if ( DebugFlag ) Log ( "Event(%s)::Post.", Tag?Tag:"" ) ; BOOL Result = FALSE ; #ifdef __OS2__ APIRET Status = DosPostEventSem ( Handle ) ; if ( Status && ( Status != ERROR_ALREADY_POSTED ) ) Result = FALSE ; else Result = TRUE ; #else Result = SetEvent ( Handle ) ; #endif return ( Result ) ; } /* endmethod */
VOID PumpMessageQueue( VOID ) { char class_name[80]; QMSG qmsg; ERRORID err; ULONG ulCount; for( ;; ) { DosWaitEventSem( PumpMessageSem, SEM_INDEFINITE_WAIT ); DosResetEventSem( PumpMessageSem, &ulCount ); WinThreadAssocQueue( GUIGetHAB(), GUIPMmq ); while ( WinGetMsg( GUIGetHAB(), &qmsg, 0L, 0, 0 ) ) { WinQueryClassName( qmsg.hwnd, sizeof( class_name ), class_name ); if (strcmp( class_name, "GUIClass" ) == 0 || strcmp( class_name, "WTool" ) == 0) { WinDefWindowProc( qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2 ); } else { WinDispatchMsg( GUIGetHAB(), &qmsg ); } } WinThreadAssocQueue( GUIGetHAB(), NULL ); err = WinGetLastError( GUIGetHAB() ); DosPostEventSem( PumpMessageDoneSem ); } }
LONG APIENTRY DARTEventFunc(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags) { if (ulFlags && MIX_WRITE_COMPLETE) { pMixBufferDesc pBufDesc; if (pBuffer) { pBufDesc = (pMixBufferDesc) (*pBuffer).ulUserParm; if (pBufDesc) { SDL_AudioDevice *pSDLAudioDevice = pBufDesc->pSDLAudioDevice; pBufDesc->iBufferUsage = BUFFER_EMPTY; if (pSDLAudioDevice) DosPostEventSem(pSDLAudioDevice->hidden->hevAudioBufferPlayed); } } } return TRUE; }
void _System Reader(ULONG arg) { int data; ULONG read; int new_index; APIRET rc; OverRun = FALSE; for( ;; ) { rc = DosRead( ComPort, &data, 1, &read ); if( rc != NO_ERROR ) break; if( read == 1 ) { new_index = ReadBuffAdd + 1; new_index &= BSIZE-1; if( new_index == ReadBuffRemove ) { OverRun = TRUE; } else { ReadBuff[ ReadBuffAdd ] = data; ReadBuffAdd = new_index; } DosPostEventSem( ReadSemaphore ); } } }
VOID APIENTRY ControlFunc( ULONG parm ) { ULONG ulCount; parm = parm; do { DosWaitEventSem( Requestsem, SEM_INDEFINITE_WAIT ); // wait for Request DosResetEventSem( Requestsem, &ulCount ); switch( Req ) { case REQ_GO: Go( true ); break; case REQ_TRACE_OVER: ExecTrace( TRACE_OVER, DbgLevel ); break; case REQ_TRACE_INTO: ExecTrace( TRACE_INTO, DbgLevel ); break; } DoInput(); _SwitchOff( SW_TASK_RUNNING ); DosPostEventSem( Requestdonesem ); } while( Req != REQ_BYE ); return; // thread over! }
int main( int argc, char **argv ) { char buff[256]; TID tid; APIRET rc; MemInit(); getcmd( buff ); CmdData = buff; DebugMain(); _SwitchOff( SW_ERROR_STARTUP ); DoInput(); VarInitInfo( &Locals ); DosCreateEventSem( NULL, &Requestsem, 0, false ); DosCreateEventSem( NULL, &Requestdonesem, 0, false ); DosPostEventSem( Requestdonesem ); // signal req done rc = DosCreateThread( &tid, ControlFunc, 0, 0, 32768 ); if( rc != 0 ) { printf( "Stubugger: Error creating thread!\n" ); } while( !Done ) { DlgCmd(); } DosCloseEventSem( Requestsem ); DosCloseEventSem( Requestdonesem ); DebugFini(); RunRequest( REQ_BYE ); MemFini(); return( 0 ); }
void TEventQueue::keyboardThread( void * arg ) { arg = arg; KBDKEYINFO *info = &TThreads::tiled->keyboardInfo; while (1) { jsSuspendThread USHORT errCode = KbdCharIn( info, IO_NOWAIT, 0 ); jsSuspendThread if ( errCode || (info->fbStatus & 0xC0)!=0x40 || info->fbStatus & 1) { // no char keyboardEvent.what = evNothing; DosSleep(keyboardPollingDelay); if (keyboardPollingDelay < 500) keyboardPollingDelay += 5; } else { keyboardEvent.what = evKeyDown; if ((info->fbStatus & 2) && (info->chChar==0xE0)) info->chChar=0; // OS/2 cursor keys. keyboardEvent.keyDown.charScan.charCode=info->chChar; keyboardEvent.keyDown.charScan.scanCode=info->chScan; shiftState = info->fsState & 0xFF; jsSuspendThread assert(! DosPostEventSem(TThreads::hevKeyboard1) ); jsSuspendThread assert(! DosWaitEventSem(TThreads::hevKeyboard2, SEM_INDEFINITE_WAIT) ); keyboardEvent.what = evNothing; ULONG dummy; jsSuspendThread assert(! DosResetEventSem(TThreads::hevKeyboard2, &dummy) ); keyboardPollingDelay=0; } } TThreads::deadEnd(); }
//--------------------------------------------------------------------- // DARTEventFunc // // This function is called by DART, when an event occures, like end of // playback of a buffer, etc... //--------------------------------------------------------------------- LONG APIENTRY DARTEventFunc(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags) { if (ulFlags && MIX_WRITE_COMPLETE) { // Playback of buffer completed! // Get pointer to buffer description pMixBufferDesc pBufDesc; if (pBuffer) { pBufDesc = (pMixBufferDesc) (*pBuffer).ulUserParm; if (pBufDesc) { SDL_AudioDevice *pSDLAudioDevice = pBufDesc->pSDLAudioDevice; // Set the buffer to be empty pBufDesc->iBufferUsage = BUFFER_EMPTY; // And notify DART feeder thread that it will have to work a bit. if (pSDLAudioDevice) DosPostEventSem(pSDLAudioDevice->hidden->hevAudioBufferPlayed); } } } return TRUE; }
VOID APIENTRY ThdDskPerf( ULONG ulTask ) { int k; PDTV pDisk; pDisk = (PDTV)ulTask; pDisk->szDir[ 6 ] = (char)( pDisk->ulTask + 0x30 ); pDisk->szDir[ 7 ] = 0; setdisk( (int)( pDisk->szDrive[ 0 ] - 'A' ) ); mkdir( pDisk->szDir ); chdir( pDisk->szDir ); /* create test files */ DosPostEventSem( pDisk->hevReady ); /* start timing */ DosWaitEventSem( hevGo, SEM_INDEFINITE_WAIT ); /* perform string of file operations */ for( k = 0; k < ITER; k++ ) readswrites( pDisk ); /*stop timimg*/ EndItAll( 0, pDisk ); }
int USBProxyServiceOs2::interruptWait(void) { int rc = DosPostEventSem(mhev); return rc == NO_ERROR || rc == ERROR_ALREADY_POSTED ? VINF_SUCCESS : RTErrConvertFromOS2(rc); }
int main(void) { APIRET apiret; TID tid; HEV hev; int i; /* test thread1 */ printf(__FILE__ " main function invoked\n"); printf("Test named event semaphores\n"); apiret = DosCreateEventSem("\\SEM32\\TEST3SEM", &hev, DC_SEM_SHARED, FALSE); printf("DosCreateEventSem function returned %d\n", (int)apiret); /* post to thread 1 */ printf("Starting thread with DosCreateThread\n"); apiret = DosCreateThread(&tid, thread1, (ULONG)hev, 0, 8092); for (i = 0; i < 4; i++) { apiret = DosPostEventSem(hev); printf("Function DosPostEventSem returned %d\n", (int)apiret); DosSleep(1500); /* 1.5 seconds */ } apiret = DosWaitThread(&tid, DCWW_WAIT); printf("Function DosWaitThread returned %d\n", (int)apiret); /* post to thread 2 */ printf("Starting thread with DosCreateThread\n"); apiret = DosCreateThread(&tid, thread2, (ULONG)hev, 0, 8092); for (i = 0; i < 4; i++) { apiret = DosPostEventSem(hev); printf("Function DosPostEventSem returned %d\n", (int)apiret); DosSleep(1500); /* 1.5 seconds */ } apiret = DosWaitThread(&tid, DCWW_WAIT); printf("Function DosWaitThread returned %d\n", (int)apiret); printf("The last DosWaitEventSem should have returned 640\n"); apiret = DosCloseEventSem(hev); printf("Function DosCloseEventSem returned %d\n", (int)apiret); return 0; }
void EndItAll( int rc, PDTV pDisk ) { pDisk->ulCount = ( CONST * ITER ); pDisk->iExitCode = rc; DosPostEventSem( pDisk->hevDone ); DosExit( 0, rc ); }
void ThreadDecodeMain( void *pv ) { while(!((PLUGINWORK *)pv)->fTerminate) { ThreadDecodeSub( (PLUGINWORK *)pv ); } DosPostEventSem( ((PLUGINWORK *)pv)->hevThreadA ); }
void vlc_cond_broadcast (vlc_cond_t *p_condvar) { if (!p_condvar->hev) return; /* Wake all threads up (as the event HANDLE has manual reset) */ DosPostEventSem( p_condvar->hev ); }
int pthread_cond_signal(pthread_cond_t *cond) { APIRET rc; /* Bring the next thread off the condition queue: */ rc = DosPostEventSem(cond->semaphore); return 0; }
// closetcp( ) // // Close the socket, set TCPSEM1, and end thread // void closetcp( ) { soclose(tcpsocket); DosFreeMem(pShareMem); // free the buffer memory DosPostEventSem(hevTCPSEM1); // signal syslogd main thread shutdown _endthread(); } //$* end of setupudp
static void vlc_entry( void *p ) { struct vlc_thread *th = p; vlc_threadvar_set (thread_key, th); th->killable = true; th->data = th->entry (th->data); DosPostEventSem( th->done_event ); vlc_thread_cleanup (th); }