-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThreadManager.h
71 lines (52 loc) · 1.77 KB
/
ThreadManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/***************************************************************************
ThreadManager.h - description
-------------------
begin : Sun Mar 13 2011
copyright : (C) 2010 by Knut-Helge Vik
email : knuthelge@vik.gs
***************************************************************************/
#pragma once
#include"BaseLib/CommonDefines.h"
#include"BaseLib/Singleton.h"
#include"BaseLib/Thread.h"
#include"BaseLib/MutexBare.h"
#include"BaseLib/MutexLocker.h"
#include"BaseLib/ObjectBase.h"
#include"BaseLib/Export.h"
namespace BaseLib
{
class DLL_STATE ThreadManager : public Thread
{
typedef MutexTypeLocker<MutexBare> Locker;
private:
ThreadManager(std::string name = std::string("BaseLib.Manager.Thread"));
public:
virtual ~ThreadManager();
friend class Singleton<ThreadManager>;
public:
CLASS_TRAITS(ThreadManager)
typedef int64 ThreadId;
typedef std::map<ThreadId, Thread*> MapIdThread; // threads that implement Thread
typedef std::map<ThreadId, std::string> MapIdThreadName;// threads that does not implement any object
public:
static ThreadManager& GetInstance();
public:
bool AddThread(Thread*);
bool AddThread(Thread*, ThreadId id);
bool AddThread(ThreadId id, std::string name);
bool RemoveThread(Thread*);
// TODO: Dangerous?
//bool StopThread(ThreadId id);
//bool RestartThread()
Thread* GetThread(ThreadId id);
protected:
virtual void run();
private:
static Singleton<ThreadManager> threadManager_;
private:
MapIdThread mapIdThread_;
MapIdThreadName mapIdThreadName_;
mutable MutexBare managerMutex_;
ThreadId threadIdAssigner_;
};
}