WorkThread Class Reference

#include <workthread.h>

List of all members.


Detailed Description

WorkThread class provides an interface for submitting jobs to secondary thread for processing, and takes care of job queue handling.

This class is a Singleton, with the only instance accessible via instance() member function. To post jobs for processing, pass them to postWork() function.

Definition at line 80 of file workthread.h.


Public Member Functions

void postWork (ThreadWorkPtr work)
 Post a work for processing.

Static Public Member Functions

static WorkThreadinstance ()

Private Member Functions

void threadLoop ()
 Main work thread loop function.
bool checkExit ()
 Used by secondary thread, this is used to check whether the thread should exit.
void exit ()
 Used by main thread, this signals work thread to exit ASAP.
Singleton Pattern requirements
 WorkThread ()
 WorkThread (const WorkThread &)
WorkThreadoperator= (const WorkThread &)
 ~WorkThread ()

Private Attributes

std::deque< ThreadWorkPtrm_queue
 Pending jobs queue, filled by postWork() and processed by secondary thread.
boost::mutex m_queueLock
 Protects m_queue member.
boost::condition m_notify
 Used to signal events to secondary thread.
boost::mutex m_notifyLock
 Protects m_notify member.
bool m_exiting
 If true, work thread should exit as soon as possible.
boost::mutex m_exitLock
 Protects m_exiting member.
boost::thread m_worker
 Worker thread object.

Constructor & Destructor Documentation

WorkThread::WorkThread  )  [private]
 

Definition at line 52 of file workthread.cpp.

WorkThread::WorkThread const WorkThread  )  [private]
 

WorkThread::~WorkThread  )  [private]
 

Definition at line 55 of file workthread.cpp.

References exit(), and m_worker.

Here is the call graph for this function:


Member Function Documentation

bool WorkThread::checkExit  )  [private]
 

Used by secondary thread, this is used to check whether the thread should exit.

Definition at line 64 of file workthread.cpp.

References m_exiting, and m_exitLock.

Referenced by threadLoop().

void WorkThread::exit  )  [private]
 

Used by main thread, this signals work thread to exit ASAP.

Definition at line 68 of file workthread.cpp.

References m_exiting, m_exitLock, m_notify, and m_notifyLock.

Referenced by ~WorkThread().

WorkThread & WorkThread::instance  )  [static]
 

Definition at line 59 of file workthread.cpp.

Referenced by PartData::doComplete(), SharedFile::onPartEvent(), SharedFile::verify(), and Detail::Chunk::verify().

WorkThread& WorkThread::operator= const WorkThread  )  [private]
 

void WorkThread::postWork ThreadWorkPtr  work  ) 
 

Post a work for processing.

Parameters:
work Pointer to ThreadWork object to be processed

Definition at line 74 of file workthread.cpp.

References m_notify, m_notifyLock, m_queue, and m_queueLock.

Referenced by PartData::doComplete(), SharedFile::onPartEvent(), SharedFile::verify(), and Detail::Chunk::verify().

void WorkThread::threadLoop  )  [private]
 

Main work thread loop function.

Definition at line 80 of file workthread.cpp.

References checkExit(), logError(), m_notify, m_notifyLock, m_queue, and m_queueLock.

Here is the call graph for this function:


Member Data Documentation

bool WorkThread::m_exiting [private]
 

If true, work thread should exit as soon as possible.

Definition at line 119 of file workthread.h.

Referenced by checkExit(), and exit().

boost::mutex WorkThread::m_exitLock [private]
 

Protects m_exiting member.

Definition at line 121 of file workthread.h.

Referenced by checkExit(), and exit().

boost::condition WorkThread::m_notify [private]
 

Used to signal events to secondary thread.

Definition at line 115 of file workthread.h.

Referenced by exit(), postWork(), and threadLoop().

boost::mutex WorkThread::m_notifyLock [private]
 

Protects m_notify member.

Definition at line 117 of file workthread.h.

Referenced by exit(), postWork(), and threadLoop().

std::deque<ThreadWorkPtr> WorkThread::m_queue [private]
 

Pending jobs queue, filled by postWork() and processed by secondary thread.

Definition at line 111 of file workthread.h.

Referenced by postWork(), and threadLoop().

boost::mutex WorkThread::m_queueLock [private]
 

Protects m_queue member.

Definition at line 113 of file workthread.h.

Referenced by postWork(), and threadLoop().

boost::thread WorkThread::m_worker [private]
 

Worker thread object.

Definition at line 123 of file workthread.h.

Referenced by ~WorkThread().


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