5 #if HAVE_EXECUTION && HAVE_TBB
10 Cluster::Cluster(Server serv
, size_t cnt
)
17 for (size_t i
= 0; i
< count
; ++i
) {
18 cluster
.push_back(proto
);
27 const vector
<Server
> &Cluster::getServers() const {
31 bool Cluster::start() {
34 for (auto &server
: cluster
) {
35 if (!server
.start()) {
39 pids
[server
.getPid()] = &server
;
45 void Cluster::stop(bool graceful
) {
46 for (auto &server
: cluster
) {
51 // no cookies for memcached; TERM is just too slow
52 server
.signal(SIGKILL
);
57 bool Cluster::isStopped() {
59 #if HAVE_EXECUTION && HAVE_TBB
62 cluster
.begin(), cluster
.end(), [](Server
&s
) {
63 return s
.getPid() && !s
.tryWait();
67 bool Cluster::isListening() const {
69 #if HAVE_EXECUTION && HAVE_TBB
72 cluster
.begin(), cluster
.end(), [](const Server
&s
) {
73 return s
.isListening();
77 bool Cluster::ensureListening() {
81 auto listening
= all_of(
82 #if HAVE_EXECUTION && HAVE_TBB
85 cluster
.begin(), cluster
.end(), [](Server
&s
) {
86 return s
.ensureListening();
90 for (auto &server
: cluster
) {
91 pids
[server
.getPid()] = &server
;
97 void Cluster::wait() {
100 while (!isStopped()) {
101 #if HAVE_WAITID_NOWAIT
102 if (waitid(P_ALL
, 0, &inf
, WEXITED
| WNOWAIT
)) {
103 perror("Cluster::wait waitid()");
107 auto server
= pids
.find(inf
.si_pid
);
108 if (server
!= pids
.end()) {
109 server
->second
->wait();
112 this_thread::sleep_for(100ms
);
117 bool Cluster::restart() {