remove lock code from atomics (as it is unused)

This commit is contained in:
daan 2019-06-24 17:54:41 -07:00
parent 8e244f6616
commit a16d95375f
2 changed files with 13 additions and 23 deletions

View File

@ -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 #ifdef _MSC_VER
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
@ -176,22 +173,4 @@ static inline uintptr_t mi_atomic_exchange(volatile uintptr_t* p, uintptr_t exch
#endif #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 #endif // __MIMALLOC_ATOMIC_H

View File

@ -11,6 +11,17 @@ void test_heap(void* p_out) {
//mi_heap_delete(heap); mi_free(p1); mi_free(p2); //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() { int main() {
void* p1 = mi_malloc(16); void* p1 = mi_malloc(16);
void* p2 = mi_malloc(1000000); void* p2 = mi_malloc(1000000);
@ -27,9 +38,9 @@ int main() {
p2 = mi_malloc_aligned(160,24); p2 = mi_malloc_aligned(160,24);
mi_free(p2); mi_free(p2);
mi_free(p1); mi_free(p1);
//test_large();
mi_collect(true); mi_collect(true);
mi_stats_print(NULL); mi_stats_print(NULL);
return 0; return 0;
} }