Fix a bug where the MachineManager's destructor became incorrect after being moved

This commit is contained in:
Tyler Neely 2022-11-02 17:45:27 +00:00
parent a815ec9617
commit fa1ddfea12
3 changed files with 7 additions and 5 deletions

View File

@ -88,6 +88,7 @@ class Queue {
public:
void Push(Message &&message) {
{
MG_ASSERT(inner_.use_count() > 0);
std::unique_lock<std::mutex> lock(inner_->mu);
inner_->queue.emplace_back(std::forward<Message>(message));
@ -132,7 +133,7 @@ class CoordinatorWorker {
public:
CoordinatorWorker(io::Io<IoImpl> io, Queue queue, Coordinator coordinator)
: io_(io), queue_(queue), coordinator_{std::move(io.ForkLocal()), {}, std::move(coordinator)} {}
: io_(io), queue_(std::move(queue)), coordinator_{std::move(io.ForkLocal()), {}, std::move(coordinator)} {}
CoordinatorWorker(CoordinatorWorker &&) = default;
CoordinatorWorker &operator=(CoordinatorWorker &&) = default;

View File

@ -92,10 +92,10 @@ class MachineManager {
MachineManager &operator=(const MachineManager &) = delete;
~MachineManager() {
coordinator_queue_.Push(coordinator::coordinator_worker::ShutDown{});
spdlog::error("a");
std::move(coordinator_handle_).join();
spdlog::error("b");
if (coordinator_handle_.joinable()) {
coordinator_queue_.Push(coordinator::coordinator_worker::ShutDown{});
std::move(coordinator_handle_).join();
}
}
Address CoordinatorAddress() { return coordinator_address_; }

View File

@ -92,6 +92,7 @@ class Queue {
public:
void Push(Message &&message) {
{
MG_ASSERT(inner_.use_count() > 0);
std::unique_lock<std::mutex> lock(inner_->mu);
inner_->queue.emplace_back(std::forward<Message>(message));