int tCircularBuffer::insertData(char *data, int count) { long i = 0; long pos = 0; tBufReader *P; WaitForSingleObject(hSemafor,1000); ResetEvent(hSemafor); while (count>0) { i=(bufferEnd+count<bufferSize ? count : bufferSize-bufferEnd); CopyMemory((void*)&buffer[bufferEnd], (void*)&data[pos], i); nowInBuffer=nowInBuffer+i; P=FirstReader; while (P!=NULL) { P->nowInBuffer=P->nowInBuffer+i; if (P->in_event_id!=0) PulseEvent(P->in_event_id); P=P->nextreader; } pos=pos+i; count=count-i; bufferEnd=bufferEnd+i; if (bufferEnd>=bufferSize) bufferEnd=0; } SetEvent(hSemafor); if (in_event_id!=0) PulseEvent(in_event_id); return 0; }
void IPC::process() { IPCLock(this); for (unsigned i = 0; i < N_SLOTS; i++){ if (s[i] != SLOT_IN) continue; QString in; QString out; string name = prefix(); name += number(i); HANDLE hMem = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, name.c_str()); if (hMem == NULL){ s[i] = SLOT_NONE; PulseEvent(hEventOut); continue; } unsigned short *mem = (unsigned short*)MapViewOfFile(hMem, FILE_MAP_ALL_ACCESS, 0, 0, 0); if (mem == NULL){ log(L_WARN, "Map error"); s[i] = SLOT_NONE; PulseEvent(hEventOut); continue; } unsigned short *p; for (p = mem; *p; p++) in += QChar(*p); bool bError = false; bool bRes = remote->command(in, out, bError); p = mem; unsigned size = 0; if (!bError){ if (bRes){ *(p++) = QChar('>').unicode(); }else{ *(p++) = QChar('?').unicode(); } size = out.length(); if (size > 0x3F00) size = 0x3F00; memcpy(p, out.unicode(), size * sizeof(unsigned short)); size++; } p[size] = 0; UnmapViewOfFile(mem); CloseHandle(hMem); s[i] = SLOT_OUT; PulseEvent(hEventOut); } }
DLL_EXPORT BOOL FishHang_PulseEvent ( const char* pszFilePosted, // source file that signalled it const int nLinePosted, // line number of source file HANDLE hEvent // handle to event object ) { FISH_THREAD* pFISH_THREAD; FISH_EVENT* pFISH_EVENT; FIXFILENAME(pszFilePosted); LockFishHang(); if (!GetThreadAndEventPtrs(&pFISH_THREAD,&pFISH_EVENT,hEvent)) FishHangAbort(pszFilePosted,nLinePosted); GetSystemTime(&pFISH_EVENT->timeSet); GetSystemTime(&pFISH_EVENT->timeReset); pFISH_EVENT->pWhoSet = pFISH_THREAD; pFISH_EVENT->pWhoReset = pFISH_THREAD; pFISH_EVENT->pszFileSet = pszFilePosted; pFISH_EVENT->pszFileReset = pszFilePosted; pFISH_EVENT->nLineSet = nLinePosted; pFISH_EVENT->nLineReset = nLinePosted; UnlockFishHang(); return PulseEvent(hEvent); }
static void TIME_TriggerCallBack(LPWINE_TIMERENTRY lpTimer) { TRACE("%04lx:CallBack => lpFunc=%p wTimerID=%04X dwUser=%08lX dwTriggerTime %ld(delta %ld)\n", GetCurrentThreadId(), lpTimer->lpFunc, lpTimer->wTimerID, lpTimer->dwUser, lpTimer->dwTriggerTime, GetTickCount() - lpTimer->dwTriggerTime); /* - TimeProc callback that is called here is something strange, under Windows 3.1x it is called * during interrupt time, is allowed to execute very limited number of API calls (like * PostMessage), and must reside in DLL (therefore uses stack of active application). So I * guess current implementation via SetTimer has to be improved upon. */ switch (lpTimer->wFlags & 0x30) { case TIME_CALLBACK_FUNCTION: (lpTimer->lpFunc)(lpTimer->wTimerID, 0, lpTimer->dwUser, 0, 0); break; case TIME_CALLBACK_EVENT_SET: SetEvent((HANDLE)lpTimer->lpFunc); break; case TIME_CALLBACK_EVENT_PULSE: PulseEvent((HANDLE)lpTimer->lpFunc); break; default: FIXME("Unknown callback type 0x%04x for mmtime callback (%p), ignored.\n", lpTimer->wFlags, lpTimer->lpFunc); break; } }
BOOL Alert_StartScout (ULONG *pStatus) { if (hScout == 0) // create scout? { heScoutWakeup = CreateEvent (NULL, FALSE, FALSE, TEXT("AfsSvrMgr Alert Scout Wakeup")); DWORD dwThreadID; if ((hScout = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)Alert_ScoutProc, NULL, 0, &dwThreadID)) == NULL) { if (pStatus) *pStatus = GetLastError(); return FALSE; } SetThreadPriority (hScout, THREAD_PRIORITY_BELOW_NORMAL); } else // or just wake up scout from its slumber? { PulseEvent (heScoutWakeup); } return TRUE; }
/** 唤醒一个阻塞等待条件成立的线程 */ int LCUICond_Signal( LCUI_Cond *cond ) { if( PulseEvent( *cond ) ) { return 0; } return -1; }
DWORD WINAPI compare(LPVOID arg) { while (1) { WaitForSingleObject(eventComparator, INFINITE); for (DWORD i = 0; i < nbThreads - 1; i++) { if (_tcscmp(entries[i], entries[i + 1])) { //If entries are different ExitThread(1); } } /*Check if all entries are "", which means that all the reading threads have terminated*/ DWORD i = 0; while (i < nbThreads && !_tcscmp(entries[i], _T(""))) { i++; } if (i == nbThreads) { //All the reading threads have terminated -->directories are equals ExitThread(0); } EnterCriticalSection(&criticalSection); counter = 0; LeaveCriticalSection(&criticalSection); //Release the reading threads PulseEvent(eventReaders); } }
bool irsdkMemServer::finalizeHeader() { assert(!m_isHeaderFinalized); if(m_isInitialized && !m_isHeaderFinalized) { // copy our local header memcpy(pHeader, &localHeader, sizeof(localHeader)); // copy over the var header char *pBase = pSharedMem + localHeader.varHeaderOffset; memcpy(pBase, &localVarHeader, sizeof(localVarHeader)); // flush caches to all processors _WriteBarrier(); localHeader.status = irsdk_stConnected; pHeader->status = irsdk_stConnected; //should we fire an event? PulseEvent(hDataValidEvent); // only write header out once m_isHeaderFinalized = true; return true; } return false; }
long CCintocxCtrl::Terminate() { // TODO: Add your dispatch handler code here // terminates the application #ifdef TERMEVENT // following scheme never worked if(IsCintThreadActive) { if(0==EventQue.Push("",NULL,TERMINATEEVENT)) { #ifndef WIN32EVENT CintEvent.PulseEvent(); #else PulseEvent(CintEvent); #endif return(0); } else { MessageBeep((WORD)(-1)); return(1); } } #else exit(0); #endif return(0); }
int pthread_cond_broadcast (pthread_cond_t *cv) { // Try to release all waiting threads. BOOL retcode = PulseEvent (cv->events_[cv->BROADCAST]); return retcode; }
void signal_quit (void) { /* Make sure this event never remains signaled; if the main thread isn't in a blocking call, then this should do nothing. */ PulseEvent (interrupt_handle); }
WaitObjectContainer::~WaitObjectContainer() { try // don't let exceptions escape destructor { if (!m_threads.empty()) { HANDLE threadHandles[MAXIMUM_WAIT_OBJECTS]; unsigned int i; for (i=0; i<m_threads.size(); i++) { WaitingThreadData &thread = *m_threads[i]; while (!thread.waitingToWait) // spin until thread is in the initial "waiting to wait" state Sleep(0); thread.terminate = true; threadHandles[i] = thread.threadHandle; } PulseEvent(m_startWaiting); ::WaitForMultipleObjects(m_threads.size(), threadHandles, TRUE, INFINITE); for (i=0; i<m_threads.size(); i++) CloseHandle(threadHandles[i]); CloseHandle(m_startWaiting); CloseHandle(m_stopWaiting); } } catch (...) { } }
DWORD QueueGet (QUEUE_OBJECT *q, PVOID msg, DWORD msize, DWORD MaxWait) { DWORD TotalWaitTime = 0; BOOL TimedOut = FALSE; WaitForSingleObject (q->qGuard, INFINITE); if (q->msgArray == NULL) return 1; /* Queue has been destroyed */ while (QueueEmpty (q) && !TimedOut) { ReleaseMutex (q->qGuard); WaitForSingleObject (q->qNe, CV_TIMEOUT); if (MaxWait != INFINITE) { TotalWaitTime += CV_TIMEOUT; TimedOut = (TotalWaitTime > MaxWait); } WaitForSingleObject (q->qGuard, INFINITE); } /* remove the message from the queue */ if (!TimedOut) QueueRemove (q, msg, msize); /* Signal that the queue is not full as we've removed a message */ PulseEvent (q->qNf); ReleaseMutex (q->qGuard); return TimedOut ? WAIT_TIMEOUT : 0; }
int pthread_cond_signal (pthread_cond_t *cv) { // Try to release one waiting thread. BOOL retcode = PulseEvent (cv->events_[cv->SIGNAL]); return retcode; }
int pthread_cond_broadcast(pthread_cond_t *cond){ if(TRUE == PulseEvent(*cond)) return 0; else{ DWORD ret = GetLastError(); return (ret == 0)? -1 : ret; } }
// send a condition signal to wake all threads waiting on condition void Broadcast( void ) { #if defined( HAVE_POSIX_THREAD ) pthread_cond_broadcast( &mCondition ); #elif defined( HAVE_WIN32_THREAD ) PulseEvent( mCondition ); #endif }
void DInputKeyboard::stop(){ if(m_hThread){ m_Stop = true; PulseEvent(m_hEvent); } if(m_lpDIDevice) m_lpDIDevice->Unacquire(); m_lpDIDevice->SetEventNotification(NULL); }
static void SP_CALLCONV notify_main_thread(sp_session *session) { DSFYDEBUG("SESSION CALLBACK\n"); #ifdef _WIN32 PulseEvent(g_notify_event); #else pthread_kill(g_main_thread, SIGIO); #endif }
// send a condition signal to wake one thread waiting on condition // in Win32, this actually wakes up all threads, same as Broadcast // use PulseEvent to auto-reset the signal after waking all threads void Signal( void ) { #if defined( HAVE_POSIX_THREAD ) pthread_cond_signal( &mCondition ); #elif defined( HAVE_WIN32_THREAD ) PulseEvent( mCondition ); #endif }
/** * Notify all waiters and reset state to non-signaled */ Bool EVENT_Pulse(Event * e) { if (!PulseEvent(e->handle)) { ASSMSG1("PulseEvent() failed, error %lu", GetLastError()); return False; } return True; }
void CondVar::Signal() { #ifdef WIN32 PulseEvent(condVarEvent); #else pthread_cond_signal(&condVar); #endif }
bool WaitObjectContainer::Wait(unsigned long milliseconds) { if (m_noWait || m_handles.empty()) return true; if (m_handles.size() > MAXIMUM_WAIT_OBJECTS) { // too many wait objects for a single WaitForMultipleObjects call, so use multiple threads static const unsigned int WAIT_OBJECTS_PER_THREAD = MAXIMUM_WAIT_OBJECTS-1; unsigned int nThreads = (m_handles.size() + WAIT_OBJECTS_PER_THREAD - 1) / WAIT_OBJECTS_PER_THREAD; if (nThreads > MAXIMUM_WAIT_OBJECTS) // still too many wait objects, maybe implement recursive threading later? throw Err("WaitObjectContainer: number of wait objects exceeds limit"); CreateThreads(nThreads); DWORD error = S_OK; for (unsigned int i=0; i<m_threads.size(); i++) { WaitingThreadData &thread = *m_threads[i]; while (!thread.waitingToWait) // spin until thread is in the initial "waiting to wait" state Sleep(0); if (i<nThreads) { thread.waitHandles = &m_handles[i*WAIT_OBJECTS_PER_THREAD]; thread.count = STDMIN(WAIT_OBJECTS_PER_THREAD, m_handles.size() - i*WAIT_OBJECTS_PER_THREAD); thread.error = &error; } else thread.count = 0; } ResetEvent(m_stopWaiting); PulseEvent(m_startWaiting); DWORD result = ::WaitForSingleObject(m_stopWaiting, milliseconds); if (result == WAIT_OBJECT_0) { if (error == S_OK) return true; else throw Err("WaitObjectContainer: WaitForMultipleObjects failed with error " + IntToString(error)); } SetEvent(m_stopWaiting); if (result == WAIT_TIMEOUT) return false; else throw Err("WaitObjectContainer: WaitForSingleObject failed with error " + IntToString(::GetLastError())); } else { DWORD result = ::WaitForMultipleObjects(m_handles.size(), &m_handles[0], FALSE, milliseconds); if (result >= WAIT_OBJECT_0 && result < WAIT_OBJECT_0 + m_handles.size()) return true; else if (result == WAIT_TIMEOUT) return false; else throw Err("WaitObjectContainer: WaitForMultipleObjects failed with error " + IntToString(::GetLastError())); } }
void Win32Event::pulse() { if( isAvailable() ) { if( 0 == PulseEvent( event_ ) ) { PSS_THROW_PARAM1( ::pss::std::Win32Error(GetLastError()) , ""); } } else { PSS_THROW_PARAM1( ::pss::std::Win32Error(constructError_) , ""); } }
/* * Prototype: * x_status x_queue_flush(x_Queue *queue, void(*do_this)(void *data)) * Description: * Flushes the queue, it releases all the messages. The queue will be empty. * Implementation: */ x_status x_queue_flush(x_queue queue, void(*do_this)(void *data)) { x_status status = xs_success; void * data; loempa(7,"o4w - queue - Begin flush"); __try { EnterCriticalSection(&queue->w_critical_section); /* ** We have the lock, either because nobody is reading from the queue, or another thread ** has called this function and went into a pthread_cond_wait state, that temporarily ** releases the above mutex. Anyhow, we can update the number of readers of the queue. */ if (queue->o4w_queue_deleted == 1) { status = xs_deleted; goto hastalavista; } if (queue->available == 0) { status = xs_success; goto hastalavista; loempa(5,"o4w - queue - hastalavista"); } /* ** OK, when we have reached this far, everything is OK to read messages ... */ while (queue->available) { data = (void *) *queue->read; queue->read += 1; if (queue->read == queue->limit) { queue->read = queue->messages; } queue->available -= 1; do_this(data); } /* ** OK, a message was delivered successfuly, so we can signal waiting writers that there is ** room again, let's signal this condition to a writing thread. */ PulseEvent(queue->w_hEvent); hastalavista: loempa(5,"o4w - queue - hastalavista"); } __finally { LeaveCriticalSection(&queue->w_critical_section); } loempa(7,"o4w - queue - end of flush"); return status; }
void Condition::signal() { #if defined(OS_WINDOWS_VISTA_DISABLED) WakeConditionVariable(&cond); #elif defined(OS_WINDOWS) PulseEvent(cond); #elif defined(OS_UNIX) pthread_cond_signal(&cond); #endif }
static void FireTimer(UINT index) { EventTimerDef *timer = &EventTimer[index]; if(timer->Flags & TIME_CALLBACK_EVENT_SET) SetEvent((HANDLE) timer->Callback); else if(timer->Flags & TIME_CALLBACK_EVENT_PULSE) PulseEvent((HANDLE) timer->Callback); else // function timer->Callback(index+1,0,timer->User,0,0); }
VOID WINAPI serviceHandler(DWORD fdwControl) { switch (fdwControl) { case SERVICE_CONTROL_STOP: { SetThisServiceStatus(SERVICE_STOP_PENDING,1000); SetThisServiceStatus(SERVICE_STOPPED,0); shut = 1; PulseEvent(shutdownEventHandle); break; } } }
void CCintocxCtrl::OnDestroy() { COleControl::OnDestroy(); // schedule destroy event EventQue.Push(NULL,this,TERMINATEEVENT); #ifndef WIN32EVENT CintEvent.PulseEvent(); #else PulseEvent(CintEvent); #endif }
VOID static __inline ReleaseReadLock(IN PWAH_SEARCH_TABLE Table, IN PVLONG Count) { /* Decrement the count. If we went below 0, someone is waiting... */ if (InterlockedDecrement(Count) < 0) { /* We use pulse since this is a shared event */ PulseEvent(ghWriterEvent); } }
/* * pj_event_pulse() */ PJ_DEF(pj_status_t) pj_event_pulse(pj_event_t *event) { PJ_CHECK_STACK(); PJ_ASSERT_RETURN(event, PJ_EINVAL); PJ_LOG(6, (event->obj_name, "Pulsing event")); if (PulseEvent(event->hEvent)) return PJ_SUCCESS; else return PJ_RETURN_OS_ERROR(GetLastError()); }