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 316 of file StdScheduler.h.

Constructor & Destructor Documentation

StdThread::StdThread ( )

Definition at line 297 of file StdScheduler.cpp.

297  : fStarted(false), fStopSignaled(false)
298 {
299 
300 }
virtual StdThread::~StdThread ( )
inlinevirtual

Definition at line 330 of file StdScheduler.h.

References Stop().

330 { 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 342 of file StdScheduler.h.

342 { return false; } // whether thread should delete itself after execution finished
bool StdThread::IsStarted ( )
inline

Definition at line 336 of file StdScheduler.h.

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

Definition at line 362 of file StdScheduler.cpp.

363 {
364  return fStopSignaled;
365 }
void StdThread::SignalStop ( )

Definition at line 318 of file StdScheduler.cpp.

Referenced by CPNGSaveThread::Execute().

319 {
320  // Not running?
321  if (!fStarted) return;
322  // Set flag
323  fStopSignaled = true;
324 }

Here is the caller graph for this function:

bool StdThread::Start ( )

Definition at line 302 of file StdScheduler.cpp.

References Stop().

Referenced by CPNGFile::ScheduleSaving().

303 {
304  // already running? stop
305  if (fStarted) Stop();
306  // begin thread
307  fStopSignaled = false;
308 #ifdef HAVE_WINTHREAD
309  iThread = _beginthread(_ThreadFunc, 0, this);
310  fStarted = (iThread != -1);
311 #elif defined(HAVE_PTHREAD)
312  fStarted = !pthread_create(&Thread, nullptr, _ThreadFunc, this);
313 #endif
314  // success?
315  return fStarted;
316 }

Here is the call graph for this function:

Here is the caller graph for this function:

void StdThread::Stop ( )

Definition at line 326 of file StdScheduler.cpp.

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

327 {
328  // Not running?
329  if (!fStarted) return;
330  // Set flag
331  fStopSignaled = true;
332 #ifdef HAVE_WINTHREAD
333  // Wait for thread to terminate itself
334  HANDLE hThread = reinterpret_cast<HANDLE>(iThread);
335  if (WaitForSingleObject(hThread, 10000) == WAIT_TIMEOUT)
336  // ... or kill it in case it refuses to do so
337  TerminateThread(hThread, -1);
338 #elif defined(HAVE_PTHREAD)
339  // wait for thread to terminate itself
340  // (whithout security - let's trust these unwashed hackers for once)
341  pthread_join(Thread, nullptr);
342 #endif
343  fStarted = false;
344  // ok
345  return;
346 }

Here is the caller graph for this function:


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