-
Notifications
You must be signed in to change notification settings - Fork 242
/
info_router.h
40 lines (33 loc) · 1.03 KB
/
info_router.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
#ifndef TEST_RPC_CINFOROUTER_HEADER
#define TEST_RPC_CINFOROUTER_HEADER
#include <mutex>
#include <atomic>
#include <memory>
#include <string>
#include <vector>
#include "common_struct.h"
#include "common/structure/thread_safe_block_queue.h"
struct FuncCallInfo;
class FuncThread;
class InfoRouter {
public:
InfoRouter();
~InfoRouter();
//add a funcmanager thread.
void AddThread(std::shared_ptr<FuncThread>& thread);
void StopAllThread();
//push call info
void PushTask(FuncCallInfo* info);
//push call function return value
void PushRet(FuncCallInfo* info);
//may block the thread
FuncCallInfo* GetRet();
void RegisterFunc(const std::string& name, const CommonFunc& func);
void RemoveFunc(const std::string& name);
private:
cppnet::ThreadSafeBlockQueue<FuncCallInfo*> _out_task_list;
std::atomic_int _curent_index;
std::mutex _mutex;
std::vector<std::shared_ptr<FuncThread>> _func_thread_vec;
};
#endif