add initial primitive api for locks
This commit is contained in:
@@ -114,6 +114,24 @@ void _mi_prim_thread_done_auto_done(void);
|
||||
// Called when the default heap for a thread changes
|
||||
void _mi_prim_thread_associate_default_heap(mi_heap_t* heap);
|
||||
|
||||
// Locks are only used if abandoned segment visiting is permitted
|
||||
#if defined(_WIN32)
|
||||
#define mi_lock_t CRITICAL_SECTION
|
||||
#elif defined(MI_USE_PTHREADS)
|
||||
#define mi_lock_t pthread_mutex_t
|
||||
#else
|
||||
#define mi_lock_t _Atomic(uintptr_t)
|
||||
#endif
|
||||
|
||||
// Take a lock (blocking). Return `true` on success.
|
||||
bool _mi_prim_lock(mi_lock_t* lock);
|
||||
|
||||
// Try to take lock and return `true` if successful.
|
||||
bool _mi_prim_try_lock(mi_lock_t* lock);
|
||||
|
||||
// Release a lock.
|
||||
void _mi_prim_unlock(mi_lock_t* lock);
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Thread id: `_mi_prim_thread_id()`
|
||||
@@ -235,10 +253,6 @@ static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
|
||||
// Windows: works on Intel and ARM in both 32- and 64-bit
|
||||
return (uintptr_t)NtCurrentTeb();
|
||||
@@ -370,4 +384,6 @@ static inline mi_heap_t* mi_prim_get_default_heap(void) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // MIMALLOC_PRIM_H
|
||||
|
||||
Reference in New Issue
Block a user