6#include <azure/core/azure_assert.hpp>
14namespace Azure {
namespace Core {
namespace Amqp {
namespace Common {
namespace _detail {
29 Pollable(
const Pollable&) =
delete;
30 Pollable& operator=(
const Pollable&) =
delete;
31 Pollable(Pollable&&) =
delete;
32 Pollable& operator=(Pollable&&) =
delete;
34 virtual void Poll() = 0;
35 virtual ~Pollable() =
default;
37 class GlobalStateHolder final {
41 std::list<std::shared_ptr<Pollable>> m_pollables;
42 std::mutex m_pollablesMutex;
43 std::thread m_pollingThread;
44 std::atomic<bool> m_activelyPolling;
45 bool m_stopped{
false};
48 static GlobalStateHolder* GlobalStateInstance();
50 GlobalStateHolder(GlobalStateHolder
const&) =
delete;
51 GlobalStateHolder& operator=(GlobalStateHolder
const&) =
delete;
53 GlobalStateHolder(GlobalStateHolder&&) =
delete;
54 GlobalStateHolder& operator=(GlobalStateHolder&&) =
delete;
56 void AddPollable(std::shared_ptr<Pollable> pollable);
58 void RemovePollable(std::shared_ptr<Pollable> pollable);
62 std::lock_guard<std::mutex> lock(m_pollablesMutex);
63 AZURE_ASSERT(m_pollables.empty());
64 if (!m_pollables.empty())
66 Azure::Core::_internal::AzureNoReturnPath(
"Global state is not idle.");