avoid memset
This commit is contained in:
parent
b31bc52618
commit
47300eeda3
@ -140,6 +140,7 @@ mi_stats_t _mi_stats_main = { MI_STATS_NULL };
|
|||||||
Initialization and freeing of the thread local heaps
|
Initialization and freeing of the thread local heaps
|
||||||
----------------------------------------------------------- */
|
----------------------------------------------------------- */
|
||||||
|
|
||||||
|
// note: in x64 in release build `sizeof(mi_thread_data_t)` is under 4KiB (= OS page size).
|
||||||
typedef struct mi_thread_data_s {
|
typedef struct mi_thread_data_s {
|
||||||
mi_heap_t heap; // must come first due to cast in `_mi_heap_done`
|
mi_heap_t heap; // must come first due to cast in `_mi_heap_done`
|
||||||
mi_tld_t tld;
|
mi_tld_t tld;
|
||||||
@ -154,12 +155,13 @@ static bool _mi_heap_init(void) {
|
|||||||
mi_assert_internal(_mi_heap_default->tld->heap_backing == mi_get_default_heap());
|
mi_assert_internal(_mi_heap_default->tld->heap_backing == mi_get_default_heap());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// use `_mi_os_alloc` to allocate directly from the OS
|
// use `_mi_os_alloc` to allocate directly from the OS
|
||||||
mi_thread_data_t* td = (mi_thread_data_t*)_mi_os_alloc(sizeof(mi_thread_data_t),&_mi_stats_main); // Todo: more efficient allocation?
|
mi_thread_data_t* td = (mi_thread_data_t*)_mi_os_alloc(sizeof(mi_thread_data_t),&_mi_stats_main); // Todo: more efficient allocation?
|
||||||
if (td == NULL) {
|
if (td == NULL) {
|
||||||
_mi_error_message(ENOMEM, "failed to allocate thread local heap memory\n");
|
_mi_error_message(ENOMEM, "failed to allocate thread local heap memory\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// OS allocated so already zero initialized
|
||||||
mi_tld_t* tld = &td->tld;
|
mi_tld_t* tld = &td->tld;
|
||||||
mi_heap_t* heap = &td->heap;
|
mi_heap_t* heap = &td->heap;
|
||||||
memcpy(heap, &_mi_heap_empty, sizeof(*heap));
|
memcpy(heap, &_mi_heap_empty, sizeof(*heap));
|
||||||
@ -168,8 +170,7 @@ static bool _mi_heap_init(void) {
|
|||||||
heap->cookie = _mi_heap_random_next(heap) | 1;
|
heap->cookie = _mi_heap_random_next(heap) | 1;
|
||||||
heap->key[0] = _mi_heap_random_next(heap);
|
heap->key[0] = _mi_heap_random_next(heap);
|
||||||
heap->key[1] = _mi_heap_random_next(heap);
|
heap->key[1] = _mi_heap_random_next(heap);
|
||||||
heap->tld = tld;
|
heap->tld = tld;
|
||||||
memset(tld, 0, sizeof(*tld));
|
|
||||||
tld->heap_backing = heap;
|
tld->heap_backing = heap;
|
||||||
tld->segments.stats = &tld->stats;
|
tld->segments.stats = &tld->stats;
|
||||||
tld->segments.os = &tld->os;
|
tld->segments.os = &tld->os;
|
||||||
|
@ -948,6 +948,7 @@ static mi_segment_t* mi_abandoned_pop(void) {
|
|||||||
// Do a pop. We use a reader count to prevent
|
// Do a pop. We use a reader count to prevent
|
||||||
// a segment to be decommitted while a read is still pending,
|
// a segment to be decommitted while a read is still pending,
|
||||||
// and a tagged pointer to prevent A-B-A link corruption.
|
// and a tagged pointer to prevent A-B-A link corruption.
|
||||||
|
// (this is called from `memory.c:_mi_mem_free` for example)
|
||||||
mi_atomic_increment(&abandoned_readers); // ensure no segment gets decommitted
|
mi_atomic_increment(&abandoned_readers); // ensure no segment gets decommitted
|
||||||
mi_tagged_segment_t next = 0;
|
mi_tagged_segment_t next = 0;
|
||||||
do {
|
do {
|
||||||
|
Loading…
Reference in New Issue
Block a user