OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 ( )
default
virtual StdThread::~StdThread ( )
inlinevirtual

Definition at line 326 of file StdScheduler.h.

References Stop().

326 { Stop(); }

Here is the call graph for this function:

Member Function Documentation

virtual void StdThread::Execute ( )
protectedpure virtual

Implemented in CPNGSaveThread.

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
bool StdThread::IsStarted ( )
inline

Definition at line 332 of file StdScheduler.h.

332 { return fStarted; }
bool StdThread::IsStopSignaled ( )
protected

Definition at line 342 of file StdScheduler.cpp.

343 {
344  return fStopSignaled;
345 }
void StdThread::SignalStop ( )

Definition at line 298 of file StdScheduler.cpp.

Referenced by CPNGSaveThread::Execute().

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

Here is the caller graph for this function:

bool StdThread::Start ( )

Definition at line 282 of file StdScheduler.cpp.

References Stop().

Referenced by CPNGFile::ScheduleSaving().

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 }

Here is the call graph for this function:

Here is the caller graph for this function:

void StdThread::Stop ( )

Definition at line 306 of file StdScheduler.cpp.

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

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 }

Here is the caller graph for this function:


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