X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fthread.h;h=166ea80f65a8af4ec6dca96ada543142873e71c4;hp=606f96262dd72ead3f3672a45c1148f840efcb97;hb=775f8239d3bec75c8deaf951ab24d3a030b671ee;hpb=098f645d26675bcf2180b290be77fe64a63de3ae diff --git a/src/thread.h b/src/thread.h index 606f9626..166ea80f 100644 --- a/src/thread.h +++ b/src/thread.h @@ -20,6 +20,7 @@ #ifndef THREAD_H_INCLUDED #define THREAD_H_INCLUDED +#include #include #include #include @@ -69,6 +70,19 @@ struct SplitPoint { }; +/// Spinlock class wraps low level atomic operations to provide spin lock functionality + +class Spinlock { + + std::atomic_flag lock; + +public: + Spinlock() { std::atomic_flag_clear(&lock); } + void acquire() { while (lock.test_and_set(std::memory_order_acquire)) {} } + void release() { lock.clear(std::memory_order_release); } +}; + + /// ThreadBase struct is the base of the hierarchy from where we derive all the /// specialized thread classes.