void BasicThread::WaitForStateUpdate(const std::function<bool()>& fn) { std::unique_lock<std::mutex> lk(m_state->m_lock); m_state->m_stateCondition.wait( lk, [&fn, this] { return fn() || ShouldStop(); } ); if(ShouldStop()) throw dispatch_aborted_exception(); }
uint32 FDDCCleanup::Run() { // Give up some time to the engine to start up and load everything Wait( 120.0f, 0.5f ); int32 FilesystemToCleanup = 0; // Check one directory every 5 seconds do { // Pick one random filesystem. TSharedPtr< FFilesystemInfo > FilesystemInfo; { FScopeLock ScopeLock( &DataLock ); if( CleanupList.Num() > 0 ) { FilesystemToCleanup %= CleanupList.Num(); FilesystemInfo = CleanupList[ FilesystemToCleanup++ ]; } } if( FilesystemInfo.IsValid() ) { CleanupFilesystemDirectory( FilesystemInfo ); } Wait( 5.0f ); } while( ShouldStop() == false ); return 0; }
void CoreRunnable::Wait(void) { { std::unique_lock<std::mutex> lk(m_lock); m_cv.wait(lk, [this] { return ShouldStop() && !IsRunning(); }); } DoAdditionalWait(); }
bool CoreRunnable::WaitUntil(TimeType timepoint) { { std::unique_lock<std::mutex> lk(m_lock); if (!m_cv.wait_until(lk, timepoint, [this] { return ShouldStop() && !IsRunning(); })) return false; } return DoAdditionalWait(timepoint - TimeType::now());; }
bool CoreRunnable::WaitFor(std::chrono::nanoseconds timeout) { { std::unique_lock<std::mutex> lk(m_lock); if (!m_cv.wait_for(lk, timeout, [this] { return ShouldStop() && !IsRunning(); })) return false; } return DoAdditionalWait(timeout); }
void FDDCCleanup::Wait( const float InSeconds, const float InSleepTime ) { // Instead of waiting the given amount of seconds doing nothing // check periodically if there's been any Stop requests. for( float TimeToWait = InSeconds; TimeToWait > 0.0f && ShouldStop() == false; TimeToWait -= InSleepTime ) { FPlatformProcess::Sleep( FMath::Min(InSleepTime, TimeToWait) ); } }
void Run(void) override { while(!ShouldStop() && totalXmit < 0x7FFFF000) { // Jam for awhile in an asynchronous way: while(++totalXmit % 100) m_ci(&CallableInterface::ZeroArgs)(); if (totalXmit % 2000 == 0) std::this_thread::yield(); } }
void Run(void) override { ElevatePriority p(*this, priority); while(!ShouldStop()) { // Obtain the lock and then increment our value: std::lock_guard<std::mutex> lk(*contended); val++; } }
unsigned int ResourceLoaderThread::DoWork(void* object) { ResourceManager* resourceManager = (ResourceManager*)object; while ((resourceManager->loadQueue.size() > 0) && (!ShouldStop())) { resourceManager->criticalSection.Enter(); QueuedResource& resource = resourceManager->loadQueue.front(); switch (resource.type) { case ResourceType_Image: resourceManager->AddResource(resource.name, new ImageResource(resource.path)); break; case ResourceType_Sound: resourceManager->AddResource(resource.name, new SoundResource(resource.path)); break; case ResourceType_Font: resourceManager->AddResource(resource.name, new FontResource(resource.path)); break; case ResourceType_Text: resourceManager->AddResource(resource.name, new TextResource(resource.path)); break; case ResourceType_Buffer: resourceManager->AddResource(resource.name, new BufferResource(resource.path)); break; } resourceManager->loadQueue.pop(); resourceManager->criticalSection.Exit(); } return 0; }
void WebserverStatus::Run() { while (!ShouldStop()) { const unsigned int rate = outgoing_rate_; outgoing_rate_ -= rate; max_attained_rate_ = max_attained_rate_ < rate ? rate : max_attained_rate_; CalculateSustainedRate_(rate); CalculateAttainedRate_(rate); CalculateLatency_(); CalculateRequests_(); Wait(1000); } }
void _Scheduler::Run() { while (!ShouldStop()) { clocks::Clock::Tick(); // Run periodic tasks // taskmanager_.Execute(); Wait(500); } Shutdown_(); }
void CUpdateDlg::CheckUpdates() { m_listView.ShowWindow(SW_HIDE); ::ShowWindow(GetDlgItem(IDC_UPDATEINFO), SW_SHOW); m_Checked = true; SetDlgItemText(IDC_UPDATEINFO, TR("Проверка обновлений...")); if (!m_UpdateManager.CheckUpdates()) { TRC(IDCANCEL, "Закрыть"); m_Checked = false; CString errorStr = TR("Ошибка при получении данных об обновлениях."); errorStr += "\r\n"; errorStr += m_UpdateManager.ErrorString(); SetDlgItemText(IDC_UPDATEINFO, errorStr); return; } Settings.LastUpdateTime = static_cast<int>(time(0)); if (m_UpdateManager.AreUpdatesAvailable()) { if ( !m_UpdateManager.AreCoreUpdates() ) { DoUpdates(); return; } if (CmdLine.IsOption(_T("update"))) { DoUpdates(); return; } ::ShowWindow(GetDlgItem(IDOK), SW_SHOW); TRC(IDOK, "Обновить"); if (m_UpdateCallback) m_UpdateCallback->UpdateAvailabilityChanged(true); if (ShouldStop()) return; if (!IsWindowVisible()) SetTimer(2, 2000, 0); CString text = m_UpdateManager.generateReport(); SetDlgItemText(IDC_UPDATEINFO, text); return; } else { TRC(IDCANCEL, "Закрыть"); SetDlgItemText(IDC_UPDATEINFO, TR("Обновление не требуется.")); } }
void BaseWorker::Run() { #ifdef ENABLE_PROFILING ::startSaturn(); #endif while (!ShouldStop()) { Process_(); } #ifdef ENABLE_PROFILING ::stopSaturn(); #endif }
void CoreJob::Wait() { { std::unique_lock<std::mutex> lk(m_dispatchLock); m_queueUpdated.wait( lk, [this] { return ShouldStop() && m_curEventInTeardown; } ); } // If the current event is valid, we can block on it until it becomes valid: if(m_curEvent.valid()) m_curEvent.wait(); }
bool CoreJob::WaitFor(std::chrono::nanoseconds duration) { { std::unique_lock<std::mutex> lk(m_dispatchLock); if(!m_queueUpdated.wait_for( lk, duration, [this] { return ShouldStop() && m_curEventInTeardown; } )) return false; } // If the current event is valid, we can block on it until it becomes valid: if(m_curEvent.valid()) m_curEvent.wait(); return true; }
bool BasicThread::ThreadSleep(std::chrono::nanoseconds timeout) { std::unique_lock<std::mutex> lk(m_state->m_lock); return m_state->m_stateCondition.wait_for(lk, timeout, [this] { return ShouldStop(); }); }
bool CoreRunnable::ThreadSleep(std::chrono::nanoseconds timeout) { std::unique_lock<std::mutex> lk(m_lock); return m_cv.wait_for(lk, timeout, [this] { return ShouldStop(); }); }
void Run(void) override { while(!ShouldStop() && totalXmit < 0x7FFFF000) // Jam for awhile in an asynchronous way: while(++totalXmit % 100) m_ci(&CallableInterface::ZeroArgs)(); }
bool FDDCCleanup::CleanupFilesystemDirectory( TSharedPtr< FFilesystemInfo > FilesystemInfo ) { bool bCleanedUp = false; const double StartTime = FPlatformTime::Seconds(); // Pick one random directory. TArray<FString> FileNames; do { const int32 DirectoryIndex = FilesystemInfo->CacheDirectories.Pop(); const FString DirectoryPath( FilesystemInfo->CachePath / FString::Printf(TEXT("%1d/%1d/%1d/"),(DirectoryIndex/100)%10,(DirectoryIndex/10)%10,DirectoryIndex%10) ); IFileManager::Get().FindFilesRecursive( FileNames, *DirectoryPath, TEXT("*.*"), true, false ); if ( FilesystemInfo->CacheDirectories.Num() == 0 ) { // Remove the filesystem and stop checking it FScopeLock ScopeLock( &DataLock ); CleanupList.Remove( FilesystemInfo ); FilesystemInfo.Reset(); } else if( ++FilesystemInfo->FoldersChecked >= FilesystemInfo->MaxNumFoldersToCheck && FilesystemInfo->MaxNumFoldersToCheck > 0 ) { // Remove the filesystem but keep checking the current folder FScopeLock ScopeLock( &DataLock ); CleanupList.Remove( FilesystemInfo ); } } while( FileNames.Num() == 0 && FilesystemInfo.IsValid() && ShouldStop() == false ); if( FilesystemInfo.IsValid() && ShouldStop() == false ) { // Iterate over all files in the selected folder and check their last access time int32 NumFilesChecked = 0; for( int32 FileIndex = 0; FileIndex < FileNames.Num() && ShouldStop() == false; FileIndex++ ) { const FDateTime LastModificationTime = IFileManager::Get().GetTimeStamp( *FileNames[ FileIndex ] ); const FDateTime LastAccessTime = IFileManager::Get().GetAccessTimeStamp( *FileNames[ FileIndex ] ); if( (LastAccessTime != FDateTime::MinValue()) || (LastModificationTime != FDateTime::MinValue()) ) { const FTimespan TimeSinceLastAccess = FDateTime::UtcNow() - LastAccessTime; const FTimespan TimeSinceLastModification = FDateTime::UtcNow() - LastModificationTime; if( TimeSinceLastAccess >= FilesystemInfo->UnusedFileTime && TimeSinceLastModification >= FilesystemInfo->UnusedFileTime ) { // Delete the file bool Result = IFileManager::Get().Delete( *FileNames[ FileIndex ], false, true, true ); } } if( ++NumFilesChecked > FilesystemInfo->MaxContinuousFileChecks && FilesystemInfo->MaxContinuousFileChecks > 0 && ShouldStop() == false ) { NumFilesChecked = 0; Wait( 2.0f ); } else { // Give up a tiny amount of time so that we're not consuming too much cpu/hdd resources. Wait( 0.05f ); } } bCleanedUp = true; } UE_LOG(LogDerivedDataCache, VeryVerbose, TEXT("DDC Folder Cleanup (%s) took %.4lfs."), *FilesystemInfo->CachePath, FPlatformTime::Seconds() - StartTime); return bCleanedUp; }