Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2013-10-20 04:12:54 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2013-10-20 04:12:54 +0400
commit4f6dd555b7254efe9e8aa58481469eca74768c79 (patch)
tree2bda287b269aec5377f322d6d5c4d4e859dfb733 /intern/guardedalloc
parent8f22c120f52fa6c9868eefa6561d06e984a86535 (diff)
Fix for wrong implementation of mmap in lock-free allocator
- Freeing was not using proper block length - Duplicating memory block was not aware of mmaped blocks.
Diffstat (limited to 'intern/guardedalloc')
-rw-r--r--intern/guardedalloc/intern/mallocn_lockfree_impl.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/intern/guardedalloc/intern/mallocn_lockfree_impl.c b/intern/guardedalloc/intern/mallocn_lockfree_impl.c
index 35caebcc5e8..44f51a34134 100644
--- a/intern/guardedalloc/intern/mallocn_lockfree_impl.c
+++ b/intern/guardedalloc/intern/mallocn_lockfree_impl.c
@@ -61,6 +61,7 @@ static void (*thread_unlock_callback)(void) = NULL;
#define MEMHEAD_FROM_PTR(ptr) (((MemHead*) vmemh) - 1)
#define PTR_FROM_MEMHEAD(memhead) (memhead + 1)
+#define MEMHEAD_IS_MMAP(memhead) ((memhead)->len & (size_t) 1)
#ifdef __GNUC__
__attribute__ ((format(printf, 1, 2)))
@@ -112,13 +113,13 @@ void MEM_lockfree_freeN(void *vmemh)
atomic_sub_u(&totblock, 1);
atomic_sub_z(&mem_in_use, len);
- if (memh->len & (size_t) 1) {
+ if (MEMHEAD_IS_MMAP(memh)) {
atomic_sub_z(&mmap_in_use, len);
#if defined(WIN32)
/* our windows mmap implementation is not thread safe */
mem_lock_thread();
#endif
- if (munmap(memh, memh->len + sizeof(MemHead)))
+ if (munmap(memh, len + sizeof(MemHead)))
printf("Couldn't unmap memory\n");
#if defined(WIN32)
mem_unlock_thread();
@@ -136,8 +137,14 @@ void *MEM_lockfree_dupallocN(const void *vmemh)
{
void *newp = NULL;
if (vmemh) {
+ MemHead *memh = MEMHEAD_FROM_PTR(vmemh);
const size_t prev_size = MEM_allocN_len(vmemh);
- newp = MEM_lockfree_mallocN(prev_size, "dupli_malloc");
+ if (MEMHEAD_IS_MMAP(memh)) {
+ newp = MEM_lockfree_mapallocN(prev_size, "dupli_mapalloc");
+ }
+ else {
+ newp = MEM_lockfree_mallocN(prev_size, "dupli_malloc");
+ }
memcpy(newp, vmemh, prev_size);
}
return newp;