Commit 295cdfc8 authored by captainwong's avatar captainwong

Merge branch 'master' of github.com:/captainwong/Global

Because I Can.
parents 7bdb54bc 837f8d03
...@@ -23,24 +23,24 @@ public: ...@@ -23,24 +23,24 @@ public:
typedef std::weak_ptr<observer_type> observer_ptr; typedef std::weak_ptr<observer_type> observer_ptr;
typedef std::lock_guard<std::mutex> lock_guard_type; typedef std::lock_guard<std::mutex> lock_guard_type;
protected: protected:
mutable std::mutex _mutex; mutable std::mutex mutex_;
std::list<observer_ptr> _observers; std::list<observer_ptr> observers_;
public: public:
void register_observer(const observer_ptr& obj) { void register_observer(const observer_ptr& obj) {
lock_guard_type lock(_mutex); lock_guard_type lock(mutex_);
_observers.push_back(obj); observers_.push_back(obj);
} }
void notify_observers(const target& target) { void notify_observers(const target& target) {
lock_guard_type lock(_mutex); lock_guard_type lock(mutex_);
auto iter = _observers.begin(); auto iter = observers_.begin();
while (iter != _observers.end()) { while (iter != observers_.end()) {
std::shared_ptr<observer_type> obj(iter->lock()); std::shared_ptr<observer_type> obj(iter->lock());
if (obj) { if (obj) {
obj->on_update(target); obj->on_update(target);
++iter; ++iter;
} else { } else {
iter = _observers.erase(iter); iter = observers_.erase(iter);
} }
} }
} }
......
...@@ -38,6 +38,10 @@ public: ...@@ -38,6 +38,10 @@ public:
static void release_singleton() { static void release_singleton() {
instance_ = nullptr; instance_ = nullptr;
} }
static bool is_instance_exists() {
return instance_ != nullptr;
}
}; };
......
#pragma once #pragma once
namespace jlib namespace jlib
{ {
inline wchar_t* FormatWSAError(int errornumber) inline const wchar_t* FormatWSAError(int errornumber)
{ {
switch (errornumber) { switch (errornumber) {
case WSANOTINITIALISED: case WSANOTINITIALISED:
......
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