Commit 83e18d59 authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

managerimpl: fix finish method

- thread-safe
- check value during event loop

Refs #64903

Change-Id: I84cb83f3a37fb77e5eff7d21e7f18d67fef7f288
parent aea5c49b
......@@ -165,8 +165,8 @@ ManagerImpl::ManagerImpl() :
toneMutex_(), telephoneTone_(), audiofile_(), audioLayerMutex_(),
waitingCalls_(), waitingCallsMutex_(), path_()
, ringbufferpool_(new RingBufferPool)
, callFactory(), conferenceMap_(), history_(),
finished_(false), accountFactory_(), ice_tf_()
, callFactory(), conferenceMap_(), history_()
, accountFactory_(), ice_tf_()
{
// initialize random generator
// mt19937_64 should be seeded with 2 x 32 bits
......@@ -291,11 +291,10 @@ ManagerImpl::setPath(const std::string &path)
void
ManagerImpl::finish()
{
if (finished_)
bool expected = false;
if (not finished_.compare_exchange_strong(expected, true))
return;
finished_ = true;
try {
// Forbid call creation
callFactory.forbid();
......@@ -326,7 +325,6 @@ ManagerImpl::finish()
RING_ERR("%s", err.what());
}
RING_DBG("Remove any remaning ports mapped to this client for RING");
upnp::Controller().removeMappingsByLocalIPAndDescription();
}
......@@ -1368,13 +1366,13 @@ ManagerImpl::unregisterEventHandler(uintptr_t handlerId)
// Must be invoked periodically by a timer from the main event loop
void ManagerImpl::pollEvents()
{
if (finished_)
return;
// Make a copy of handlers map as handlers can modify this map
const auto handlers = eventHandlerMap_;
for (const auto& it : handlers)
for (const auto& it : handlers) {
if (finished_)
return;
it.second();
}
}
//THREAD=Main
......
......@@ -47,6 +47,7 @@
#include <memory>
#include <mutex>
#include <random>
#include <atomic>
#include "client/client.h"
......@@ -991,7 +992,7 @@ class ManagerImpl {
* TODO: move this to ConfigurationManager
*/
History history_;
bool finished_;
std::atomic_bool finished_ {false};
AccountFactory accountFactory_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment