MIRA
Classes | Public Types | Static Public Member Functions | Static Protected Member Functions | List of all members
ThreadMonitor Class Reference

A thread monitor class. More...

#include <thread/ThreadMonitor.h>

Inheritance diagram for ThreadMonitor:
Inheritance graph
[legend]

Classes

struct  ThreadInfo
 A thread information type. More...
 

Public Types

typedef Base::Type Type
 

Public Member Functions

Constructor and destructor
 ThreadMonitor ()
 Default constructor. More...
 
virtual ~ThreadMonitor ()
 The destructor. More...
 
Add and remove threads.
void addThisThread (const std::string &pName)
 Add the calling thread to the thread monitor. More...
 
void removeThisThread ()
 Remove the calling thread from the monitor. More...
 
void removeThread (const boost::thread &pThread)
 Remove a thread from the monitor. More...
 
void removeThread (const boost::thread::id &pThreadID)
 Remove a thread from the monitor. More...
 
void removeThread (ThreadID pThreadID)
 Remove a thread from the monitor. More...
 

Static Public Member Functions

static Typeinstance ()
 Returns a reference to the singleton instance. More...
 
static bool isDestroyed ()
 Returns true, if the singleton was already destroyed. More...
 

Static Protected Member Functions

static TypemakeInstance ()
 
static void destroyInstance (void)
 

Thread information

typedef std::vector< ThreadInfoThreadInfoVector
 Definition of a vector of thread information. More...
 
ThreadInfoVector getThreadInformation ()
 Collect information about all threads of the current process. More...
 

Detailed Description

A thread monitor class.

A thread monitor, which collects information about the resources of all running threads.

To add a new thread to the monitor, the method addThisThread must be called within the created thread. To remove a thread, the method removeThisThread or removeThread should be called. If a thread is stopped without calling removeThisThread first, it will be automatically removed from the internal thread list when getThreadInformation() is called.

The method getThreadInformation returns a vector of all threads of the current process (not only the threads, which are added using addThisThread). For each thread, the creation time and the used CPU time in user mode and kernel mode are determined. For threads, which were added using addThisThread also the name is returned in the vector.

Example:

void processThread()
{
ThreadMonitor::instance().addThisThread("MyThreadName");
while (!boost::this_thread::interruption_requested())
{
...
}
ThreadMonitor::instance().removeThisThread();
}
int main(int pArgc, char* pArgv[])
{
...
boost::thread tMyThread(boost::bind(&processThread));
...
ThreadMonitor::instance().getThreadInformation();
}

Member Typedef Documentation

◆ ThreadInfoVector

typedef std::vector<ThreadInfo> ThreadInfoVector

Definition of a vector of thread information.

◆ Type

typedef Base::Type Type
inherited

Constructor & Destructor Documentation

◆ ThreadMonitor()

Default constructor.

◆ ~ThreadMonitor()

virtual ~ThreadMonitor ( )
virtual

The destructor.

Member Function Documentation

◆ addThisThread()

void addThisThread ( const std::string &  pName)

Add the calling thread to the thread monitor.

Parameters
[in]pNameThe name of the thread.

◆ removeThisThread()

void removeThisThread ( )

Remove the calling thread from the monitor.

◆ removeThread() [1/3]

void removeThread ( const boost::thread &  pThread)

Remove a thread from the monitor.

Parameters
[in]pThreadThe thread, which should be removed.

◆ removeThread() [2/3]

void removeThread ( const boost::thread::id &  pThreadID)

Remove a thread from the monitor.

Parameters
[in]pThreadIDThe boost thread ID.

◆ removeThread() [3/3]

void removeThread ( ThreadID  pThreadID)

Remove a thread from the monitor.

Parameters
[in]pThreadIDThe native thread ID.

◆ getThreadInformation()

ThreadInfoVector getThreadInformation ( )

Collect information about all threads of the current process.

Returns
The information vector (
See also
ThreadInfo and
ThreadInfoVector).

◆ instance()

static Type& instance ( )
inlinestaticinherited

Returns a reference to the singleton instance.

Exceptions
XLogicalIf the singleton was already destroyed (dead reference) or not yet created (when using ExplicitInstantiation).

◆ isDestroyed()

static bool isDestroyed ( )
inlinestaticinherited

Returns true, if the singleton was already destroyed.

Trying to access it will result in an exception.

◆ makeInstance()

static Type* makeInstance ( )
inlinestaticprotectedinherited

◆ destroyInstance()

static void destroyInstance ( void  )
inlinestaticprotectedinherited

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