| … | … | @@ -388,22 +388,18 @@ void CogChannel<Client, Data>::reply_handler(const Msg& msg) |
| 388 | 388 | template<typename Client, typename Data> |
| 389 | 389 | void CogChannel<Client, Data>::barrier() |
| 390 | 390 | { |
| 391 | | // Drain work queues. |
| 392 | | _msg_buffer.barrier(); |
| 393 | | |
| 394 | | // Server can complete barrier only after it receives it on |
| 395 | | // all of the open sockets; the random string is the uuid to |
| 396 | | // disambiguate this barrier from any others that might get |
| 397 | | // issued. The barrier is retired after all N of them are received. |
| 391 | // Generate a unique barrier ID |
| 398 | 392 | static thread_local std::minstd_rand rng(std::random_device{}()); |
| 399 | 393 | uint64_t rnd = (uint64_t(rng()) << 32) | rng(); |
| 400 | 394 | |
| 401 | | std::lock_guard<std::mutex> lck(_sock_set_mtx); |
| 395 | // Build the barrier message. Each worker thread will send this, |
| 396 | // opening its socket if needed. Server completes when all N arrive. |
| 402 | 397 | char msg[64]; |
| 403 | | snprintf(msg, sizeof(msg), "(cog-barrier %zu \"%016lx\")\n", |
| 404 | | _open_socks.size(), rnd); |
| 405 | | for (int sockfd : _open_socks) |
| 406 | | send(sockfd, msg, strlen(msg), MSG_NOSIGNAL); |
| 398 | snprintf(msg, sizeof(msg), "(cog-barrier %u \"%016lx\")\n", NTHREADS, rnd); |
| 399 | |
| 400 | Data dummy = Data(); |
| 401 | Msg block{nullptr, nullptr, true, msg, dummy}; |
| 402 | _msg_buffer.barrier(block); |
| 407 | 403 | } |
| 408 | 404 | |
| 409 | 405 | template<typename Client, typename Data> |