Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::base::ThreadSpawner Class Reference

A ThreadSpawner instance launches a new thread in its constructor and waits for the thread to finish in its destructor. More...

#include "threadspawner.h"

Public Member Functions

 ThreadSpawner (const std::string &name, port::ThreadFuncPtr func_ptr)
 Creates a ThreadSpawner instance that runs the given function. More...
 
 ThreadSpawner (const std::string &name, const port::ThreadStdFunc &func)
 
 ~ThreadSpawner ()
 The destructor calls Join() to wait for the thread to finish. More...
 
void Join ()
 Waits for the thread to finish. More...
 
const std::string & GetName () const
 Returns the name of the thread supplied to the constructor. More...
 
port::ThreadId GetId () const
 Returns the ThreadId for the thread. More...
 

Detailed Description

A ThreadSpawner instance launches a new thread in its constructor and waits for the thread to finish in its destructor.

Definition at line 30 of file threadspawner.h.

Constructor & Destructor Documentation

ion::base::ThreadSpawner::ThreadSpawner ( const std::string &  name,
port::ThreadFuncPtr  func_ptr 
)

Creates a ThreadSpawner instance that runs the given function.

The thread is given the specified name if thread naming is supported.

Definition at line 37 of file threadspawner.cc.

ion::base::ThreadSpawner::ThreadSpawner ( const std::string &  name,
const port::ThreadStdFunc func 
)

Definition at line 46 of file threadspawner.cc.

ion::base::ThreadSpawner::~ThreadSpawner ( )

The destructor calls Join() to wait for the thread to finish.

Definition at line 53 of file threadspawner.cc.

References Join().

Member Function Documentation

port::ThreadId ion::base::ThreadSpawner::GetId ( ) const
inline

Returns the ThreadId for the thread.

This will be port::kInvalidThreadId if the thread has not yet spawned, if there was an error spawning the thread, or if Join() has already completed.

Definition at line 50 of file threadspawner.h.

const std::string& ion::base::ThreadSpawner::GetName ( ) const
inline

Returns the name of the thread supplied to the constructor.

Definition at line 45 of file threadspawner.h.

void ion::base::ThreadSpawner::Join ( )

Waits for the thread to finish.

This is called automatically by the destructor.

Definition at line 57 of file threadspawner.cc.

References ion::port::JoinThread().

Referenced by ~ThreadSpawner().


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