add original source
This commit is contained in:
18
source/listing_7.1.cpp
Normal file
18
source/listing_7.1.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <atomic>
|
||||
|
||||
class spinlock_mutex
|
||||
{
|
||||
std::atomic_flag flag;
|
||||
public:
|
||||
spinlock_mutex():
|
||||
flag(ATOMIC_FLAG_INIT)
|
||||
{}
|
||||
void lock()
|
||||
{
|
||||
while(flag.test_and_set(std::memory_order_acquire));
|
||||
}
|
||||
void unlock()
|
||||
{
|
||||
flag.clear(std::memory_order_release);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user