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)
 
 ~CPNGSaveThread () override
 
bool Start ()
 
void SignalStop ()
 
void Stop ()
 
bool IsStarted ()
 

Static Public Member Functions

static bool HasPendingThreads ()
 

Protected Member Functions

void Execute () override
 
bool IsSelfDestruct () override
 
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 ( )
override

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 ( )
overrideprotectedvirtual

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:442
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:

bool CPNGSaveThread::IsSelfDestruct ( )
inlineoverrideprotectedvirtual

Reimplemented from StdThread.

Definition at line 318 of file StdPNG.cpp.

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

Definition at line 332 of file StdScheduler.h.

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

Definition at line 342 of file StdScheduler.cpp.

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

Definition at line 298 of file StdScheduler.cpp.

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

Definition at line 282 of file StdScheduler.cpp.

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

Definition at line 306 of file StdScheduler.cpp.

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