diff --git a/include/mimalloc-atomic.h b/include/mimalloc-atomic.h index 05a9f01c..55b11f7a 100644 --- a/include/mimalloc-atomic.h +++ b/include/mimalloc-atomic.h @@ -52,9 +52,6 @@ static inline void* mi_atomic_exchange_ptr(volatile void** p, void* exchange) { } - -#define mi_atomic_locked(mutex) for(bool _mheld = mi_mutex_lock(mutex); _mheld; _mheld = mi_mutex_unlock(mutex)) - #ifdef _MSC_VER #define WIN32_LEAN_AND_MEAN #include @@ -176,22 +173,4 @@ static inline uintptr_t mi_atomic_exchange(volatile uintptr_t* p, uintptr_t exch #endif -// Light weight mutex for low contention situations -typedef struct mi_mutex_s { - volatile uint32_t value; -} mi_mutex_t; - -static inline bool mi_mutex_lock(mi_mutex_t* mutex) { - while(!mi_atomic_compare_exchange32(&mutex->value, 1, 0)) { - mi_atomic_yield(); - } - return true; -} - -static inline bool mi_mutex_unlock(mi_mutex_t* mutex) { - mutex->value = 0; - return false; -} - - #endif // __MIMALLOC_ATOMIC_H diff --git a/test/main.c b/test/main.c index 8b2b2cd4..b148f712 100644 --- a/test/main.c +++ b/test/main.c @@ -11,6 +11,17 @@ void test_heap(void* p_out) { //mi_heap_delete(heap); mi_free(p1); mi_free(p2); } +void test_large() { + const size_t N = 1000; + + for (size_t i = 0; i < N; ++i) { + size_t sz = 1ull << 21; + char* a = mi_mallocn_tp(char,sz); + for (size_t k = 0; k < sz; k++) { a[k] = 'x'; } + mi_free(a); + } +} + int main() { void* p1 = mi_malloc(16); void* p2 = mi_malloc(1000000); @@ -27,9 +38,9 @@ int main() { p2 = mi_malloc_aligned(160,24); mi_free(p2); mi_free(p1); - + //test_large(); + mi_collect(true); mi_stats_print(NULL); return 0; } -