Use size_t instead of unsigned int.
[tairon.git] / src / core / threadmanager.h
blob890177b25687adcb8f6ca7ed6908adf9028c272f
1 /***************************************************************************
2 * *
3 * Copyright (C) 2006 David Brodsky *
4 * *
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. *
9 * *
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. *
14 * *
15 ***************************************************************************/
17 #ifndef _tairon_core_threadmanager_h
18 #define _tairon_core_threadmanager_h
20 #include <map>
21 #include <pthread.h>
23 #include "string.h"
25 namespace Tairon
28 namespace Core
31 class Mutex;
32 class Thread;
34 /** \brief Holds informations about all created threads.
36 * This class is a singleton.
38 class ThreadManager
40 public:
41 /** Initializes the manager.
43 ThreadManager();
45 /** Destroys the manager.
47 ~ThreadManager();
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() {
60 return threadManager;
63 /** Sets main program's thread.
65 void setMainThread(Thread *thread);
67 private:
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);
89 private:
90 /** Main program's thread.
92 Thread *mainThread;
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;
114 friend class Thread;
117 }; // namespace Core
119 }; // namespace Tairon
121 #endif
123 // vim: ai sw=4 ts=4 noet fdm=marker