Skip to content

Commit af8044b

Browse files
committed
use YieldProcessor on win32 for both C and C++ for consistency (pr #1215)
1 parent 4734971 commit af8044b

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

include/mimalloc/atomic.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,9 @@ typedef _Atomic(uintptr_t) mi_atomic_guard_t;
358358
// Yield
359359
// ----------------------------------------------------------------------
360360

361-
#if defined(__cplusplus)
362-
#include <thread>
363-
static inline void mi_atomic_yield(void) {
364-
std::this_thread::yield();
365-
}
366-
#elif defined(_WIN32)
361+
#if defined(_WIN32)
367362
static inline void mi_atomic_yield(void) {
368-
YieldProcessor();
363+
YieldProcessor(); // see issue #1215 and #1225 why this is preferred over __yield or SwitchToThread
369364
}
370365
#elif defined(__SSE2__)
371366
#include <emmintrin.h>
@@ -406,7 +401,6 @@ static inline void mi_atomic_yield(void) {
406401
#endif
407402
#endif
408403
#elif defined(__sun)
409-
// Fallback for other archs
410404
#include <synch.h>
411405
static inline void mi_atomic_yield(void) {
412406
smt_pause();
@@ -416,6 +410,12 @@ static inline void mi_atomic_yield(void) {
416410
static inline void mi_atomic_yield(void) {
417411
sched_yield();
418412
}
413+
// Fallback for other archs
414+
#elif defined(__cplusplus)
415+
#include <thread>
416+
static inline void mi_atomic_yield(void) {
417+
std::this_thread::yield();
418+
}
419419
#else
420420
#include <unistd.h>
421421
static inline void mi_atomic_yield(void) {

0 commit comments

Comments
 (0)