void CadenceThread() { size_t cadenceIndex = 0; while (m_ringCadence.size() > 0 && WaitForSingleObject(m_hRingStopEvent, m_ringCadence[cadenceIndex]) == WAIT_TIMEOUT) { m_KeyMutex.Enter(); if (++cadenceIndex >= m_ringCadence.size()) cadenceIndex = 0; Beep((cadenceIndex&1) != 0 ? 0 : m_ringFrequency); m_KeyMutex.Leave(); } }
bool dequeue( _Tx *out ) { bool success = false; m_cs.Enter(); if (m_queue.size() > 0) { *out = m_queue.front(); m_queue.pop(); success = true; } m_cs.Exit(); return success; }
// // Given a buffer of size DWORDs, populates the buffer with // the thread IDs of all currently active lisp threads. // Returns the number of thread IDs actually stored in the buffer. // DWORD LispThreadQueue::GetLispThreadIDs(DWORD* buf, int size) { TQCriticalSection.Enter(); ThreadRecord* tr = list; int i = 0; while (tr && i < size) { buf[i++] = tr->threadID; tr = tr->next; } TQCriticalSection.Leave(); return i; }
void LispThreadQueue::resumeAllOtherThreads() { TQCriticalSection.Enter(); ThreadRecord* tr = list; ThreadRecord* currThread = (ThreadRecord*)TlsGetValue(Thread_Index); while (tr) { if (tr != currThread) ResumeThread(tr->thread); tr = tr->next; } TQCriticalSection.Leave(); }
// Flush all existing thread streams... returns false on socket error bool AsyncStream::FlushAll(Socket &s) { OVR_CAPTURE_CPU_ZONE(AsyncStream_FlushAll); bool okay = true; g_listlock.Lock(); for(AsyncStream *curr=s_head; curr; curr=curr->m_next) { okay = curr->Flush(s); if(!okay) break; } g_listlock.Unlock(); return okay; }
bool push(const _et &element,long timeout) { if (free_space.wait(timeout) ) { c_region.enter(); int next = (last + 1) % element_count; elements[last] = element; last = next; active_buffers++; c_region.leave(); data_avail.signal(); return true; } return false; }
CSSet FMLPAnalysis::short_outermost_cs(CSSet::const_iterator begin, CSSet::const_iterator end) const { stack<CriticalSection> s; for (auto i = begin; i != end; ++i) s.push(*i); CSSet work; while(s.size() >0) { CriticalSection cs = s.top(); s.pop(); Resource r = get_res(cs.get_resource()); if (r.is_short()) work.push_back(cs); else for (auto i = cs.begin(); i!=cs.end(); ++i) s.push(*i); } return work; }
int ServiceManager::release(void *svcptr) { if (svcptr == NULL) return 0; waServiceFactory *wsvc = NULL; cs.enter(); // note cs getting locked twice via release+unlock if (!lockmap.getItem(svcptr, &wsvc)) { cs.leave(); DebugString("WARNING: got release with no lock record!"); return 0; } unlock(svcptr); cs.leave(); ASSERT(wsvc != NULL); return wsvc->releaseInterface(svcptr); }
//------------------------------------------------------------------------------------------------------------------------------------ bool __stdcall spiInitialize( client_info *gameClientInfo, user_info *userData, battle_info *bnCallbacks, module_info *moduleData, HANDLE hEvent) { // Called when the module is loaded // DropMessage(0, "spiInitialize"); fatalError = false; gameAppInfo = *gameClientInfo; receiveEvent = hEvent; critSec.init(); try { pluggedNetwork->initialize(); } catch(GeneralException &e) { fatalError = true; DropLastError(__FUNCTION__ " unhandled exception: %s", e.getMessage()); return false; } return true; }
void safeExit(int retcode) { bool shutdown; globalMutex.lock(false); shutdown=deadYet; if(!deadYet) { deadYet=true; cleanup(); fconfig_deleteinstance(); } globalMutex.unlock(false); if(!shutdown) exit(retcode); else pthread_exit(0); }
void unlock() { #ifdef DEBUG if (!locked) throw "Already unlocked"; #endif cs->leave(); locked = false; }
/////////////////////////////////////////////////////////////////////////////////////////////////////// // this function builds up the log string and outputs it to various places based on display flags /////////////////////////////////////////////////////////////////////////////////////////////////////// void LogMgr::Log(const string& tag, const string& message, const char* func, const char* source, unsigned int line) { _tag_critical_section.Lock(); Tags::iterator it = _tags.find(tag); if(it != _tags.end()) { _tag_critical_section.Unlock(); string buffer; GetOutputBuffer(buffer, tag, message, func, source, line); OutputFinalBufferToLogs(buffer, it->second); } else { //critical section is exited in the if above, so need to do it here if above wasnt executed _tag_critical_section.Unlock(); } }
void lock() { #ifdef DEBUG if (locked) throw "Already locked"; #endif cs->enter(); locked = true; }
void LogMgr::log(const std::string& tag, const std::string& message, const char* funcName, const char* sourceFile, unsigned int lineNum) { m_TagCriticalSection.lock(); Tags::iterator findIt = m_Tags.find(tag); if (findIt != m_Tags.end()) { m_TagCriticalSection.unlock(); std::string buffer; getOutputBuffer(buffer, tag, message, funcName, sourceFile, lineNum); outputFinalBufferToLogs(buffer, tag, findIt->second); } else { m_TagCriticalSection.unlock(); } }
void LogMgr::setDisplayFLags(const std::string& tag, unsigned char flags) { m_TagCriticalSection.lock(); if (flags != 0) { Tags::iterator findIt = m_Tags.find(tag); if (findIt == m_Tags.end()) m_Tags.insert(std::make_pair(tag, flags)); else findIt->second = flags; } else { m_Tags.erase(tag); } m_TagCriticalSection.unlock(); }
/////////////////////////////////////////////////////////////////////////////////////// // sets one or more display flags /////////////////////////////////////////////////////////////////////////////////////// void LogMgr::SetDisplayFlags(const std::string& tag, unsigned char flags) { _tag_critical_section.Lock(); if(flags != 0) { Tags::iterator it = _tags.find(tag); if(it == _tags.end()) _tags.insert(std::make_pair(tag, flags)); else it->second = flags; } else { _tags.erase(tag); } _tag_critical_section.Unlock(); }
void JUCETaskSuspend(int taskID) { tasklistmutex.enter(); JUCETask *thistask; thistask = taskArray[taskID]; tasklistmutex.exit(); if (thistask != NULL) { if (Thread::getCurrentThreadId() != thistask->getThreadId()) { thistask->stopThread(5000); } else thistask->signalThreadShouldExit(); } }
//--------------------------------------------------------------------------- const wchar_t* MB2WC(void* Handle, size_t Pos, const char* Text) { //Coherancy Critical.Enter(); mi_inputs::iterator MI_Input=MI_Inputs.find(Handle); if (MI_Input==MI_Inputs.end()) { MI_Inputs[Handle]=new mi_input; //Generic Handle MI_Input=MI_Inputs.find(Handle); } Critical.Leave(); //Adaptation if (utf8) return MI_Input->second->Unicode[Pos].From_UTF8(Text).c_str(); else return MI_Input->second->Unicode[Pos].From_Local(Text).c_str(); }
//--------------------------------------------------------------------------- const char* WC2MB(void* Handle, const wchar_t* Text) { //Coherancy Critical.Enter(); mi_outputs::iterator MI_Output=MI_Outputs.find(Handle); if (MI_Outputs.find(Handle)==MI_Outputs.end()) { MI_Outputs[Handle]=new mi_output; //Generic Handle MI_Output=MI_Outputs.find(Handle); } Critical.Leave(); //Adaptation if (utf8) MI_Output->second->Ansi=Ztring(Text).To_UTF8(); else MI_Output->second->Ansi=Ztring(Text).To_Local(); return MI_Output->second->Ansi.c_str(); }
//------------------------------------------------------------------------------------------------------------------------------------ // This function builds up the log string and outputs it to various places based on the display flags (m_displayFlags). //------------------------------------------------------------------------------------------------------------------------------------ void LogMgr::Log(const string& tag, const string& message, const char* funcName, const char* sourceFile, unsigned int lineNum) { m_tagCriticalSection.Lock(); Tags::iterator findIt = m_tags.find(tag); if (findIt != m_tags.end()) { m_tagCriticalSection.Unlock(); string buffer; GetOutputBuffer(buffer, tag, message, funcName, sourceFile, lineNum); OutputFinalBufferToLogs(buffer, findIt->second); } else { // Critical section is exited in the if statement above, so we need to exit it here if that didn't // get executed. m_tagCriticalSection.Unlock(); } } // end LogMgr::Log()
int MutexListList_GetID(CriticalSection *mutexPointer) { queuelistmutex.enter(); MutexList_t *temp = MutexList; int returnID = -1; while (temp != NULL) { if (temp->mutexPointer == mutexPointer) { returnID = temp->mutexID; break; } temp = temp->next; } queuelistmutex.exit(); return returnID; }
void JUCETaskResumeAll(void) { tasklistmutex.enter(); JUCETask *thistaskArray[MAX_JUCETASKS]; for (unsigned int i = 0; i < MAX_JUCETASKS; i++) { thistaskArray[i] = taskArray[i]; } tasklistmutex.exit(); for (unsigned int i = 0; i < MAX_JUCETASKS; i++) { if (thistaskArray[i] != NULL) { thistaskArray[i]->startThread(); } } }
HANDLE LispThreadQueue::GetLispThreadHandle(DWORD id) { TQCriticalSection.Enter(); ThreadRecord* tr = list; int i = 0; HANDLE ret = 0; while (tr) { if (id == tr->threadID) { ret = tr->thread; break; } tr = tr->next; } if (!tr) ret = 0; TQCriticalSection.Leave(); return ret; }
STDMETHODIMP DynamicDisplayItem::RetrieveIconDataAsync( IconExtractParams * theParams, void * theAsyncArg ) { HRESULT aRes = E_FAIL; CComQIPtr<IIconAcceptor> aExtr(myItem); if (aExtr == 0) return aRes; aRes = aExtr->RetrieveIconDataAsync(theParams, theAsyncArg); if ( FAILED(aRes) ) return aRes; gDisplayItemCS.Enter(); aRes = UpdateIconData(HRESULT_CODE(aRes), theParams); gDisplayItemCS.Leave(); return aRes; }
int ServiceManager::unlock(void *svcptr) { if (svcptr == NULL) return 0; waServiceFactory *wsvc = NULL; cs.enter(); if (!lockmap.getItem(svcptr, &wsvc)) { cs.leave(); DebugString("WARNING: got unlock with no lock record!"); return 0; } int r = lockmap.delItem(svcptr); ASSERT(r); //CUT // this might fail, client locking isn't enforceable //CUT clientmap.delItem(svcptr); cs.leave(); return 1; }
CriticalSection *MutexList_GetPointer(int mutexID) { queuelistmutex.enter(); MutexList_t *temp = MutexList; CriticalSection *returnPointer = NULL; while (temp != NULL) { if (temp->mutexID == mutexID) { returnPointer = temp->mutexPointer; break; } temp = temp->next; } queuelistmutex.exit(); return returnPointer; }
void ProfileSection::AddProfileToMap(const std::string& profileName){ profileCritSec.Enter(); ProfileMapIterator profileEntry = s_profileMap.find(profileName); //if entry exists, increment existing entry if (profileEntry != s_profileMap.end()){ ProfileReport& existingProfile = (profileEntry->second); //assumes elapsed time already set existingProfile.m_totalElapsedTime += elapsedTime; existingProfile.m_numCalls++;//= numCalls; existingProfile.SetAverageElapsedTime(); } else{ //numCalls++; //add entry s_profileMap.insert(ProfileEntry(profileName, ProfileReport(profileName, totalElapsedTime, numCalls))); //Access violation reading location 0xBAADF00D. serious memory corruption here O.o } profileCritSec.Exit(); }
AsyncStream::AsyncStream(void) { m_bufferLock = 0; #if defined(OVR_CAPTURE_POSIX) OVR_CAPTURE_STATIC_ASSERT(sizeof(pid_t) <= sizeof(UInt32)); union { UInt32 i; pid_t t; }; i = 0; t = gettid(); m_threadID = i; #elif defined(OVR_CAPTURE_WINDOWS) m_threadID = static_cast<UInt32>(GetCurrentThreadId()); #else #error UNKNOWN PLATFORM! #endif m_cacheBegin = (UInt8*)malloc(s_bufferSize); m_cacheTail = m_cacheBegin; m_cacheEnd = m_cacheBegin + s_bufferSize; m_flushBegin = (UInt8*)malloc(s_bufferSize); m_flushTail = m_flushBegin; m_flushEnd = m_flushBegin + s_bufferSize; // Make sure we are open by default... we don't close until we fill the buffer... m_gate.Open(); // when we are finally initialized... add ourselves to the linked list... g_listlock.Lock(); m_next = s_head; s_head = this; g_listlock.Unlock(); // Try and acquire thread name... SendThreadName(); }
void FindContacts_Threaded(void *fc) { static CriticalSection cs; ContactFinder *cf = (ContactFinder*)fc; map<ArbiterKey, Arbiter> &arbitersf = *cf->_arbiters; cf->last = min(cf->last, (i32)cf->potentials->size()); for(int i=cf->first;i<cf->last;++i) { World::PotentiallyColliding pc = cf->potentials->at(i); Arbiter arb(pc.body1, pc.body2); ArbiterKey arbKey(pc.body1, pc.body2); if(arb.DoCollision()) { ArbIter iter = arbitersf.find(arbKey); if(iter != arbitersf.end()) { iter->second.Update(arb.contacts, arb.numContacts); } else { cs.Lock(); cf->addList->push_back(Arbiter_ADD(arb, arbKey)); cs.Unlock(); } } else { cs.Lock(); cf->eraseList->push_back(Arbiter_ERASE(arbKey)); cs.Unlock(); } } };
void Ignition::StopAll(const bool cancel, IgniteError* err) { factoryLock.Enter(); if (started) { JniErrorInfo jniErr; SharedPointer<JniContext> ctx(JniContext::Create(NULL, 0, JniHandlers(), &jniErr)); IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err); if (err->GetCode() == IgniteError::IGNITE_SUCCESS) { ctx.Get()->IgnitionStopAll(cancel, &jniErr); IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err); } } factoryLock.Leave(); }