lichao
2021-03-29 5657dca25451cfb63a90a3908db0c464fe3f343d
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
/*
 * =====================================================================================
 *
 *       Filename:  pubsub.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年03月24日 18时44分36秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef PUBSUB_4KGRA997
#define PUBSUB_4KGRA997
 
#include "shm_queue.h"
#include <thread>
#include <atomic>
#include <mutex>
#include <vector>
 
namespace bhome_shm {
 
// publish/subcribe manager.
class BusManager
{
    ShmMsgQueue busq_;
    std::atomic<bool> run_;
    std::vector<std::thread> workers_;
    std::mutex mutex_;
 
    bool StopNoLock();
public:
    BusManager(SharedMemory &shm);
    ~BusManager();
    bool Start(const int nworker = 2);
    bool Stop();
};
 
 
} // namespace bhome_shm
 
#endif // end of include guard: PUBSUB_4KGRA997