diff --git a/core/base/Environment.cpp b/core/base/Environment.cpp index 0f544855..5a20229c 100644 --- a/core/base/Environment.cpp +++ b/core/base/Environment.cpp @@ -143,6 +143,9 @@ void Environment::log(v_int32 priority, const std::string& tag, const std::strin } void Environment::logFormatted(v_int32 priority, const std::string& tag, const char* message, ...) { + if(message == nullptr) { + message = "[null]"; + } char buffer[4097]; va_list args; va_start (args, message); diff --git a/core/concurrency/SpinLock.cpp b/core/concurrency/SpinLock.cpp index 398e0ac3..e4d0f9d6 100644 --- a/core/concurrency/SpinLock.cpp +++ b/core/concurrency/SpinLock.cpp @@ -30,15 +30,25 @@ namespace oatpp { namespace concurrency { SpinLock::SpinLock(Atom& atom) - : m_atom(atom) + : m_atom(&atom) { - while (std::atomic_exchange_explicit(&m_atom, true, std::memory_order_acquire)) { + while (std::atomic_exchange_explicit(m_atom, true, std::memory_order_acquire)) { std::this_thread::yield(); } } SpinLock::~SpinLock(){ - std::atomic_store_explicit(&m_atom, false, std::memory_order_release); + std::atomic_store_explicit(m_atom, false, std::memory_order_release); +} + +void SpinLock::lock(Atom& atom) { + while (std::atomic_exchange_explicit(&atom, true, std::memory_order_acquire)) { + std::this_thread::yield(); + } +} + +void SpinLock::unlock(Atom& atom) { + std::atomic_store_explicit(&atom, false, std::memory_order_release); } }} diff --git a/core/concurrency/SpinLock.hpp b/core/concurrency/SpinLock.hpp index 5f10b59a..4dc04db0 100644 --- a/core/concurrency/SpinLock.hpp +++ b/core/concurrency/SpinLock.hpp @@ -34,10 +34,15 @@ class SpinLock { public: typedef std::atomic Atom; private: - Atom& m_atom; + Atom* m_atom; public: + SpinLock(Atom& atom); ~SpinLock(); + + static void lock(Atom& atom); + static void unlock(Atom& atom); + }; }}