Nektar++
|
#include <Thread.h>
Public Types | |
enum | ThreadManagerName { SessionJob, THREADMANAGER_MAX } |
Public Member Functions | |
ThreadMaster () | |
Constructor. More... | |
~ThreadMaster () | |
Destructor. More... | |
void | SetThreadingType (const std::string &p_type) |
Sets what ThreadManagers will be created in CreateInstance. More... | |
ThreadManagerSharedPtr & | GetInstance (const ThreadManagerName t) |
Gets the ThreadManager associated with string s. More... | |
ThreadManagerSharedPtr | CreateInstance (const ThreadManagerName t, unsigned int nThr) |
Creates an instance of a ThreadManager (which one is determined by a previous call to SetThreadingType) and associates it with the string s. More... | |
Private Attributes | |
std::vector < ThreadManagerSharedPtr > | m_threadManagers |
boost::shared_mutex | m_mutex |
std::string | m_threadingType |
A class to manage multiple ThreadManagers. It also acts as a cut-out during static initialisation, where code attempts to grab a ThreadManager before any can have been initialised. When this happens the ThreadMaster creates a simple implementation of ThreadManager, ThreadStartupManager, which behaves as a single-threaded ThreadManager that fails if anything non-trivial is attempted. This means code should be cautious about caching the value of GetInstance(string), as it might change once that particular threading system is initialised.
Multiple ThreadManagers should now be possible. Each is identified with a string and can be recovered by calling Thread::GetThreadMaster().GetInstance(string).
ThreadMaster is thread-safe apart from CreateInstance. Call CreateInstance in single threaded code only.
Nektar::Thread::ThreadMaster::ThreadMaster | ( | ) |
Constructor.
ThreadMaster implementation
Definition at line 123 of file Thread.cpp.
Nektar::Thread::ThreadMaster::~ThreadMaster | ( | ) |
Destructor.
Will clear the list of ThreadManagers, destructing them.
Definition at line 133 of file Thread.cpp.
References m_threadManagers.
ThreadManagerSharedPtr Nektar::Thread::ThreadMaster::CreateInstance | ( | const ThreadManagerName | t, |
unsigned int | nThr | ||
) |
Creates an instance of a ThreadManager (which one is determined by a previous call to SetThreadingType) and associates it with the string s.
An error occurs if this is called before SetThreadingType.
Definition at line 200 of file Thread.cpp.
References ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, >::CreateInstance(), Nektar::Thread::GetThreadManagerFactory(), m_threadingType, and m_threadManagers.
ThreadManagerSharedPtr & Nektar::Thread::ThreadMaster::GetInstance | ( | const ThreadManagerName | t | ) |
Gets the ThreadManager associated with string s.
Calling code may store the result if it is sure the call to GetInstance(s) has occurred after the call to CreateInstance(s). This cannot be before threadedcommReader::StartThreads(), as that's where SetThreadingType is called.
Definition at line 183 of file Thread.cpp.
References m_threadManagers.
void Nektar::Thread::ThreadMaster::SetThreadingType | ( | const std::string & | p_type | ) |
Sets what ThreadManagers will be created in CreateInstance.
p_type | String to be passed to the ThreadManagerFactory |
Subsequent CreateInstance calls will pass this string to the ThreadManagerFactory to create a ThreadManager.
It is an error to call this more than once (since having different kinds of ThreadManager active is probably a stupendously bad idea).
Definition at line 162 of file Thread.cpp.
References ASSERTL0, and m_threadingType.
|
private |
|
private |
Definition at line 349 of file Thread.h.
Referenced by CreateInstance(), and SetThreadingType().
|
private |
Definition at line 347 of file Thread.h.
Referenced by CreateInstance(), GetInstance(), and ~ThreadMaster().