OpenClonk
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 304 of file StdPNG.cpp.

Constructor & Destructor Documentation

◆ CPNGSaveThread()

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

Definition at line 326 of file StdPNG.cpp.

326  : png(png), filename(filename)
327 {
328  // keep track of current saves
329  CStdLock lock(&threads_sec);
330  threads.push_back(this);
331 }

◆ ~CPNGSaveThread()

CPNGSaveThread::~CPNGSaveThread ( )
override

Definition at line 333 of file StdPNG.cpp.

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

Member Function Documentation

◆ Execute()

void CPNGSaveThread::Execute ( )
overrideprotectedvirtual

Implements StdThread.

Definition at line 340 of file StdPNG.cpp.

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

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

Here is the call graph for this function:

◆ HasPendingThreads()

bool CPNGSaveThread::HasPendingThreads ( )
static

Definition at line 348 of file StdPNG.cpp.

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

Referenced by CPNGFile::WaitForSaves().

Here is the caller graph for this function:

◆ IsSelfDestruct()

bool CPNGSaveThread::IsSelfDestruct ( )
inlineoverrideprotectedvirtual

Reimplemented from StdThread.

Definition at line 320 of file StdPNG.cpp.

320 { return true; }

◆ IsStarted()

bool StdThread::IsStarted ( )
inlineinherited

Definition at line 332 of file StdScheduler.h.

332 { return fStarted; }

◆ IsStopSignaled()

bool StdThread::IsStopSignaled ( )
protectedinherited

Definition at line 342 of file StdScheduler.cpp.

343 {
344  return fStopSignaled;
345 }

◆ SignalStop()

void StdThread::SignalStop ( )
inherited

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 Execute(), C4StartupModsLocalModDiscovery::Execute(), and C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck::Execute().

Here is the caller graph for this function:

◆ Start()

bool StdThread::Start ( )
inherited

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

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

Here is the caller graph for this function:

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