Skip to content

Commit

Permalink
Explicitly stop IoContext in Controller
Browse files Browse the repository at this point in the history
By stopping the Controllers IoContext in the destructor we make sure that no
scheduled task tries to access a deleted resource from DiscoveryService while
it is being deleted.
  • Loading branch information
fgo-ableton committed Dec 15, 2020
1 parent 322552f commit 17479b4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/ableton/link/Controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ class Controller
Controller& operator=(const Controller&) = delete;
Controller& operator=(Controller&&) = delete;

~Controller()
{
mIo->stop();
}

void enable(const bool bEnable)
{
const bool bWasEnabled = mEnabled.exchange(bEnable);
Expand Down
13 changes: 12 additions & 1 deletion include/ableton/platforms/asio/Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,24 @@ class Context

~Context()
{
if (mpService)
if (mpService && mpWork)
{
mpWork.reset();
mThread.join();
}
}

void stop()
{
if (mpService && mpWork)
{
mpWork.reset();
mpService->stop();
mThread.join();
}
}


template <std::size_t BufferSize>
Socket<BufferSize> openUnicastSocket(const ::asio::ip::address_v4& addr)
{
Expand Down
4 changes: 4 additions & 0 deletions include/ableton/platforms/esp32/Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ class Context
{
}

void stop()
{
}

template <std::size_t BufferSize>
Socket<BufferSize> openUnicastSocket(const ::asio::ip::address_v4& addr)
{
Expand Down
4 changes: 4 additions & 0 deletions include/ableton/test/serial_io/Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class Context
{
}

void stop()
{
}

template <typename Handler>
void async(Handler handler)
{
Expand Down
4 changes: 4 additions & 0 deletions src/ableton/link/tst_Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ struct MockIoContext
}
};

void stop()
{
}

template <std::size_t BufferSize>
Socket<BufferSize> openUnicastSocket(const asio::ip::address_v4&)
{
Expand Down

0 comments on commit 17479b4

Please sign in to comment.