1 /***************************************************************************
3 * Copyright (C) 2006 David Brodsky *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Library General Public *
7 * License as published by the Free Software Foundation and appearing *
8 * in the file LICENSE.LGPL included in the packaging of this file. *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * Library General Public License for more details. *
15 ***************************************************************************/
17 #ifndef _tairon_core_threadmanager_h
18 #define _tairon_core_threadmanager_h
34 /** \brief Holds informations about all created threads.
36 * This class is a singleton.
41 /** Initializes the manager.
45 /** Destroys the manager.
49 /** Returns the thread object identified by its ID.
51 Thread
*getThreadByID(pthread_t id
);
53 /** Returns the thread object identified by its name.
55 Thread
*getThreadByName(const String
&name
);
57 /** Returns pointer to the instance of this class.
59 static ThreadManager
*self() {
63 /** Sets main program's thread.
65 void setMainThread(Thread
*thread
);
68 /** Registers a new thread.
70 * \param name Name of the new thread.
71 * \param thread Thread object to register.
73 void registerThread(const String
&name
, Thread
*thread
);
75 /** Registers an ID of a thread.
77 void registerThreadID(pthread_t id
, Thread
*thread
);
79 /** Unregisters a thread.
81 * \param name Name of the thread to unregister.
83 void unregisterThread(const String
&name
);
85 /** Unregisters an ID.
87 void unregisterThreadID(pthread_t id
);
90 /** Main program's thread.
94 /** Mapping from an ID to the thread.
96 std::map
<pthread_t
, Thread
*> threadIDs
;
98 /** Mutex protecting access to the threadIDs.
100 Mutex
*threadIDsMutex
;
102 /** Holds pointer to the instance of this class.
104 static ThreadManager
*threadManager
;
106 /** Mapping from a name to the thread.
108 std::map
<String
, Thread
*> threadNames
;
110 /** Mutex protecting access to the threadNames.
112 Mutex
*threadNamesMutex
;
119 }; // namespace Tairon
123 // vim: ai sw=4 ts=4 noet fdm=marker