/* ================ idThread::Event_WaitForThread ================ */ void idThread::Event_WaitForThread( int num ) { idThread *thread; thread = GetThread( num ); if ( !thread ) { if ( g_debugScript.GetBool() ) { // just print a warning and continue executing Warning( "Thread %d not running", num ); } } else { Pause(); waitingForThread = thread; } }
//+---------------------------------------------------------------------------- // // Method: CRemotingServices::CheckForContextMatch public // // Synopsis: This code generates a check to see if the current context and // the context of the proxy match. // //+---------------------------------------------------------------------------- // // returns zero if contexts match // returns non-zero if contexts don't match // extern "C" UINT_PTR __stdcall CRemotingServices__CheckForContextMatch(Object* pStubData) { // This method cannot have a contract because CreateStubForNonVirtualMethod assumes // it won't trash XMM registers. The code generated for contracts by recent compilers // is trashing XMM registers. STATIC_CONTRACT_NOTHROW; STATIC_CONTRACT_GC_NOTRIGGER; STATIC_CONTRACT_MODE_COOPERATIVE; // due to the Object parameter STATIC_CONTRACT_SO_TOLERANT; UINT_PTR contextID = *(UINT_PTR*)pStubData->UnBox(); UINT_PTR contextCur = (UINT_PTR)GetThread()->m_Context; return (contextCur != contextID); // chosen to match x86 convention }
bool LcdComBase::IsRunning(){ wxThread *t = GetThread(); if( t ){ if( t->IsRunning() ){ return true; } else { return false; } } return false; }
void dlgMain::OnRefreshAll(wxCommandEvent &event) { // prevent reentrancy static wxRecursionGuardFlag s_rgf; wxRecursionGuard recursion_guard(s_rgf); if (recursion_guard.IsInside()) return; if (GetThread() && GetThread()->IsRunning()) return; if (!MServer->GetServerCount()) return; m_LstCtrlServers->DeleteAllItems(); m_LstCtrlPlayers->DeleteAllItems(); QueriedServers = 0; TotalPlayers = 0; mtcs_Request.Signal = mtcs_getservers; mtcs_Request.ServerListIndex = -1; mtcs_Request.Index = -1; // Create monitor thread and run it if (this->wxThreadHelper::Create() != wxTHREAD_NO_ERROR) { wxMessageBox(_T("Could not create monitor thread!"), _T("Error"), wxOK | wxICON_ERROR); wxExit(); } GetThread()->Run(); }
void wxGISMapView::StartFlashing(wxGISEnumFlashStyle eFlashStyle) { m_eFlashStyle = eFlashStyle; Flash(eFlashStyle); Refresh(); //wait drawings end to flash if (GetThread() && GetThread()->IsRunning()) { GetThread()->Wait(); } int nMilliSec = DEFAULT_FLASH_PERIOD; switch(eFlashStyle) { case enumGISMapFlashWaves: nMilliSec /= 2; { wxGISAppConfig oConfig = GetConfig(); if(oConfig.IsOk()) nMilliSec = oConfig.ReadInt(enumGISHKCU, wxString(wxT("wxGISCommon/map/flash_waves_time")), nMilliSec); } break; default: case enumGISMapFlashNewColor: { wxGISAppConfig oConfig = GetConfig(); if(oConfig.IsOk()) nMilliSec = oConfig.ReadInt(enumGISHKCU, wxString(wxT("wxGISCommon/map/flash_newcolor_time")), nMilliSec); } break; }; m_nDrawingState = enumGISMapFlashing; m_timer.Start(nMilliSec); }
int piwait(int tid){ Initialize(); TCB_t* waitedThread; //TRY TO GET THREAD TO BE WAITED FOR FROM //THREAD LISTS waitedThread = GetThread(activeThreads, tid); if(!waitedThread){ waitedThread = GetThread(expiredThreads, tid); if(!waitedThread){ waitedThread = GetThread(blockedThreads, tid); if(!waitedThread){ waitedThread = GetThread(mutexBlockedThreads, tid); } } } //IF FOUND THE SPECIFIED TID IN THREAD LISTS if(waitedThread){ //THE SPECIFIED TID CAN'T BE WAITED FOR //ANOTHER THREAD if(!GetWait(waitTids, tid)){ waitTids = AddWait(waitTids, tid, runningThread->tid); runningThread->state = BLOCKED; swapcontext(&runningThread->context, schedulerCtx); return 0; } } return -1; }
/* ================ idThread::ObjectMoveDone ================ */ void idThread::ObjectMoveDone( int threadnum, idEntity *obj ) { idThread *thread; if ( !threadnum ) { return; } thread = GetThread( threadnum ); if ( thread ) { thread->ObjectMoveDone( obj ); } }
wxThread::ExitCode Timer::Entry() { // here we do our long task, periodically calling TestDestroy(): while (_running && !GetThread()->TestDestroy()) { wxMilliSleep(_ms); if (_running) { wxQueueEvent(_parent->GetEventHandler(), new wxCommandEvent(UpdateEvent)); //new wxTimerEvent()); } } // TestDestroy() returned true (which means the main thread asked us // to terminate as soon as possible) or we ended the long task... return (wxThread::ExitCode)0; }
// Posts a message from the main thread to the monitor thread bool dlgMain::MainThrPostEvent(mtcs_t CommandSignal, wxInt32 Index, wxInt32 ListIndex) { if (GetThread() && GetThread()->IsRunning()) return false; // Create monitor thread if (this->wxThreadHelper::Create() != wxTHREAD_NO_ERROR) { wxMessageBox(_T("Could not create monitor thread!"), _T("Error"), wxOK | wxICON_ERROR); wxExit(); } mtcs_Request.Signal = CommandSignal; mtcs_Request.Index = Index; mtcs_Request.ServerListIndex = ListIndex; GetThread()->Run(); return true; }
void CrstBase::PostEnter() { if (g_pThreadStore->IsCrstForThreadStore(this)) return; Thread* pThread = GetThread(); if (pThread) { if (!m_heldInSuspension) m_ulReadyForSuspensionCount = pThread->GetReadyForSuspensionCount(); if (!m_enterInCoopGCMode) m_enterInCoopGCMode = pThread->PreemptiveGCDisabled(); } }
bool wxGxDiscConnectionUI::CreateAndRunCheckThread(void) { if (CreateThread(wxTHREAD_JOINABLE) != wxTHREAD_NO_ERROR) { wxLogError(_("Could not create the thread!")); return false; } if (GetThread()->Run() != wxTHREAD_NO_ERROR) { wxLogError(_("Could not run the thread!")); return false; } return true; }
FCIMPLEND #endif // !FEATURE_CORECLR FCIMPL4(void, AssemblyNameNative::Init, Object * refThisUNSAFE, OBJECTREF * pAssemblyRef, CLR_BOOL fForIntrospection, CLR_BOOL fRaiseResolveEvent) { FCALL_CONTRACT; ASSEMBLYNAMEREF pThis = (ASSEMBLYNAMEREF) (OBJECTREF) refThisUNSAFE; HRESULT hr = S_OK; HELPER_METHOD_FRAME_BEGIN_1(pThis); *pAssemblyRef = NULL; if (pThis == NULL) COMPlusThrow(kNullReferenceException, W("NullReference_This")); Thread * pThread = GetThread(); CheckPointHolder cph(pThread->m_MarshalAlloc.GetCheckpoint()); //hold checkpoint for autorelease AssemblySpec spec; hr = spec.InitializeSpec(&(pThread->m_MarshalAlloc), (ASSEMBLYNAMEREF *) &pThis, TRUE, FALSE); if (SUCCEEDED(hr)) { spec.AssemblyNameInit(&pThis,NULL); } else if ((hr == FUSION_E_INVALID_NAME) && fRaiseResolveEvent) { Assembly * pAssembly = GetAppDomain()->RaiseAssemblyResolveEvent(&spec, fForIntrospection, FALSE); if (pAssembly == NULL) { EEFileLoadException::Throw(&spec, hr); } else { *((OBJECTREF *) (&(*pAssemblyRef))) = pAssembly->GetExposedObject(); } } else { ThrowHR(hr); } HELPER_METHOD_FRAME_END(); }
void SpinLock::dbg_EnterLock() { Thread *pThread = GetThread(); if (pThread) { if (!m_heldInSuspension) m_ulReadyForSuspensionCount = pThread->GetReadyForSuspensionCount(); if (!m_enterInCoopGCMode) m_enterInCoopGCMode = (pThread->PreemptiveGCDisabled() == TRUE); } else { _ASSERTE(g_fProcessDetach == TRUE || dbgOnly_IsSpecialEEThread()); } }
JEventBody* JThreadManager::MakeEventBody(JCHAR* pThrdName, JCHAR* pModName, JEVT_TYPE eType) { JThread* pThread = JNULL; JEventBody* pEventBody = JNULL; JLogAutoPtr clsLogAutoPtr(JSingleton<JLog>::instance(), JLOG_MOD_THREAD, "JThreadManager::MakeEventBody"); pThread = GetThread(pThrdName); if (pThread) { pEventBody = pThread->MakeEventBody(eType, pModName); } return pEventBody; }
bool wxGISProcess::CreateAndRunReadThread(void) { if (CreateThread(wxTHREAD_JOINABLE) != wxTHREAD_NO_ERROR)//wxTHREAD_DETACHED// { wxLogError(_("Could not create the thread!")); return false; } // go! if (GetThread()->Run() != wxTHREAD_NO_ERROR) { wxLogError(_("Could not run the thread!")); return false; } return true; }
bool wxGISServerApp::CreateAndRunExitThread(void) { if (CreateThread(wxTHREAD_JOINABLE) != wxTHREAD_NO_ERROR)////wxTHREAD_DETACHED { wxLogError(_("Could not create the exit thread!")); return false; } // go! if (GetThread()->Run() != wxTHREAD_NO_ERROR) { wxLogError(_("Could not run the exit thread!")); return false; } return true; }
bool wxGxContentView::CreateAndRunFillMetaThread(void) { if (CreateThread(wxTHREAD_DETACHED) != wxTHREAD_NO_ERROR) { wxLogError(_("Could not create the thread!")); return false; } if (GetThread()->Run() != wxTHREAD_NO_ERROR) { wxLogError(_("Could not run the thread!")); return false; } return true; }
/* ================ idThread::Init ================ */ void idThread::Init( void ) { // create a unique threadNum do { threadIndex++; if( threadIndex == 0 ) { threadIndex = 1; } } while( GetThread( threadIndex ) ); threadNum = threadIndex; threadList.Append( this ); creationTime = gameLocal.time; lastExecuteTime = 0; manualControl = false; ClearWaitFor(); interpreter.SetThread( this ); }
void PacketManager :: GetPackets2(void) { if(mQueueData.size() == 0) return; #ifdef DEBUG_TIME Debug::TimeTrack("GetPackets2", 50); #endif GetThread("PacketManager::GetPackets2"); mTransition.assign(mQueueData.begin(), mQueueData.end()); mQueueData.clear(); ReleaseThread(); //Sort the transition list into the outgoing Send list according to socket. //Try to cluster the packets if possible. std::list<PendingSocket>::iterator it; std::list<Packet>::iterator pit; for(it = mTransition.begin(); it != mTransition.end(); ++it) { PendingSocket *pSock = GetSendSocket(it->mSocket); if(pSock != NULL) { for(pit = it->mPacketList.begin(); pit != it->mPacketList.end(); ++pit) { int r = pSock->AddData(*pit); if(r == PendingSocket::DATA_ELEMENT_APPEND) { mClusterPackets++; mClusterPacketBytes += pit->mData.size(); } } } } //All sorted, wipe the transition buffer. mTransition.clear(); /* if(mSendData.size() == 0) mSendData.assign(mQueueData.begin(), mQueueData.end()); else mSendData.insert(mSendData.end(), mQueueData.begin(), mQueueData.end()); mQueueData.clear(); ReleaseThread(); */ }
bool ThreadInfo::CanInvokeJS() const { #ifdef SPS_STANDALONE return false; #else nsIThread* thread = GetThread(); if (!thread) { MOZ_ASSERT(IsMainThread()); return true; } bool result; mozilla::DebugOnly<nsresult> rv = thread->GetCanInvokeJS(&result); MOZ_ASSERT(NS_SUCCEEDED(rv)); return result; #endif }
// Block waiting for data to become available on the console stream indicated by the safe file handle passed. // Ensure that the thread remains abortable in the process. FCIMPL2(void, ConsoleStreamHelper::WaitForAvailableConsoleInput, SafeHandle* refThisUNSAFE, CLR_BOOL bIsPipe) { FCALL_CONTRACT; SAFEHANDLEREF refConsoleHandle(refThisUNSAFE); HELPER_METHOD_FRAME_BEGIN_1(refConsoleHandle); // Prevent the console handle being closed under our feet. SafeHandleHolder shh(&refConsoleHandle); // Don't pass the address of the native handle within the safe handle to DoAppropriateWait since the safe // handle is on the GC heap and could be moved. Instead copy the native handle out into a stack location // (this is safe because we've ref-counted the safe handle to prevent it being disposed on us). HANDLE hNativeConsoleHandle = refConsoleHandle->GetHandle(); bool skipWait = false; // If we are reading from a pipe and the other end of the pipe was closed, then do not block. No one can write to it. // Also we can skip blocking if we do have data available. We should block if nothing is available, with the assumption // that Windows is smart enough to handle pipes where the other end is closed. if (bIsPipe) { DWORD cBytesRead, cTotalBytesAvailable, cBytesLeftThisMessage; int r = PeekNamedPipe(hNativeConsoleHandle, NULL, 0, &cBytesRead, &cTotalBytesAvailable, &cBytesLeftThisMessage); if (r != 0) { skipWait = cTotalBytesAvailable > 0; } else { // Windows returns ERROR_BROKEN_PIPE if the other side of a pipe is closed. However, we've seen // pipes return ERROR_NO_DATA and ERROR_PIPE_NOT_CONNECTED. Check for those too. int errorCode = GetLastError(); skipWait = errorCode == ERROR_BROKEN_PIPE || errorCode == ERROR_NO_DATA || errorCode == ERROR_PIPE_NOT_CONNECTED; } } // Perform the wait (DoAppropriateWait automatically handles thread aborts). if (!skipWait) { GetThread()->DoAppropriateWait(1, &hNativeConsoleHandle, TRUE, INFINITE, WaitMode_Alertable); } HELPER_METHOD_FRAME_END(); }
void GetAddrInfoOperator::Reply(DNSServiceRef aSdRef, DNSServiceFlags aFlags, uint32_t aInterfaceIndex, DNSServiceErrorType aErrorCode, const nsACString& aHostName, const NetAddr& aAddress, uint32_t aTTL) { MOZ_ASSERT(GetThread() == NS_GetCurrentThread()); auto guard = MakeScopeExit([&] { Unused << NS_WARN_IF(NS_FAILED(Stop())); }); if (NS_WARN_IF(kDNSServiceErr_NoError != aErrorCode)) { LOG_E("GetAddrInfoOperator::Reply (%d)", aErrorCode); return; } if (!mListener) { return; } NetAddr addr = aAddress; nsCOMPtr<nsINetAddr> address = new nsNetAddr(&addr); nsCString addressStr; if (NS_WARN_IF(NS_FAILED(address->GetAddress(addressStr)))) { return; } nsCOMPtr<nsIDNSServiceInfo> info = new nsDNSServiceInfo(mServiceInfo); if (NS_WARN_IF(NS_FAILED(info->SetAddress(addressStr)))) { return; } /** * |kDNSServiceFlagsMoreComing| means this callback will be one or more * callback events later, so this instance should be kept alive until all * follow-up events are processed. */ if (aFlags & kDNSServiceFlagsMoreComing) { guard.release(); } if (kDNSServiceErr_NoError == aErrorCode) { mListener->OnServiceResolved(info); } else { mListener->OnResolveFailed(info, aErrorCode); } }
void PacketManager::ExternalAddPacket(int socket, const char *data, int length) { if (length == 0) { g_Logs.server->error("Cannot add packet of zero size."); return; } Packet packet; packet.Assign(data, length); GetThread("PacketManager::ExternalAddPacket"); PendingSocket *pSock = GetPendingSocket(socket); if (pSock != NULL) pSock->mPacketList.push_back(packet); //Clustering will be performed when the thread grabs and sorts this pending data. else g_Logs.server->error("Could not retrieve a PendingSocket object."); ReleaseThread(); }
wxThread::ExitCode TaskBase::Entry() { // here we do our long task, periodically calling TestDestroy(): // TODO(JK#1#2017-09-29): do not use _running to stop the task but another variable. Use _running = false here to check afterwards if running while (_running && !GetThread()->TestDestroy()) { update(); // give other tasks some time wxMilliSleep(1); } // call onStop whenever the thread exits its main loop (i.e is stopped by user or system) onStop(); // reset recording state _recording = false; // TestDestroy() returned true (which means the main thread asked us // to terminate as soon as possible) or we ended the long task... return (wxThread::ExitCode)0; }
/* * HndCreateHandle * * Entrypoint for allocating an individual handle. * */ OBJECTHANDLE HndCreateHandle(HHANDLETABLE hTable, UINT uType, OBJECTREF object, LPARAM lExtraInfo) { // update perf-counters: track number of handles COUNTER_ONLY(GetGlobalPerfCounters().m_GC.cHandles ++); COUNTER_ONLY(GetPrivatePerfCounters().m_GC.cHandles ++); VALIDATEOBJECTREF(object); // fetch the handle table pointer HandleTable *pTable = Table(hTable); // sanity check the type index _ASSERTE(uType < pTable->uTypeCount); // get a handle from the table's cache OBJECTHANDLE handle = TableAllocSingleHandleFromCache(pTable, uType); // did the allocation succeed? if (handle) { // yep - the handle better not point at anything yet _ASSERTE(*(_UNCHECKED_OBJECTREF *)handle == NULL); // we are not holding the lock - check to see if there is nonzero extra info if (lExtraInfo) { // initialize the user data BEFORE assigning the referent // this ensures proper behavior if we are currently scanning HandleQuickSetUserData(handle, lExtraInfo); } // store the referent HndAssignHandle(handle, object); } else FailFast(GetThread(), FatalOutOfMemory); #ifdef _DEBUG DEBUG_TrackAlloc(handle); #endif // return the result return handle; }
void SceneryManager::RunGarbageCheck(void) { if(mActiveLocations.size() == 0) return; ActiveLocation::CONTAINER perZone; ITERATOR zoneit; GetThread("SceneryManager::RunGarbageCheck"); zoneit = mZones.begin(); while(zoneit != mZones.end()) { //Build a list of all active locations that match this zone. for(size_t i = 0; i < mActiveLocations.size(); i++) { if(mActiveLocations[i] == zoneit->second.mZone) perZone.push_back(mActiveLocations[i]); /* if(mActiveLocations[i].mZoneID == zoneit->second.mZone) perZone.push_back(mActiveLocations[i]); */ } //Pass the filtered active locations to the zone's garbage checker. //Since unmatched zones are filtered out, fewer iterations are needed for each tile. zoneit->second.RemoveInactiveTiles(perZone); if(perZone.size() > 0) perZone.clear(); if(zoneit->second.GetTileCount() == 0) { g_Log.AddMessageFormat("[SCENERY] Removing inactive Zone: %d", zoneit->second.mZone); mZones.erase(zoneit++); } else zoneit++; } mActiveLocations.clear(); ReleaseThread(); }
HRESULT CorHost::CreateEvidence(IUnknown **pEvidence) { HRESULT hr = S_OK; if (!pEvidence) return E_POINTER; BEGINCANNOTTHROWCOMPLUSEXCEPTION(); // Create the domain. Thread* pThread = GetThread(); if (!pThread) IfFailGo(E_UNEXPECTED); IfFailGo(QuickCOMStartup()); BOOL fWasGCEnabled; fWasGCEnabled = !pThread->PreemptiveGCDisabled(); if (fWasGCEnabled) pThread->DisablePreemptiveGC(); COMPLUS_TRY { struct _gc { OBJECTREF pEvidence; } gc; ZeroMemory(&gc, sizeof(gc)); MethodTable* pMT = g_Mscorlib.GetClass(CLASS__EVIDENCE); GCPROTECT_BEGIN(gc); gc.pEvidence = AllocateObject(pMT); IfFailThrow(QuickCOMStartup()); *pEvidence = GetComIPFromObjectRef((OBJECTREF*) &gc.pEvidence); GCPROTECT_END(); } COMPLUS_CATCH { hr = SecurityHelper::MapToHR(GETTHROWABLE()); } COMPLUS_END_CATCH if (fWasGCEnabled) pThread->EnablePreemptiveGC(); ErrExit: ENDCANNOTTHROWCOMPLUSEXCEPTION(); return hr; }
void SceneryManager::CheckAutosave(bool force) { if(g_ServerTime < mNextAutosaveTime && force == false) return; int debugPagesSaved = 0; int debugPropsSaved = 0; GetThread("SceneryPage::CheckAutosave"); ITERATOR it; for(it = mZones.begin(); it != mZones.end(); ++it) it->second.CheckAutosave(debugPagesSaved, debugPropsSaved); ReleaseThread(); mNextAutosaveTime = g_ServerTime + g_SceneryAutosaveTime; if(debugPropsSaved > 0) g_Log.AddMessageFormat("[SCENERY] Saved %d props in %d pages.", debugPropsSaved, debugPagesSaved); }
void LLDBThreadsView::OnContextMenu(wxDataViewEvent& event) { wxDataViewItemArray items; m_dvListCtrlThreads->GetSelections(items); std::vector<int> threadIds; for(size_t i = 0; i < items.GetCount(); ++i) { const auto& item = items.Item(i); const auto cd = reinterpret_cast<LLDBThreadViewClientData*>(m_dvListCtrlThreads->GetItemData(item)); if(cd) { const auto threadId = cd->GetThread().GetId(); if(threadId != wxNOT_FOUND) { threadIds.push_back(threadId); } } } wxMenu menu; if(!threadIds.empty()) { const auto suffix = (threadIds.size() > 1) ? wxT("s") : wxT(""); menu.Append(lldbSuspendThreadIds, wxString("Suspend thread") << suffix); menu.Append(lldbSuspendOtherThreadIds, wxString("Suspend other threads")); menu.AppendSeparator(); menu.Append(lldbResumeThreadIds, wxString("Resume thread") << suffix); menu.Append(lldbResumeOtherThreadIds, wxString("Resume other threads")); } menu.Append(lldbResumeAllThreadsId, wxString("Resume all threads")); const auto sel = GetPopupMenuSelectionFromUser(menu); if(lldbSuspendThreadIds == sel) { m_plugin->GetLLDB()->SuspendThreads(threadIds); } else if(lldbSuspendOtherThreadIds == sel) { m_plugin->GetLLDB()->SuspendOtherThreads(threadIds); } else if(lldbResumeThreadIds == sel) { m_plugin->GetLLDB()->ResumeThreads(threadIds); } else if(lldbResumeOtherThreadIds == sel) { m_plugin->GetLLDB()->ResumeOtherThreads(threadIds); } else if(lldbResumeAllThreadsId == sel) { m_plugin->GetLLDB()->ResumeAllThreads(); } }
// Return per-thread allocation information. HRESULT CorHost::GetThreadStats( DWORD *pFiberCookie, COR_GC_THREAD_STATS *pStats) { Thread *pThread; // Get the thread from the caller or the current thread. if (!pFiberCookie) pThread = GetThread(); else pThread = (Thread *) pFiberCookie; if (!pThread) return (E_INVALIDARG); // Get the allocation context which contains this counter in it. alloc_context *p = &pThread->m_alloc_context; pStats->PerThreadAllocation = p->alloc_bytes; if (pThread->GetHasPromotedBytes()) pStats->Flags = COR_GC_THREAD_HAS_PROMOTED_BYTES; return (S_OK); }