void server_stats_obtain(struct worker* worker, struct worker* who, struct stats_info* s, int reset) { uint8_t *reply = NULL; uint32_t len = 0; if(worker == who) { /* just fill it in */ server_stats_compile(worker, s, reset); return; } /* communicate over tube */ verbose(VERB_ALGO, "write stats cmd"); if(reset) worker_send_cmd(who, worker_cmd_stats); else worker_send_cmd(who, worker_cmd_stats_noreset); verbose(VERB_ALGO, "wait for stats reply"); if(!tube_read_msg(worker->cmd, &reply, &len, 0)) fatal_exit("failed to read stats over cmd channel"); if(len != (uint32_t)sizeof(*s)) fatal_exit("stats on cmd channel wrong length %d %d", (int)len, (int)sizeof(*s)); memcpy(s, reply, (size_t)len); free(reply); }
/** * Stop the other threads. * @param daemon: the daemon with other threads. */ static void daemon_stop_others(struct daemon* daemon) { int i; log_assert(daemon); verbose(VERB_ALGO, "stop threads"); /* skip i=0, is this thread */ /* use i=0 buffer for sending cmds; because we are #0 */ for(i=1; i<daemon->num; i++) { worker_send_cmd(daemon->workers[i], worker_cmd_quit); } /* wait for them to quit */ for(i=1; i<daemon->num; i++) { /* join it to make sure its dead */ verbose(VERB_ALGO, "join %d", i); ub_thread_join(daemon->workers[i]->thr_id); verbose(VERB_ALGO, "join success %d", i); } }