UniSet  2.24.2
EventLoopServer.h
1 // -------------------------------------------------------------------------
2 #ifndef EventLoopServer_H_
3 #define EventLoopServer_H_
4 // -------------------------------------------------------------------------
5 #include <ev++.h>
6 #include <atomic>
7 #include <thread>
8 #include <future>
9 // -------------------------------------------------------------------------
10 namespace uniset
11 {
18  {
19  public:
20 
22  virtual ~EventLoopServer();
23 
24  bool evIsActive() const noexcept;
25 
26  protected:
27  // действия при завершении
28  // завершение своих ev::xxx.stop()
29  virtual void evfinish() {}
30 
31  // подготовка перед запуском loop
32  // запуску своих ev::xxx.start()
33  virtual void evprepare() {}
34 
35  // Управление потоком событий
36 
40  bool async_evrun( size_t waitRunningTimeout_msec = 60000 );
41 
42  void evstop();
48  bool evrun();
49 
50  ev::dynamic_loop loop;
51 
52  private:
53 
54  void onStop() noexcept;
55  void defaultLoop() noexcept;
56  bool waitDefaultLoopRunning( size_t waitTimeout_msec );
57  void onLoopOK( ev::timer& t, int revents ) noexcept;
58 
59  std::atomic_bool cancelled = { false };
60  std::atomic_bool isactive = { false };
61  std::timed_mutex run_mutex;
62 
63  ev::async evterm;
64  std::unique_ptr<std::thread> thr;
65 
66  std::mutex looprunOK_mutex;
67  std::condition_variable looprunOK_event;
68  std::atomic_bool isrunning = { false };
69  ev::timer evruntimer;
70  };
71  // -------------------------------------------------------------------------
72 } // end of uniset namespace
73 // -------------------------------------------------------------------------
74 #endif // EventLoopServer_H_
75 // -------------------------------------------------------------------------
The EventLoopServer class Реализация общей части всех процессов использующих libev....
Definition: EventLoopServer.h:18
bool evrun()
Definition: EventLoopServer.cc:26
void evstop()
Definition: EventLoopServer.cc:83
bool async_evrun(size_t waitRunningTimeout_msec=60000)
Definition: EventLoopServer.cc:41
Definition: CommonEventLoop.h:15