mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-19 13:39:31 +03:00
Introduction of mi_mem_clear
This commit is contained in:
parent
fd3ce5dc7d
commit
e398a3d52c
3 changed files with 13 additions and 1 deletions
|
@ -230,6 +230,7 @@ mi_decl_export bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_all_b
|
|||
mi_decl_export bool mi_is_in_heap_region(const void* p) mi_attr_noexcept;
|
||||
mi_decl_export int mi_reserve_huge_os_pages(size_t pages, double max_secs, size_t* pages_reserved) mi_attr_noexcept;
|
||||
mi_decl_export bool mi_is_redirected() mi_attr_noexcept;
|
||||
mi_decl_export void mi_mem_clear(void *p, size_t);
|
||||
|
||||
// ------------------------------------------------------
|
||||
// Convenience
|
||||
|
|
11
src/memory.c
11
src/memory.c
|
@ -130,6 +130,17 @@ bool mi_is_in_heap_region(const void* p) mi_attr_noexcept {
|
|||
return false;
|
||||
}
|
||||
|
||||
// In secure mode, volatile function pointer is used
|
||||
// to discard eventual compiler optimization
|
||||
void mi_mem_clear(void *p, size_t len) {
|
||||
if (MI_SECURE>=1) {
|
||||
void *(*volatile mem_clear)(void *, int, size_t) = memset;
|
||||
(void)mem_clear(p, 0, len);
|
||||
} else {
|
||||
(void)memset(p, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
Commit from a region
|
||||
|
|
|
@ -248,7 +248,7 @@ static void* thread_entry(void* param) {
|
|||
|
||||
static void run_os_threads(size_t nthreads) {
|
||||
pthread_t* threads = (pthread_t*)custom_malloc(nthreads*sizeof(pthread_t));
|
||||
memset(threads, 0, sizeof(pthread_t)*nthreads);
|
||||
mi_mem_clear(threads, sizeof(pthread_t)*nthreads);
|
||||
//pthread_setconcurrency(nthreads);
|
||||
for (uintptr_t i = 0; i < nthreads; i++) {
|
||||
pthread_create(&threads[i], NULL, &thread_entry, (void*)i);
|
||||
|
|
Loading…
Add table
Reference in a new issue