Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes | Private Attributes
CThread Class Reference

#include <thread.h>

Inheritance diagram for CThread:
Inheritance graph
[legend]
Collaboration diagram for CThread:
Collaboration graph
[legend]

List of all members.

Public Member Functions

BOOL setInitEvent ()
BOOL setShutEvent ()
BOOL isAlive ()
BOOL isBusy ()
HANDLE getHandle ()
void run ()
 CThread (DWORD aInitTimeOut=INFINITE, DWORD aShutTimeOut=INFINITE)
virtual ~CThread ()
BOOL open (CThread *aThread)
void close (CThread *aThread)
BOOL tryAction (int aAction)
BOOL doAction (int aAction)
virtual BOOL init ()=0
virtual void shut ()=0
virtual void dispatch ()=0

Protected Attributes

int mAction

Private Attributes

HANDLE mThread
DWORD mID
HANDLE mEventThreadInitializationFinished
HANDLE mEventThreadShutdownFinished
DWORD mInitTimeOut
DWORD mShutTimeOut
HANDLE mEventDo
ThreadState mState

Detailed Description

Definition at line 48 of file thread.h.


Constructor & Destructor Documentation

CThread::CThread ( DWORD  aInitTimeOut = INFINITE,
DWORD  aShutTimeOut = INFINITE 
)

Definition at line 64 of file thread.cpp.

CThread::~CThread ( ) [virtual]

Definition at line 78 of file thread.cpp.

{
  dbgOut1("CThread::~CThread");
}

Member Function Documentation

void CThread::close ( CThread aThread)

Definition at line 104 of file thread.cpp.

{
  switch (mState) {
    case ts_dead:
      break;
    case ts_ready:
      mState = ts_dead;
      SetEvent(mEventDo);
      if(mEventThreadShutdownFinished != NULL)
        WaitForSingleObject(mEventThreadShutdownFinished, mShutTimeOut);
      break;
    case ts_busy:
    {
      aThread->shut();
      DWORD ret;
      GetExitCodeThread(aThread->getHandle(), &ret);
      TerminateThread(mThread, ret);
      mState = ts_dead;
      break;
    }
    default:
      break;
  }

  mThread = NULL;
  CloseHandle(mEventThreadInitializationFinished);
  CloseHandle(mEventThreadShutdownFinished);
  CloseHandle(mEventDo);
  dbgOut1("CThread::close");
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void CThread::dispatch ( ) [pure virtual]

Implemented in nsPluginThread.

Here is the caller graph for this function:

BOOL CThread::doAction ( int  aAction)

Definition at line 188 of file thread.cpp.

{
  while(mState != ts_ready) {
    //dbgOut2("CThread::doAction %i -- waiting...", aAction);
    if(mState == ts_dead)
      return FALSE;
    Sleep(0);
  }

  mState = ts_busy;
  mAction = aAction;
  //dbgOut2("CThread::doAction -- about to signal %i", aAction);
  SetEvent(mEventDo);

  return TRUE;
}

Here is the caller graph for this function:

Definition at line 155 of file thread.cpp.

{
  return mThread;
}

Here is the caller graph for this function:

virtual BOOL CThread::init ( ) [pure virtual]

Implemented in nsPluginThread.

Here is the caller graph for this function:

Definition at line 145 of file thread.cpp.

{
  return (mThread != NULL);
}

Definition at line 150 of file thread.cpp.

{
  return (mState == ts_busy);
}

Here is the caller graph for this function:

BOOL CThread::open ( CThread aThread)

Definition at line 83 of file thread.cpp.

{
  dbgOut1("CThread::open");

  mEventThreadInitializationFinished = CreateEvent(NULL, TRUE, FALSE, NULL);
  mEventThreadShutdownFinished = CreateEvent(NULL, TRUE, FALSE, NULL);
  mEventDo = CreateEvent(NULL, TRUE, FALSE, NULL);

  mThread = (HANDLE)::_beginthreadex(0, 1024, (UINT (__stdcall *)(void *))ThreadFunction, aThread, 0L, (UINT *)&mID);

  if(mThread == NULL)
    return FALSE;

  SetThreadPriority(mThread, THREAD_PRIORITY_NORMAL);

  if(mEventThreadInitializationFinished != NULL)
    WaitForSingleObject(mEventThreadInitializationFinished, mInitTimeOut);

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 160 of file thread.cpp.

{
  mState = ts_ready;

  while(mState != ts_dead) {
    WaitForSingleObject(mEventDo, INFINITE);
    //dbgOut2("CThread::run(): Do event signalled, %u", mState);
    ResetEvent(mEventDo);
    if(mState == ts_dead)
      return;
    mState = ts_busy;
    dispatch();
    mState = ts_ready;
  }
  mState = ts_dead;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 135 of file thread.cpp.

{
  return SetEvent(mEventThreadInitializationFinished);
}

Here is the caller graph for this function:

Definition at line 140 of file thread.cpp.

{
  return SetEvent(mEventThreadShutdownFinished);
}

Here is the caller graph for this function:

virtual void CThread::shut ( ) [pure virtual]

Implemented in nsPluginThread.

Here is the caller graph for this function:

BOOL CThread::tryAction ( int  aAction)

Definition at line 177 of file thread.cpp.

{
  if(mState != ts_ready)
    return FALSE;

  mAction = aAction;
  SetEvent(mEventDo);

  return TRUE;
}

Member Data Documentation

int CThread::mAction [protected]

Definition at line 60 of file thread.h.

Definition at line 56 of file thread.h.

Definition at line 52 of file thread.h.

Definition at line 53 of file thread.h.

DWORD CThread::mID [private]

Definition at line 51 of file thread.h.

Definition at line 54 of file thread.h.

Definition at line 55 of file thread.h.

Definition at line 57 of file thread.h.

Definition at line 50 of file thread.h.


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