mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-05 06:59:32 +03:00
switch to using C++ atomics in MSVC as well
This commit is contained in:
parent
73c109a04e
commit
e27422adca
2 changed files with 13 additions and 5 deletions
|
@ -13,12 +13,12 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||||
// We need to be portable between C, C++, and MSVC.
|
// We need to be portable between C, C++, and MSVC.
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(__cplusplus)
|
||||||
#define _Atomic(tp) tp
|
|
||||||
#define ATOMIC_VAR_INIT(x) x
|
|
||||||
#elif defined(__cplusplus)
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#define _Atomic(tp) std::atomic<tp>
|
#define _Atomic(tp) std::atomic<tp>
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#define _Atomic(tp) tp
|
||||||
|
#define ATOMIC_VAR_INIT(x) x
|
||||||
#else
|
#else
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -126,7 +126,7 @@ static inline intptr_t mi_atomic_subi(volatile _Atomic(intptr_t)* p, intptr_t su
|
||||||
(T*)mi_atomic_exchange((volatile _Atomic(uintptr_t)*)(p), (uintptr_t)((T*)exchange))
|
(T*)mi_atomic_exchange((volatile _Atomic(uintptr_t)*)(p), (uintptr_t)((T*)exchange))
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#if !defined(__cplusplus) && defined(_MSC_VER)
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
|
|
|
@ -72,6 +72,14 @@ static inline uintptr_t mi_bitmap_mask_(size_t count, size_t bitidx) {
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#define MI_HAVE_BITSCAN
|
#define MI_HAVE_BITSCAN
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
|
#ifndef MI_64
|
||||||
|
#if MI_INTPTR_SIZE==8
|
||||||
|
#define MI_64(f) f##64
|
||||||
|
#else
|
||||||
|
#define MI_64(f) f
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline size_t mi_bsf(uintptr_t x) {
|
static inline size_t mi_bsf(uintptr_t x) {
|
||||||
if (x==0) return 8*MI_INTPTR_SIZE;
|
if (x==0) return 8*MI_INTPTR_SIZE;
|
||||||
DWORD idx;
|
DWORD idx;
|
||||||
|
|
Loading…
Add table
Reference in a new issue