OpenClonk
StdThread Class Referenceabstract

#include <StdScheduler.h>

Inheritance diagram for StdThread:
[legend]

Public Member Functions

 StdThread ()
 
virtual ~StdThread ()
 
bool Start ()
 
void SignalStop ()
 
void Stop ()
 
bool IsStarted ()
 

Protected Member Functions

virtual void Execute ()=0
 
bool IsStopSignaled ()
 
virtual bool IsSelfDestruct ()
 

Detailed Description

Definition at line 312 of file StdScheduler.h.

Constructor & Destructor Documentation

◆ StdThread()

StdThread::StdThread ( )
default

◆ ~StdThread()

virtual StdThread::~StdThread ( )
inlinevirtual

Definition at line 326 of file StdScheduler.h.

326 { Stop(); }

References Stop().

Here is the call graph for this function:

Member Function Documentation

◆ Execute()

virtual void StdThread::Execute ( )
protectedpure virtual

◆ IsSelfDestruct()

virtual bool StdThread::IsSelfDestruct ( )
inlineprotectedvirtual

Reimplemented in CPNGSaveThread.

Definition at line 338 of file StdScheduler.h.

338 { return false; } // whether thread should delete itself after execution finished

◆ IsStarted()

bool StdThread::IsStarted ( )
inline

Definition at line 332 of file StdScheduler.h.

332 { return fStarted; }

◆ IsStopSignaled()

bool StdThread::IsStopSignaled ( )
protected

Definition at line 342 of file StdScheduler.cpp.

343 {
344  return fStopSignaled;
345 }

◆ SignalStop()

void StdThread::SignalStop ( )

Definition at line 298 of file StdScheduler.cpp.

299 {
300  // Not running?
301  if (!fStarted) return;
302  // Set flag
303  fStopSignaled = true;
304 }

Referenced by CPNGSaveThread::Execute(), C4StartupModsLocalModDiscovery::Execute(), and C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck::Execute().

Here is the caller graph for this function:

◆ Start()

bool StdThread::Start ( )

Definition at line 282 of file StdScheduler.cpp.

283 {
284  // already running? stop
285  if (fStarted) Stop();
286  // begin thread
287  fStopSignaled = false;
288 #ifdef HAVE_WINTHREAD
289  iThread = _beginthread(_ThreadFunc, 0, this);
290  fStarted = (iThread != -1);
291 #elif defined(HAVE_PTHREAD)
292  fStarted = !pthread_create(&Thread, nullptr, _ThreadFunc, this);
293 #endif
294  // success?
295  return fStarted;
296 }

References Stop().

Referenced by C4StartupModsLocalModDiscovery::C4StartupModsLocalModDiscovery(), CPNGFile::ScheduleSaving(), and C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck::Start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stop()

void StdThread::Stop ( )

Definition at line 306 of file StdScheduler.cpp.

307 {
308  // Not running?
309  if (!fStarted) return;
310  // Set flag
311  fStopSignaled = true;
312 #ifdef HAVE_WINTHREAD
313  // Wait for thread to terminate itself
314  HANDLE hThread = reinterpret_cast<HANDLE>(iThread);
315  if (WaitForSingleObject(hThread, 10000) == WAIT_TIMEOUT)
316  // ... or kill it in case it refuses to do so
317  TerminateThread(hThread, -1);
318 #elif defined(HAVE_PTHREAD)
319  // wait for thread to terminate itself
320  // (whithout security - let's trust these unwashed hackers for once)
321  pthread_join(Thread, nullptr);
322 #endif
323  fStarted = false;
324  // ok
325  return;
326 }

Referenced by Start(), and ~StdThread().

Here is the caller graph for this function:

The documentation for this class was generated from the following files: