OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
CPNGSaveThread Class Reference
Inheritance diagram for CPNGSaveThread:
[legend]
Collaboration diagram for CPNGSaveThread:
[legend]

Public Member Functions

 CPNGSaveThread (CPNGFile *png, const char *filename)
 
virtual ~CPNGSaveThread ()
 
bool Start ()
 
void SignalStop ()
 
void Stop ()
 
bool IsStarted ()
 

Static Public Member Functions

static bool HasPendingThreads ()
 

Protected Member Functions

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

Detailed Description

Definition at line 302 of file StdPNG.cpp.

Constructor & Destructor Documentation

CPNGSaveThread::CPNGSaveThread ( CPNGFile png,
const char *  filename 
)

Definition at line 324 of file StdPNG.cpp.

324  : png(png), filename(filename)
325 {
326  // keep track of current saves
327  CStdLock lock(&threads_sec);
328  threads.push_back(this);
329 }
CPNGSaveThread::~CPNGSaveThread ( )
virtual

Definition at line 331 of file StdPNG.cpp.

332 {
333  // keep track of current saves
334  CStdLock lock(&threads_sec);
335  threads.remove(this);
336 }

Member Function Documentation

void CPNGSaveThread::Execute ( )
protectedvirtual

Implements StdThread.

Definition at line 338 of file StdPNG.cpp.

References StdStrBuf::getData(), and StdThread::SignalStop().

339 {
340  // Save without feedback. There's no way to post e.g. a log message to the main thread at the moment.
341  // But if saving fails, there's just a missing screenshot, which shouldn't be a big deal.
342  png->Save(filename.getData());
343  SignalStop();
344 }
const char * getData() const
Definition: StdBuf.h:450
void SignalStop()

Here is the call graph for this function:

bool CPNGSaveThread::HasPendingThreads ( )
static

Definition at line 346 of file StdPNG.cpp.

Referenced by CPNGFile::WaitForSaves().

347 {
348  CStdLock lock(&threads_sec);
349  return !threads.empty();
350 }

Here is the caller graph for this function:

virtual bool CPNGSaveThread::IsSelfDestruct ( )
inlineprotectedvirtual

Reimplemented from StdThread.

Definition at line 318 of file StdPNG.cpp.

318 { return true; }
bool StdThread::IsStarted ( )
inlineinherited

Definition at line 336 of file StdScheduler.h.

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

Definition at line 362 of file StdScheduler.cpp.

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

Definition at line 318 of file StdScheduler.cpp.

Referenced by 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 ( )
inherited

Definition at line 302 of file StdScheduler.cpp.

References StdThread::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 ( )
inherited

Definition at line 326 of file StdScheduler.cpp.

Referenced by StdThread::Start(), and StdThread::~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 file: