mirror of
https://github.com/microsoft/mimalloc.git
synced 2024-12-25 20:14:12 +08:00
remove lock code from atomics (as it is unused)
This commit is contained in:
parent
8e244f6616
commit
a16d95375f
@ -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 <windows.h>
|
||||
@ -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
|
||||
|
15
test/main.c
15
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user