foobar2000 SDK  2015-08-03
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
CSimpleThreadabstract

#include <fb2k_threads.h>

+ Inheritance diagram for CSimpleThread:

Public Member Functions

void AbortThread ()
 
bool IsThreadActive () const
 
void StartThread (int priority)
 
void StartThread ()
 
void WaitTillThreadDone ()
 

Protected Member Functions

 CSimpleThread ()
 
 ~CSimpleThread ()
 
virtual void ThreadDone (unsigned p_code)
 
virtual unsigned ThreadProc (abort_callback &p_abort)=0
 

Private Member Functions

void CloseThread ()
 
void on_task_completion (unsigned p_id, unsigned p_status)
 
 PFC_CLASS_NOT_COPYABLE_EX (CSimpleThread)
 
void threadProc ()
 
- Private Member Functions inherited from completion_notify_receiver
 ~completion_notify_receiver ()
 
completion_notify::ptr create_or_get_task (unsigned p_id)
 
completion_notify_ptr create_task (unsigned p_id)
 
bool have_task (unsigned p_id) const
 
void orphan_all_tasks ()
 
void orphan_task (unsigned p_id)
 
- Private Member Functions inherited from pfc::thread
 thread ()
 
 ~thread ()
 
int getPriority ()
 
bool isActive () const
 
 PFC_DECLARE_EXCEPTION (exception_creation, exception,"Could not create thread")
 
pthread_t posixThreadHandle ()
 
void setPriority (int priority)
 
void start ()
 
void startWithPriority (int priority)
 
void waitTillDone ()
 
void winStart (int priority, DWORD *outThreadID)
 
HANDLE winThreadHandle ()
 

Private Attributes

abort_callback_impl m_abort
 
completion_notify_ptr m_ownNotify
 

Additional Inherited Members

- Static Private Member Functions inherited from pfc::thread
static int currentPriority ()
 

Detailed Description

IMPORTANT: all classes derived from CSimpleThread must call AbortThread()/WaitTillThreadDone() in their destructors, to avoid object destruction during a virtual function call!

Definition at line 34 of file fb2k_threads.h.

Constructor & Destructor Documentation

CSimpleThread::CSimpleThread ( )
inlineprotected

Definition at line 56 of file fb2k_threads.h.

56 {}
CSimpleThread::~CSimpleThread ( )
inlineprotected

Definition at line 57 of file fb2k_threads.h.

57 {AbortThread();}
void AbortThread()
Definition: fb2k_threads.h:45

Member Function Documentation

void CSimpleThread::AbortThread ( )
inline

Definition at line 45 of file fb2k_threads.h.

45  {
46  m_abort.abort();
47  CloseThread();
48  }
void CloseThread()
Definition: fb2k_threads.h:63
abort_callback_impl m_abort
Definition: fb2k_threads.h:81
void CSimpleThread::CloseThread ( )
inlineprivate

Definition at line 63 of file fb2k_threads.h.

63  {
66  }
void waitTillDone()
Definition: threads.h:21
bool CSimpleThread::IsThreadActive ( ) const
inline

Definition at line 49 of file fb2k_threads.h.

49  {
50  return this->pfc::thread::isActive();
51  }
bool isActive() const
Definition: threads.cpp:70
void CSimpleThread::on_task_completion ( unsigned  p_id,
unsigned  p_status 
)
inlineprivatevirtual

Reimplemented from completion_notify_receiver.

Definition at line 68 of file fb2k_threads.h.

68  {
69  if (IsThreadActive()) {
70  CloseThread();
71  ThreadDone(p_status);
72  }
73  }
void CloseThread()
Definition: fb2k_threads.h:63
bool IsThreadActive() const
Definition: fb2k_threads.h:49
virtual void ThreadDone(unsigned p_code)
Called when the thread has completed normally, with p_code equal to ThreadProc retval. Not called when AbortThread() or WaitTillThreadDone() was used to abort the thread / wait for the thread to finish.
Definition: fb2k_threads.h:61
CSimpleThread::PFC_CLASS_NOT_COPYABLE_EX ( CSimpleThread  )
private
void CSimpleThread::StartThread ( int  priority)
inline

Definition at line 36 of file fb2k_threads.h.

36  {
37  AbortThread();
38  m_abort.reset();
40  this->pfc::thread::startWithPriority( priority );
41  }
void startWithPriority(int priority)
Definition: threads.cpp:86
completion_notify_ptr create_task(unsigned p_id)
void AbortThread()
Definition: fb2k_threads.h:45
completion_notify_ptr m_ownNotify
Definition: fb2k_threads.h:82
abort_callback_impl m_abort
Definition: fb2k_threads.h:81
void CSimpleThread::StartThread ( )
inline

Definition at line 42 of file fb2k_threads.h.

42  {
44  }
void StartThread()
Definition: fb2k_threads.h:42
static int currentPriority()
Definition: threads.cpp:106
virtual void CSimpleThread::ThreadDone ( unsigned  p_code)
inlineprotectedvirtual

Called when the thread has completed normally, with p_code equal to ThreadProc retval. Not called when AbortThread() or WaitTillThreadDone() was used to abort the thread / wait for the thread to finish.

Definition at line 61 of file fb2k_threads.h.

61 {};
virtual unsigned CSimpleThread::ThreadProc ( abort_callback p_abort)
protectedpure virtual
void CSimpleThread::threadProc ( )
inlineprivatevirtual

Reimplemented from pfc::thread.

Definition at line 74 of file fb2k_threads.h.

74  {
75  unsigned code = ~0;
76  try {
77  code = ThreadProc(m_abort);
78  } catch(...) {}
79  if (!m_abort.is_aborting()) m_ownNotify->on_completion_async(code);
80  }
virtual unsigned ThreadProc(abort_callback &p_abort)=0
completion_notify_ptr m_ownNotify
Definition: fb2k_threads.h:82
abort_callback_impl m_abort
Definition: fb2k_threads.h:81
void CSimpleThread::WaitTillThreadDone ( )
inline

Definition at line 52 of file fb2k_threads.h.

52  {
53  CloseThread();
54  }
void CloseThread()
Definition: fb2k_threads.h:63

Field Documentation

abort_callback_impl CSimpleThread::m_abort
private

Definition at line 81 of file fb2k_threads.h.

completion_notify_ptr CSimpleThread::m_ownNotify
private

Definition at line 82 of file fb2k_threads.h.


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