2019-06-19 16:26:12 -07:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
Copyright (c) 2018, Microsoft Research, Daan Leijen
|
|
|
|
This is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the MIT license. A copy of the license can be found in the file
|
2019-06-23 19:53:34 +08:00
|
|
|
"LICENSE" at the root of this distribution.
|
2019-06-19 16:26:12 -07:00
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
#pragma once
|
2019-06-26 12:57:13 +08:00
|
|
|
#ifndef MIMALLOC_ATOMIC_H
|
|
|
|
#define MIMALLOC_ATOMIC_H
|
2019-06-19 16:26:12 -07:00
|
|
|
|
|
|
|
// ------------------------------------------------------
|
2020-01-19 18:35:45 -08:00
|
|
|
// Atomics
|
2019-08-25 22:59:12 -07:00
|
|
|
// We need to be portable between C, C++, and MSVC.
|
2019-06-19 16:26:12 -07:00
|
|
|
// ------------------------------------------------------
|
|
|
|
|
2020-07-25 20:55:45 -07:00
|
|
|
#if defined(__cplusplus)
|
2019-08-25 22:59:12 -07:00
|
|
|
#include <atomic>
|
|
|
|
#define _Atomic(tp) std::atomic<tp>
|
2020-07-25 20:55:45 -07:00
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
#define _Atomic(tp) tp
|
|
|
|
#define ATOMIC_VAR_INIT(x) x
|
2019-08-25 22:59:12 -07:00
|
|
|
#else
|
|
|
|
#include <stdatomic.h>
|
|
|
|
#endif
|
2019-06-19 16:26:12 -07:00
|
|
|
|
2019-08-25 22:59:12 -07:00
|
|
|
// ------------------------------------------------------
|
|
|
|
// Atomic operations specialized for mimalloc
|
|
|
|
// ------------------------------------------------------
|
2019-06-19 16:26:12 -07:00
|
|
|
|
2020-07-25 22:52:27 -07:00
|
|
|
// Atomically add a value; returns the previous value. Memory ordering is acquire-release.
|
|
|
|
static inline uintptr_t mi_atomic_add(_Atomic(uintptr_t)* p, uintptr_t add);
|
2019-06-19 16:26:12 -07:00
|
|
|
|
2020-07-25 22:52:27 -07:00
|
|
|
// Atomically "and" a value; returns the previous value. Memory ordering is acquire-release.
|
|
|
|
static inline uintptr_t mi_atomic_and(_Atomic(uintptr_t)* p, uintptr_t x);
|
2019-11-06 21:37:23 -08:00
|
|
|
|
2020-07-25 22:52:27 -07:00
|
|
|
// Atomically "or" a value; returns the previous value. Memory ordering is acquire-release.
|
|
|
|
static inline uintptr_t mi_atomic_or(_Atomic(uintptr_t)* p, uintptr_t x);
|
2019-11-06 21:37:23 -08:00
|
|
|
|
2020-01-19 18:35:45 -08:00
|
|
|
// Atomically compare and exchange a value; returns `true` if successful.
|
2020-07-25 22:52:27 -07:00
|
|
|
// May fail spuriously. Memory ordering is acquire-release; with acquire on failure.
|
|
|
|
static inline bool mi_atomic_cas_weak(_Atomic(uintptr_t)* p, uintptr_t* expected, uintptr_t desired);
|
2019-06-19 16:26:12 -07:00
|
|
|
|
|
|
|
// Atomically compare and exchange a value; returns `true` if successful.
|
2020-07-25 22:52:27 -07:00
|
|
|
// Memory ordering is acquire-release; with acquire on failure.
|
|
|
|
static inline bool mi_atomic_cas_strong(_Atomic(uintptr_t)* p, uintptr_t* expected, uintptr_t desired);
|
2019-06-19 16:26:12 -07:00
|
|
|
|
2019-08-26 08:11:15 -07:00
|
|
|
// Atomically exchange a value. Memory ordering is acquire-release.
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_exchange(_Atomic(uintptr_t)* p, uintptr_t exchange);
|
2019-06-19 16:26:12 -07:00
|
|
|
|
2019-08-26 08:11:15 -07:00
|
|
|
// Atomically read a value. Memory ordering is relaxed.
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_read_relaxed(const _Atomic(uintptr_t)* p);
|
2019-06-19 16:26:12 -07:00
|
|
|
|
2019-08-26 08:11:15 -07:00
|
|
|
// Atomically read a value. Memory ordering is acquire.
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_read(const _Atomic(uintptr_t)* p);
|
2019-07-02 07:23:24 -07:00
|
|
|
|
2019-08-26 08:11:15 -07:00
|
|
|
// Atomically write a value. Memory ordering is release.
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline void mi_atomic_write(_Atomic(uintptr_t)* p, uintptr_t x);
|
2019-07-02 07:23:24 -07:00
|
|
|
|
2019-08-25 22:59:12 -07:00
|
|
|
// Yield
|
|
|
|
static inline void mi_atomic_yield(void);
|
|
|
|
|
2020-07-25 22:52:27 -07:00
|
|
|
// Atomically add a 64-bit value; returns the previous value. Memory ordering is relaxed.
|
2020-07-22 13:45:04 -07:00
|
|
|
// Note: not using _Atomic(int64_t) as it is only used for statistics.
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline int64_t mi_atomic_addi64_relaxed(volatile int64_t* p, int64_t add);
|
2020-07-22 13:45:04 -07:00
|
|
|
|
2020-07-22 14:16:18 -07:00
|
|
|
// Atomically update `*p` with the maximum of `*p` and `x` as a 64-bit value.
|
|
|
|
// Returns the previous value. Note: not using _Atomic(int64_t) as it is only used for statistics.
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline void mi_atomic_maxi64_relaxed(volatile int64_t* p, int64_t x);
|
2020-07-22 13:45:04 -07:00
|
|
|
|
2019-08-25 22:59:12 -07:00
|
|
|
|
|
|
|
// Atomically subtract a value; returns the previous value.
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_sub(_Atomic(uintptr_t)* p, uintptr_t sub) {
|
2020-01-22 19:44:54 -08:00
|
|
|
return mi_atomic_add(p, (uintptr_t)(-((intptr_t)sub)));
|
2019-07-15 17:35:43 -07:00
|
|
|
}
|
|
|
|
|
2019-08-25 22:59:12 -07:00
|
|
|
// Atomically increment a value; returns the incremented result.
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_increment(_Atomic(uintptr_t)* p) {
|
2020-01-22 19:44:54 -08:00
|
|
|
return mi_atomic_add(p, 1);
|
2019-08-25 22:59:12 -07:00
|
|
|
}
|
2019-06-19 16:26:12 -07:00
|
|
|
|
2019-08-25 22:59:12 -07:00
|
|
|
// Atomically decrement a value; returns the decremented result.
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_decrement(_Atomic(uintptr_t)* p) {
|
2020-01-22 19:44:54 -08:00
|
|
|
return mi_atomic_sub(p, 1);
|
2019-08-25 22:59:12 -07:00
|
|
|
}
|
|
|
|
|
2020-01-22 19:44:54 -08:00
|
|
|
// Atomically add a signed value; returns the previous value.
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline intptr_t mi_atomic_addi(_Atomic(intptr_t)* p, intptr_t add) {
|
|
|
|
return (intptr_t)mi_atomic_add((_Atomic(uintptr_t)*)p, (uintptr_t)add);
|
2019-08-25 22:59:12 -07:00
|
|
|
}
|
2019-07-15 17:35:43 -07:00
|
|
|
|
2020-01-22 19:44:54 -08:00
|
|
|
// Atomically subtract a signed value; returns the previous value.
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline intptr_t mi_atomic_subi(_Atomic(intptr_t)* p, intptr_t sub) {
|
2020-01-22 19:44:54 -08:00
|
|
|
return (intptr_t)mi_atomic_addi(p,-sub);
|
2019-08-26 08:11:15 -07:00
|
|
|
}
|
2019-07-15 17:35:43 -07:00
|
|
|
|
2020-01-22 19:44:54 -08:00
|
|
|
// Atomically read a pointer; Memory order is relaxed (i.e. no fence, only atomic).
|
|
|
|
#define mi_atomic_read_ptr_relaxed(T,p) \
|
2020-07-25 22:52:27 -07:00
|
|
|
(T*)(mi_atomic_read_relaxed((const _Atomic(uintptr_t)*)(p)))
|
2020-01-22 19:44:54 -08:00
|
|
|
|
|
|
|
// Atomically read a pointer; Memory order is acquire.
|
|
|
|
#define mi_atomic_read_ptr(T,p) \
|
2020-07-25 22:52:27 -07:00
|
|
|
(T*)(mi_atomic_read((const _Atomic(uintptr_t)*)(p)))
|
2020-01-22 19:44:54 -08:00
|
|
|
|
|
|
|
// Atomically write a pointer; Memory order is acquire.
|
|
|
|
#define mi_atomic_write_ptr(T,p,x) \
|
2020-07-25 22:52:27 -07:00
|
|
|
mi_atomic_write((_Atomic(uintptr_t)*)(p), (uintptr_t)((T*)x))
|
|
|
|
|
|
|
|
|
|
|
|
static inline bool mi_atomic_cas_weak_voidp(_Atomic(void*)*p, void** expected, void* desired, void* unused) {
|
|
|
|
(void)(unused);
|
|
|
|
return mi_atomic_cas_weak((_Atomic(uintptr_t)*)p, (uintptr_t*)expected, (uintptr_t)desired);
|
|
|
|
}
|
2019-08-25 22:59:12 -07:00
|
|
|
|
|
|
|
// Atomically compare and exchange a pointer; returns `true` if successful. May fail spuriously.
|
2020-01-22 19:44:54 -08:00
|
|
|
// Memory order is release. (like a write)
|
2020-07-25 22:52:27 -07:00
|
|
|
#define mi_atomic_cas_ptr_weak(T,p,expected,desired) \
|
|
|
|
mi_atomic_cas_weak_voidp((_Atomic(void*)*)(p), (void**)(expected), desired, *(expected))
|
2020-01-22 19:44:54 -08:00
|
|
|
|
2019-06-19 16:26:12 -07:00
|
|
|
|
|
|
|
// Atomically exchange a pointer value.
|
2020-01-22 19:44:54 -08:00
|
|
|
#define mi_atomic_exchange_ptr(T,p,exchange) \
|
2020-07-25 22:52:27 -07:00
|
|
|
(T*)mi_atomic_exchange((_Atomic(uintptr_t)*)(p), (uintptr_t)((T*)exchange))
|
2019-06-19 16:26:12 -07:00
|
|
|
|
|
|
|
|
2020-07-25 20:55:45 -07:00
|
|
|
#if !defined(__cplusplus) && defined(_MSC_VER)
|
2019-06-19 16:26:12 -07:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <intrin.h>
|
2019-08-25 22:59:12 -07:00
|
|
|
#ifdef _WIN64
|
2019-07-07 21:59:53 -07:00
|
|
|
typedef LONG64 msc_intptr_t;
|
2019-11-06 21:37:23 -08:00
|
|
|
#define MI_64(f) f##64
|
2019-06-19 16:26:12 -07:00
|
|
|
#else
|
2019-07-07 21:59:53 -07:00
|
|
|
typedef LONG msc_intptr_t;
|
2019-11-06 21:37:23 -08:00
|
|
|
#define MI_64(f) f
|
2019-06-19 16:26:12 -07:00
|
|
|
#endif
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_add(_Atomic(uintptr_t)* p, uintptr_t add) {
|
2020-01-22 19:44:54 -08:00
|
|
|
return (uintptr_t)MI_64(_InterlockedExchangeAdd)((volatile msc_intptr_t*)p, (msc_intptr_t)add);
|
2019-11-06 21:37:23 -08:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_and(_Atomic(uintptr_t)* p, uintptr_t x) {
|
2019-11-06 21:37:23 -08:00
|
|
|
return (uintptr_t)MI_64(_InterlockedAnd)((volatile msc_intptr_t*)p, (msc_intptr_t)x);
|
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_or(_Atomic(uintptr_t)* p, uintptr_t x) {
|
2019-11-06 21:37:23 -08:00
|
|
|
return (uintptr_t)MI_64(_InterlockedOr)((volatile msc_intptr_t*)p, (msc_intptr_t)x);
|
2019-06-19 16:26:12 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline bool mi_atomic_cas_strong(_Atomic(uintptr_t)* p, uintptr_t* expected, uintptr_t desired) {
|
|
|
|
uintptr_t read = (uintptr_t)MI_64(_InterlockedCompareExchange)((volatile msc_intptr_t*)p, (msc_intptr_t)desired, (msc_intptr_t)(*expected));
|
|
|
|
if (read == *expected) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*expected = read;
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-19 16:26:12 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline bool mi_atomic_cas_weak(_Atomic(uintptr_t)* p, uintptr_t* expected, uintptr_t desired) {
|
|
|
|
return mi_atomic_cas_strong(p,expected,desired);
|
2019-06-19 16:26:12 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_exchange(_Atomic(uintptr_t)* p, uintptr_t exchange) {
|
2019-11-06 21:37:23 -08:00
|
|
|
return (uintptr_t)MI_64(_InterlockedExchange)((volatile msc_intptr_t*)p, (msc_intptr_t)exchange);
|
2019-06-19 16:26:12 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_read(_Atomic(uintptr_t) const* p) {
|
2019-07-02 07:23:24 -07:00
|
|
|
return *p;
|
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_read_relaxed(_Atomic(uintptr_t) const* p) {
|
2020-01-22 19:44:54 -08:00
|
|
|
return *p;
|
2019-08-26 08:11:15 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline void mi_atomic_write(_Atomic(uintptr_t)* p, uintptr_t x) {
|
2020-01-22 19:44:54 -08:00
|
|
|
#if defined(_M_IX86) || defined(_M_X64)
|
|
|
|
*p = x;
|
|
|
|
#else
|
2019-08-25 22:59:12 -07:00
|
|
|
mi_atomic_exchange(p,x);
|
2020-01-22 19:44:54 -08:00
|
|
|
#endif
|
2019-07-02 07:23:24 -07:00
|
|
|
}
|
2019-06-25 12:16:36 +02:00
|
|
|
static inline void mi_atomic_yield(void) {
|
2019-06-19 16:26:12 -07:00
|
|
|
YieldProcessor();
|
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline int64_t mi_atomic_addi64_relaxed(volatile _Atomic(int64_t)* p, int64_t add) {
|
2019-08-25 22:59:12 -07:00
|
|
|
#ifdef _WIN64
|
2020-07-25 22:52:27 -07:00
|
|
|
return (int64_t)mi_atomic_addi((int64_t*)p,add);
|
2019-06-19 16:26:12 -07:00
|
|
|
#else
|
|
|
|
int64_t current;
|
|
|
|
int64_t sum;
|
|
|
|
do {
|
|
|
|
current = *p;
|
|
|
|
sum = current + add;
|
|
|
|
} while (_InterlockedCompareExchange64(p, sum, current) != current);
|
2020-07-25 22:52:27 -07:00
|
|
|
return current;
|
2019-06-19 16:26:12 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline void mi_atomic_maxi64_relaxed(volatile _Atomic(int64_t)*p, int64_t x) {
|
2020-07-22 13:45:04 -07:00
|
|
|
int64_t current;
|
|
|
|
do {
|
|
|
|
current = *p;
|
|
|
|
} while (current < x && _InterlockedCompareExchange64(p, x, current) != current);
|
|
|
|
}
|
|
|
|
|
2019-06-19 16:26:12 -07:00
|
|
|
#else
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define MI_USING_STD using namespace std;
|
|
|
|
#else
|
|
|
|
#define MI_USING_STD
|
|
|
|
#endif
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_add(_Atomic(uintptr_t)* p, uintptr_t add) {
|
2019-06-19 16:26:12 -07:00
|
|
|
MI_USING_STD
|
2020-07-25 22:52:27 -07:00
|
|
|
return atomic_fetch_add_explicit(p, add, memory_order_acq_rel);
|
2019-06-19 16:26:12 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_and(_Atomic(uintptr_t)* p, uintptr_t x) {
|
2019-11-06 21:37:23 -08:00
|
|
|
MI_USING_STD
|
2020-07-23 15:00:49 -07:00
|
|
|
return atomic_fetch_and_explicit(p, x, memory_order_acq_rel);
|
2019-11-06 21:37:23 -08:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_or(_Atomic(uintptr_t)* p, uintptr_t x) {
|
2019-11-06 21:37:23 -08:00
|
|
|
MI_USING_STD
|
2020-07-23 15:00:49 -07:00
|
|
|
return atomic_fetch_or_explicit(p, x, memory_order_acq_rel);
|
2019-11-06 21:37:23 -08:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline bool mi_atomic_cas_weak(_Atomic(uintptr_t)* p, uintptr_t* expected, uintptr_t desired) {
|
2019-06-19 16:26:12 -07:00
|
|
|
MI_USING_STD
|
2020-07-25 22:52:27 -07:00
|
|
|
return atomic_compare_exchange_weak_explicit(p, expected, desired, memory_order_acq_rel, memory_order_acquire);
|
2019-06-19 16:26:12 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline bool mi_atomic_cas_strong(_Atomic(uintptr_t)* p, uintptr_t* expected, uintptr_t desired) {
|
2019-06-19 16:26:12 -07:00
|
|
|
MI_USING_STD
|
2020-07-25 22:52:27 -07:00
|
|
|
return atomic_compare_exchange_strong_explicit(p, expected, desired, memory_order_acq_rel, memory_order_acquire);
|
2019-06-19 16:26:12 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_exchange(_Atomic(uintptr_t)* p, uintptr_t exchange) {
|
2019-06-19 16:26:12 -07:00
|
|
|
MI_USING_STD
|
2019-08-25 22:59:12 -07:00
|
|
|
return atomic_exchange_explicit(p, exchange, memory_order_acq_rel);
|
2019-06-19 16:26:12 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_read_relaxed(const _Atomic(uintptr_t)* p) {
|
2019-06-19 16:26:12 -07:00
|
|
|
MI_USING_STD
|
2020-07-25 22:52:27 -07:00
|
|
|
return atomic_load_explicit((_Atomic(uintptr_t)*) p, memory_order_relaxed);
|
2019-06-19 16:26:12 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline uintptr_t mi_atomic_read(const _Atomic(uintptr_t)* p) {
|
2019-07-02 07:23:24 -07:00
|
|
|
MI_USING_STD
|
2020-07-25 22:52:27 -07:00
|
|
|
return atomic_load_explicit((_Atomic(uintptr_t)*) p, memory_order_acquire);
|
2019-07-02 07:23:24 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline void mi_atomic_write(_Atomic(uintptr_t)* p, uintptr_t x) {
|
2019-07-02 07:23:24 -07:00
|
|
|
MI_USING_STD
|
2019-08-25 22:59:12 -07:00
|
|
|
return atomic_store_explicit(p, x, memory_order_release);
|
2019-07-02 07:23:24 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline int64_t mi_atomic_addi64_relaxed(volatile int64_t* p, int64_t add) {
|
2020-07-22 14:16:18 -07:00
|
|
|
MI_USING_STD
|
2020-07-25 22:52:27 -07:00
|
|
|
return atomic_fetch_add_explicit((_Atomic(int64_t)*)p, add, memory_order_relaxed);
|
2020-07-22 14:16:18 -07:00
|
|
|
}
|
2020-07-25 22:52:27 -07:00
|
|
|
static inline void mi_atomic_maxi64_relaxed(volatile int64_t* p, int64_t x) {
|
2020-07-22 14:16:18 -07:00
|
|
|
MI_USING_STD
|
2020-07-25 22:52:27 -07:00
|
|
|
int64_t current = atomic_load_explicit((_Atomic(int64_t)*)p, memory_order_relaxed);
|
|
|
|
while (current < x && !atomic_compare_exchange_weak_explicit((_Atomic(int64_t)*)p, ¤t, x, memory_order_acq_rel, memory_order_acquire)) { /* nothing */ };
|
2020-07-22 14:16:18 -07:00
|
|
|
}
|
2019-06-19 16:26:12 -07:00
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#include <thread>
|
2019-06-25 12:16:36 +02:00
|
|
|
static inline void mi_atomic_yield(void) {
|
2019-06-19 16:26:12 -07:00
|
|
|
std::this_thread::yield();
|
|
|
|
}
|
2019-06-23 16:53:00 +08:00
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && \
|
|
|
|
(defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))
|
|
|
|
#if defined(__x86_64__) || defined(__i386__)
|
2019-06-25 12:16:36 +02:00
|
|
|
static inline void mi_atomic_yield(void) {
|
2019-06-19 16:26:12 -07:00
|
|
|
asm volatile ("pause" ::: "memory");
|
|
|
|
}
|
2019-06-23 16:53:00 +08:00
|
|
|
#elif defined(__arm__) || defined(__aarch64__)
|
2019-06-25 12:16:36 +02:00
|
|
|
static inline void mi_atomic_yield(void) {
|
2019-06-23 16:53:00 +08:00
|
|
|
asm volatile("yield");
|
|
|
|
}
|
|
|
|
#endif
|
2019-07-10 20:23:20 +02:00
|
|
|
#elif defined(__wasi__)
|
|
|
|
#include <sched.h>
|
2019-11-13 13:19:21 +08:00
|
|
|
static inline void mi_atomic_yield(void) {
|
2019-07-10 20:23:20 +02:00
|
|
|
sched_yield();
|
|
|
|
}
|
2019-06-19 16:26:12 -07:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
2019-06-25 12:16:36 +02:00
|
|
|
static inline void mi_atomic_yield(void) {
|
2019-06-19 16:26:12 -07:00
|
|
|
sleep(0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // __MIMALLOC_ATOMIC_H
|