diff options
-rw-r--r-- | sal/rtl/source/alloc_arena.c | 11 | ||||
-rw-r--r-- | sal/rtl/source/alloc_cache.c | 28 | ||||
-rw-r--r-- | sal/rtl/source/alloc_global.c | 7 | ||||
-rw-r--r-- | sal/rtl/source/alloc_impl.h | 7 |
4 files changed, 45 insertions, 8 deletions
diff --git a/sal/rtl/source/alloc_arena.c b/sal/rtl/source/alloc_arena.c index b06366427f33..571d6de7d1d0 100644 --- a/sal/rtl/source/alloc_arena.c +++ b/sal/rtl/source/alloc_arena.c @@ -37,6 +37,8 @@ #include <string.h> #include <stdio.h> +extern AllocMode alloc_mode; + /* ================================================================= * * * arena internals. @@ -999,6 +1001,9 @@ SAL_CALL rtl_arena_alloc ( if ((arena != 0) && (pSize != 0)) { + if (alloc_mode == AMode_SYSTEM) + return rtl_allocateMemory(*pSize); + sal_Size size = RTL_MEMORY_ALIGN((*pSize), arena->m_quantum); if (size > arena->m_qcache_max) { @@ -1072,6 +1077,12 @@ SAL_CALL rtl_arena_free ( { if (arena != 0) { + if (alloc_mode == AMode_SYSTEM) + { + rtl_freeMemory(addr); + return; + } + size = RTL_MEMORY_ALIGN(size, arena->m_quantum); if (size > arena->m_qcache_max) { diff --git a/sal/rtl/source/alloc_cache.c b/sal/rtl/source/alloc_cache.c index 91786ade6436..4fa16f4e6039 100644 --- a/sal/rtl/source/alloc_cache.c +++ b/sal/rtl/source/alloc_cache.c @@ -41,6 +41,8 @@ #include <stdio.h> #endif +extern AllocMode alloc_mode; + /* ================================================================= * * * cache internals. @@ -498,6 +500,7 @@ rtl_cache_slab_alloc ( addr = bufctl; /* DEBUG ONLY: mark allocated, undefined */ + /* OSL_DEBUG_ONLY() */ VALGRIND_MAKE_MEM_UNDEFINED(addr, cache->m_type_size); OSL_DEBUG_ONLY(memset(addr, 0x77777777, cache->m_type_size)); VALGRIND_MEMPOOL_ALLOC(cache, addr, cache->m_type_size); } @@ -1203,6 +1206,20 @@ SAL_CALL rtl_cache_alloc ( if (cache == 0) return (0); + if (alloc_mode == AMode_SYSTEM) + { + obj = rtl_allocateMemory(cache->m_type_size); + if ((obj != 0) && (cache->m_constructor != 0)) + { + if (!((cache->m_constructor)(obj, cache->m_userarg))) + { + /* construction failure */ + rtl_freeMemory(obj), obj = 0; + } + } + return obj; + } + RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock)); if (cache->m_cpu_curr != 0) { @@ -1278,6 +1295,17 @@ SAL_CALL rtl_cache_free ( { if ((obj != 0) && (cache != 0)) { + if (alloc_mode == AMode_SYSTEM) + { + if (cache->m_destructor != 0) + { + /* destruct object */ + (cache->m_destructor)(obj, cache->m_userarg); + } + rtl_freeMemory(obj); + return; + } + RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock)); for (;;) diff --git a/sal/rtl/source/alloc_global.c b/sal/rtl/source/alloc_global.c index 9e0ae7d1c49f..e93c666f596e 100644 --- a/sal/rtl/source/alloc_global.c +++ b/sal/rtl/source/alloc_global.c @@ -34,12 +34,9 @@ #include <string.h> #include <stdio.h> -#if !defined(FORCE_SYSALLOC) - -typedef enum { AMode_CUSTOM, AMode_SYSTEM, AMode_UNSET } AllocMode; - -static AllocMode alloc_mode = AMode_UNSET; +AllocMode alloc_mode = AMode_UNSET; +#if !defined(FORCE_SYSALLOC) static void determine_alloc_mode(void) { /* This shouldn't happen, but still ... */ diff --git a/sal/rtl/source/alloc_impl.h b/sal/rtl/source/alloc_impl.h index a226f0607d9c..5e68edb06d7d 100644 --- a/sal/rtl/source/alloc_impl.h +++ b/sal/rtl/source/alloc_impl.h @@ -260,11 +260,12 @@ typedef CRITICAL_SECTION rtl_memory_lock_type; #define VALGRIND_MEMPOOL_FREE(pool, addr) #elif defined(HAVE_MEMCHECK_H) #include <memcheck.h> -#if !defined(FORCE_SYSALLOC) -#define FORCE_SYSALLOC 1 -#endif /* !FORCE_SYSALLOC */ #endif /* NVALGRIND || HAVE_MEMCHECK_H */ +typedef enum { AMode_CUSTOM, AMode_SYSTEM, AMode_UNSET } AllocMode; + +extern AllocMode alloc_mode; + #ifdef __cplusplus } #endif |