fix multi singleton
All checks were successful
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 1m29s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Successful in 1m44s
linux-arm-gcc / linux-gcc-armhf (push) Successful in 1m47s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 1m48s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 1m59s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 2m10s
All checks were successful
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 1m29s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Successful in 1m44s
linux-arm-gcc / linux-gcc-armhf (push) Successful in 1m47s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 1m48s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 1m59s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 2m10s
This commit is contained in:
parent
3ead7ff87a
commit
7807eecc08
@ -15,5 +15,6 @@ GetEventRegistryCount()
|
|||||||
{
|
{
|
||||||
return g_event_registry_count.load(std::memory_order_acquire);
|
return g_event_registry_count.load(std::memory_order_acquire);
|
||||||
}
|
}
|
||||||
|
|
||||||
}// namespace internal
|
}// namespace internal
|
||||||
}// namespace sled
|
}// namespace sled
|
||||||
|
@ -19,9 +19,6 @@ using EnableNotVolatile = typename std::enable_if<!std::is_volatile<T>::value>;
|
|||||||
// using RawType = typename std::remove_const<typename std::remove_reference<Event>::type>::type;
|
// using RawType = typename std::remove_const<typename std::remove_reference<Event>::type>::type;
|
||||||
void IncrementEvenetRegistryCount();
|
void IncrementEvenetRegistryCount();
|
||||||
int GetEventRegistryCount();
|
int GetEventRegistryCount();
|
||||||
}// namespace internal
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
template<typename Event>
|
template<typename Event>
|
||||||
class EventRegistry {
|
class EventRegistry {
|
||||||
@ -36,8 +33,8 @@ public:
|
|||||||
|
|
||||||
static EventRegistry &Instance()
|
static EventRegistry &Instance()
|
||||||
{
|
{
|
||||||
static EventRegistry instance_;
|
static EventRegistry registry;
|
||||||
return instance_;
|
return registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::function<void(EventBus *)> &GetCleanupHandler()
|
static std::function<void(EventBus *)> &GetCleanupHandler()
|
||||||
@ -112,7 +109,7 @@ private:
|
|||||||
SubscriberTable signals_;
|
SubscriberTable signals_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}// namespace
|
}// namespace internal
|
||||||
|
|
||||||
class EventBus {
|
class EventBus {
|
||||||
public:
|
public:
|
||||||
@ -138,14 +135,14 @@ public:
|
|||||||
void Post(Event &&event)
|
void Post(Event &&event)
|
||||||
{
|
{
|
||||||
using U = typename internal::RawType<Event>;
|
using U = typename internal::RawType<Event>;
|
||||||
EventRegistry<U>::Instance().Post(this, std::forward<Event>(event));
|
internal::EventRegistry<U>::Instance().Post(this, std::forward<Event>(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Event, typename From>
|
template<typename Event, typename From>
|
||||||
void PostTo(From &&value)
|
void PostTo(From &&value)
|
||||||
{
|
{
|
||||||
using U = typename internal::RawType<Event>;
|
using U = typename internal::RawType<Event>;
|
||||||
EventRegistry<U>::Instance().Post(this, std::forward<From>(value));
|
internal::EventRegistry<U>::Instance().Post(this, std::forward<From>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// On<Event1> ([](const Event1 &){})
|
// On<Event1> ([](const Event1 &){})
|
||||||
@ -158,21 +155,21 @@ public:
|
|||||||
sled::MutexLock lock(&mutex_);
|
sled::MutexLock lock(&mutex_);
|
||||||
auto iter = cleanup_handlers_.find(std::type_index(typeid(U)));
|
auto iter = cleanup_handlers_.find(std::type_index(typeid(U)));
|
||||||
if (iter == cleanup_handlers_.end()) {
|
if (iter == cleanup_handlers_.end()) {
|
||||||
cleanup_handlers_[std::type_index(typeid(U))] = EventRegistry<U>::GetCleanupHandler();
|
cleanup_handlers_[std::type_index(typeid(U))] = internal::EventRegistry<U>::GetCleanupHandler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventRegistry<U>::Instance().Subscribe(this, instance, method);
|
internal::EventRegistry<U>::Instance().Subscribe(this, instance, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Event, typename C>
|
template<typename Event, typename C>
|
||||||
typename std::enable_if<std::is_base_of<sigslot::has_slots_interface, C>::value>::type Unsubscribe(C *instance)
|
typename std::enable_if<std::is_base_of<sigslot::has_slots_interface, C>::value>::type Unsubscribe(C *instance)
|
||||||
{
|
{
|
||||||
using U = typename internal::RawType<Event>;
|
using U = typename internal::RawType<Event>;
|
||||||
EventRegistry<U>::Instance().Unsubscribe(this, instance);
|
internal::EventRegistry<U>::Instance().Unsubscribe(this, instance);
|
||||||
{
|
{
|
||||||
sled::MutexLock lock(&mutex_);
|
sled::MutexLock lock(&mutex_);
|
||||||
if (EventRegistry<U>::Instance().IsEmpty(this)) {
|
if (internal::EventRegistry<U>::Instance().IsEmpty(this)) {
|
||||||
auto iter = cleanup_handlers_.find(std::type_index(typeid(U)));
|
auto iter = cleanup_handlers_.find(std::type_index(typeid(U)));
|
||||||
if (iter != cleanup_handlers_.end()) {
|
if (iter != cleanup_handlers_.end()) {
|
||||||
iter->second(this);
|
iter->second(this);
|
||||||
|
Loading…
Reference in New Issue
Block a user