Fixed spinlock for windows

This commit is contained in:
WolverinDEV 2019-07-05 23:28:24 +02:00
parent 107d752cb8
commit 48b4bace5d
1 changed files with 6 additions and 1 deletions

View File

@ -9,7 +9,12 @@ class spin_lock {
inline void lock() {
uint8_t round = 0;
while (locked.test_and_set(std::memory_order_acquire)) {
while(locked._M_i) { /* waiting 'till its zero so we can try an exchanged again; Atomic exchanges have a huge bug overhead to deal with! */
/* waiting 'till its zero so we can try an exchanged again; Atomic exchanges have a huge bug overhead to deal with! */
#ifdef WIN32
while(locked._My_flag > 0) {
#else
while(locked._M_i) {
#endif
//Yield when we're using this lock for a longer time, which we usually not doing
if(round++ % 8 == 0)
std::this_thread::yield();