mirror of
https://github.com/oatpp/oatpp.git
synced 2025-03-19 18:10:23 +08:00
Additional static lock/unlock for SpinLock
This commit is contained in:
parent
c846ed6759
commit
e2f33e906a
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}}
|
||||
|
@ -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);
|
||||
|
||||
};
|
||||
|
||||
}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user