From 4ee08e9533593b0e7cf7f50b3c4c61eb5598c13e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 15 Nov 2016 12:16:26 +0100 Subject: Atomics: Make naming more obvious about which value is being returned --- intern/guardedalloc/intern/mallocn_guarded_impl.c | 12 +++++------ intern/guardedalloc/intern/mallocn_lockfree_impl.c | 24 +++++++++++----------- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'intern/guardedalloc') diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c index 1933e9d3ee3..76b7e072321 100644 --- a/intern/guardedalloc/intern/mallocn_guarded_impl.c +++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c @@ -505,8 +505,8 @@ static void make_memhead_header(MemHead *memh, size_t len, const char *str) memt = (MemTail *)(((char *) memh) + sizeof(MemHead) + len); memt->tag3 = MEMTAG3; - atomic_add_u(&totblock, 1); - atomic_add_z(&mem_in_use, len); + atomic_add_and_fetch_u(&totblock, 1); + atomic_add_and_fetch_z(&mem_in_use, len); mem_lock_thread(); addtail(membase, &memh->next); @@ -638,7 +638,7 @@ void *MEM_guarded_mapallocN(size_t len, const char *str) if (memh != (MemHead *)-1) { make_memhead_header(memh, len, str); memh->mmap = 1; - atomic_add_z(&mmap_in_use, len); + atomic_add_and_fetch_z(&mmap_in_use, len); mem_lock_thread(); peak_mem = mmap_in_use > peak_mem ? mmap_in_use : peak_mem; mem_unlock_thread(); @@ -1007,8 +1007,8 @@ static void rem_memblock(MemHead *memh) } mem_unlock_thread(); - atomic_sub_u(&totblock, 1); - atomic_sub_z(&mem_in_use, memh->len); + atomic_sub_and_fetch_u(&totblock, 1); + atomic_sub_and_fetch_z(&mem_in_use, memh->len); #ifdef DEBUG_MEMDUPLINAME if (memh->need_free_name) @@ -1016,7 +1016,7 @@ static void rem_memblock(MemHead *memh) #endif if (memh->mmap) { - atomic_sub_z(&mmap_in_use, memh->len); + atomic_sub_and_fetch_z(&mmap_in_use, memh->len); #if defined(WIN32) /* our windows mmap implementation is not thread safe */ mem_lock_thread(); diff --git a/intern/guardedalloc/intern/mallocn_lockfree_impl.c b/intern/guardedalloc/intern/mallocn_lockfree_impl.c index a80d67c3e80..ce8a5b29ece 100644 --- a/intern/guardedalloc/intern/mallocn_lockfree_impl.c +++ b/intern/guardedalloc/intern/mallocn_lockfree_impl.c @@ -142,11 +142,11 @@ void MEM_lockfree_freeN(void *vmemh) return; } - atomic_sub_u(&totblock, 1); - atomic_sub_z(&mem_in_use, len); + atomic_sub_and_fetch_u(&totblock, 1); + atomic_sub_and_fetch_z(&mem_in_use, len); if (MEMHEAD_IS_MMAP(memh)) { - atomic_sub_z(&mmap_in_use, len); + atomic_sub_and_fetch_z(&mmap_in_use, len); #if defined(WIN32) /* our windows mmap implementation is not thread safe */ mem_lock_thread(); @@ -287,8 +287,8 @@ void *MEM_lockfree_callocN(size_t len, const char *str) if (LIKELY(memh)) { memh->len = len; - atomic_add_u(&totblock, 1); - atomic_add_z(&mem_in_use, len); + atomic_add_and_fetch_u(&totblock, 1); + atomic_add_and_fetch_z(&mem_in_use, len); update_maximum(&peak_mem, mem_in_use); return PTR_FROM_MEMHEAD(memh); @@ -312,8 +312,8 @@ void *MEM_lockfree_mallocN(size_t len, const char *str) } memh->len = len; - atomic_add_u(&totblock, 1); - atomic_add_z(&mem_in_use, len); + atomic_add_and_fetch_u(&totblock, 1); + atomic_add_and_fetch_z(&mem_in_use, len); update_maximum(&peak_mem, mem_in_use); return PTR_FROM_MEMHEAD(memh); @@ -361,8 +361,8 @@ void *MEM_lockfree_mallocN_aligned(size_t len, size_t alignment, const char *str memh->len = len | (size_t) MEMHEAD_ALIGN_FLAG; memh->alignment = (short) alignment; - atomic_add_u(&totblock, 1); - atomic_add_z(&mem_in_use, len); + atomic_add_and_fetch_u(&totblock, 1); + atomic_add_and_fetch_z(&mem_in_use, len); update_maximum(&peak_mem, mem_in_use); return PTR_FROM_MEMHEAD(memh); @@ -396,9 +396,9 @@ void *MEM_lockfree_mapallocN(size_t len, const char *str) if (memh != (MemHead *)-1) { memh->len = len | (size_t) MEMHEAD_MMAP_FLAG; - atomic_add_u(&totblock, 1); - atomic_add_z(&mem_in_use, len); - atomic_add_z(&mmap_in_use, len); + atomic_add_and_fetch_u(&totblock, 1); + atomic_add_and_fetch_z(&mem_in_use, len); + atomic_add_and_fetch_z(&mmap_in_use, len); update_maximum(&peak_mem, mem_in_use); update_maximum(&peak_mem, mmap_in_use); -- cgit v1.2.3