Additional static lock/unlock for SpinLock

This commit is contained in:
lganzzzo 2018-09-12 23:37:49 +03:00
parent c846ed6759
commit e2f33e906a
3 changed files with 22 additions and 4 deletions

View File

@ -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);

View File

@ -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);
}
}}

View File

@ -34,10 +34,15 @@ class SpinLock {
public:
typedef std::atomic<bool> Atom;
private:
Atom& m_atom;
Atom* m_atom;
public:
SpinLock(Atom& atom);
~SpinLock();
static void lock(Atom& atom);
static void unlock(Atom& atom);
};
}}