Kaydet (Commit) e2c60649 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Moved sal/rtl/source/alloc_* files from C to C++, for easier maintenance.

üst 2a6aeea9
......@@ -27,13 +27,31 @@
* instead of those above.
*/
#ifndef INCLUDED_SAL_INTERNAL_RTL_LOCALE_INIT_H
#define INCLUDED_SAL_INTERNAL_RTL_LOCALE_INIT_H
#ifndef INCLUDED_SAL_INTERNAL_RTLLIFECYCLE_H
#define INCLUDED_SAL_INTERNAL_RTLLIFECYCLE_H
#if defined __cplusplus
extern "C" {
#endif
void rtl_arena_init();
void rtl_arena_fini();
void ensureArenaSingleton();
void rtl_cache_init();
void rtl_cache_fini();
void ensureCacheSingleton();
void rtl_memory_init();
void rtl_memory_fini();
void ensureMemorySingleton();
void rtl_locale_init();
void rtl_locale_fini();
......
......@@ -44,7 +44,7 @@
#include <osl/mutex.h>
#include <sal/types.h>
#include "internal/rtl_locale_init.h"
#include "internal/rtllifecycle.h"
//------------------------------------------------------------------------------
// externals
......@@ -56,10 +56,6 @@ extern CRITICAL_SECTION g_ThreadKeyListCS;
extern oslMutex g_Mutex;
extern oslMutex g_CurrentDirectoryMutex;
extern void rtl_memory_fini (void);
extern void rtl_cache_fini (void);
extern void rtl_arena_fini (void);
#ifdef __MINGW32__
typedef void (*func_ptr) (void);
......
......@@ -27,10 +27,11 @@
************************************************************************/
#define _BSD_SOURCE /* sys/mman.h: MAP_ANON */
#include "alloc_arena.h"
#include "alloc_arena.hxx"
#include "alloc_impl.h"
#include "alloc_impl.hxx"
#include "internal/once.h"
#include "internal/rtllifecycle.h"
#include "sal/macros.h"
#include "osl/diagnose.h"
......@@ -54,7 +55,7 @@ struct rtl_arena_list_st
rtl_arena_type m_arena_head;
};
static struct rtl_arena_list_st g_arena_list;
static rtl_arena_list_st g_arena_list;
/** gp_arena_arena
......@@ -89,7 +90,7 @@ SAL_CALL rtl_machdep_free (
);
static sal_Size
rtl_machdep_pagesize (void);
rtl_machdep_pagesize();
/** gp_default_arena
......@@ -142,7 +143,8 @@ rtl_arena_segment_populate (
rtl_arena_segment_type *span;
sal_Size size = rtl_machdep_pagesize();
span = rtl_machdep_alloc(gp_machdep_arena, &size);
span = static_cast< rtl_arena_segment_type * >(
rtl_machdep_alloc(gp_machdep_arena, &size));
if (span != 0)
{
rtl_arena_segment_type *first, *last, *head;
......@@ -473,7 +475,7 @@ rtl_arena_segment_alloc (
if (!RTL_MEMORY_ISP2(size))
{
int msb = highbit(size);
if (RTL_ARENA_FREELIST_SIZE == SAL_INT_CAST(size_t, msb))
if (RTL_ARENA_FREELIST_SIZE == sal::static_int_cast< size_t >(msb))
{
/* highest possible freelist: fall back to first fit */
rtl_arena_segment_type *head, *segment;
......@@ -708,7 +710,7 @@ rtl_arena_destructor (void * obj)
OSL_ASSERT(arena->m_hash_size == RTL_ARENA_HASH_SIZE);
OSL_ASSERT(
arena->m_hash_shift ==
SAL_INT_CAST(unsigned, highbit(arena->m_hash_size) - 1));
sal::static_int_cast< unsigned >(highbit(arena->m_hash_size) - 1));
}
/* ================================================================= */
......@@ -748,7 +750,7 @@ rtl_arena_activate (
if (arena->m_qcache_max > 0)
{
char name[RTL_ARENA_NAME_LENGTH + 1];
char namebuf[RTL_ARENA_NAME_LENGTH + 1];
int i, n = (arena->m_qcache_max >> arena->m_quantum_shift);
sal_Size size = n * sizeof(rtl_cache_type*);
......@@ -761,8 +763,8 @@ rtl_arena_activate (
for (i = 1; i <= n; i++)
{
size = i * arena->m_quantum;
(void) snprintf (name, sizeof(name), "%s_%lu", arena->m_name, size);
arena->m_qcache_ptr[i - 1] = rtl_cache_create(name, size, 0, NULL, NULL, NULL, NULL, arena, RTL_CACHE_FLAG_QUANTUMCACHE);
(void) snprintf (namebuf, sizeof(namebuf), "%s_%lu", arena->m_name, size);
arena->m_qcache_ptr[i - 1] = rtl_cache_create(namebuf, size, 0, NULL, NULL, NULL, NULL, arena, RTL_CACHE_FLAG_QUANTUMCACHE);
}
}
......@@ -909,8 +911,6 @@ rtl_arena_deactivate (
*
* ================================================================= */
extern void ensureArenaSingleton();
/** rtl_arena_create()
*/
rtl_arena_type *
......@@ -921,14 +921,12 @@ SAL_CALL rtl_arena_create (
rtl_arena_type * source_arena,
void * (SAL_CALL * source_alloc)(rtl_arena_type *, sal_Size *),
void (SAL_CALL * source_free) (rtl_arena_type *, void *, sal_Size),
int flags
int
) SAL_THROW_EXTERN_C()
{
rtl_arena_type * result = 0;
sal_Size size = sizeof(rtl_arena_type);
(void) flags; /* unused */
try_alloc:
result = (rtl_arena_type*)rtl_arena_alloc (gp_arena_arena, &size);
if (result != 0)
......@@ -978,7 +976,7 @@ try_alloc:
void
SAL_CALL rtl_arena_destroy (
rtl_arena_type * arena
)
) SAL_THROW_EXTERN_C()
{
if (arena != 0)
{
......@@ -1243,7 +1241,7 @@ SAL_CALL rtl_machdep_free (
/** rtl_machdep_pagesize()
*/
static sal_Size
rtl_machdep_pagesize (void)
rtl_machdep_pagesize()
{
#if defined(SAL_UNX)
#if defined(FREEBSD) || defined(NETBSD) || defined(DRAGONFLY)
......@@ -1265,7 +1263,7 @@ rtl_machdep_pagesize (void)
* ================================================================= */
void
rtl_arena_init (void)
rtl_arena_init()
{
{
/* list of arenas */
......@@ -1333,7 +1331,7 @@ rtl_arena_init (void)
/* ================================================================= */
void
rtl_arena_fini (void)
rtl_arena_fini()
{
if (gp_arena_arena != 0)
{
......
......@@ -26,22 +26,17 @@
*
************************************************************************/
#ifndef INCLUDED_RTL_ALLOC_ARENA_H
#define INCLUDED_RTL_ALLOC_ARENA_H
#ifndef INCLUDED_RTL_ALLOC_ARENA_HXX
#define INCLUDED_RTL_ALLOC_ARENA_HXX
#include "sal/types.h"
#include "rtl/alloc.h"
#include "alloc_impl.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "alloc_impl.hxx"
/** rtl_arena_stat_type
* @internal
*/
typedef struct rtl_arena_stat_st rtl_arena_stat_type;
struct rtl_arena_stat_st
struct rtl_arena_stat_type
{
sal_uInt64 m_alloc;
sal_uInt64 m_free;
......@@ -59,8 +54,7 @@ struct rtl_arena_stat_st
#define RTL_ARENA_SEGMENT_TYPE_FREE ((sal_Size)(0x04))
#define RTL_ARENA_SEGMENT_TYPE_USED ((sal_Size)(0x08))
typedef struct rtl_arena_segment_st rtl_arena_segment_type;
struct rtl_arena_segment_st
struct rtl_arena_segment_type
{
/* segment list linkage */
rtl_arena_segment_type * m_snext;
......@@ -130,11 +124,6 @@ struct rtl_arena_st
*/
extern rtl_arena_type * gp_default_arena;
#ifdef __cplusplus
}
#endif
#endif /* INCLUDED_RTL_ALLOC_ARENA_H */
#endif /* INCLUDED_RTL_ALLOC_ARENA_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -26,10 +26,11 @@
*
************************************************************************/
#include "alloc_cache.h"
#include "alloc_impl.h"
#include "alloc_arena.h"
#include "alloc_cache.hxx"
#include "alloc_impl.hxx"
#include "alloc_arena.hxx"
#include "internal/once.h"
#include "internal/rtllifecycle.h"
#include "sal/macros.h"
#include "osl/diagnose.h"
......@@ -67,7 +68,7 @@ struct rtl_cache_list_st
int m_update_done;
};
static struct rtl_cache_list_st g_cache_list;
static rtl_cache_list_st g_cache_list;
/** gp_cache_arena
......@@ -257,12 +258,10 @@ rtl_cache_hash_remove (
/** rtl_cache_slab_constructor()
*/
static int
rtl_cache_slab_constructor (void * obj, void * arg)
rtl_cache_slab_constructor (void * obj, void *)
{
rtl_cache_slab_type * slab = (rtl_cache_slab_type*)(obj);
(void) arg; /* unused */
QUEUE_START_NAMED(slab, slab_);
slab->m_ntypes = 0;
......@@ -273,7 +272,7 @@ rtl_cache_slab_constructor (void * obj, void * arg)
/** rtl_cache_slab_destructor()
*/
static void
rtl_cache_slab_destructor (void * obj, void * arg)
rtl_cache_slab_destructor (void * obj, void *)
{
#if OSL_DEBUG_LEVEL == 0
(void) obj; /* unused */
......@@ -286,8 +285,6 @@ rtl_cache_slab_destructor (void * obj, void * arg)
/* assure no longer referenced */
OSL_ASSERT(slab->m_ntypes == 0);
#endif /* OSL_DEBUG_LEVEL */
(void) arg; /* unused */
}
......@@ -587,13 +584,11 @@ rtl_cache_slab_free (
/** rtl_cache_magazine_constructor()
*/
static int
rtl_cache_magazine_constructor (void * obj, void * arg)
rtl_cache_magazine_constructor (void * obj, void *)
{
rtl_cache_magazine_type * mag = (rtl_cache_magazine_type*)(obj);
/* @@@ sal_Size size = (sal_Size)(arg); @@@ */
(void) arg; /* unused */
mag->m_mag_next = 0;
mag->m_mag_size = RTL_CACHE_MAGAZINE_SIZE;
mag->m_mag_used = 0;
......@@ -605,7 +600,7 @@ rtl_cache_magazine_constructor (void * obj, void * arg)
/** rtl_cache_magazine_destructor()
*/
static void
rtl_cache_magazine_destructor (void * obj, void * arg)
rtl_cache_magazine_destructor (void * obj, void *)
{
#if OSL_DEBUG_LEVEL == 0
(void) obj; /* unused */
......@@ -618,8 +613,6 @@ rtl_cache_magazine_destructor (void * obj, void * arg)
/* assure no longer referenced */
OSL_ASSERT(mag->m_mag_used == 0);
#endif /* OSL_DEBUG_LEVEL */
(void) arg; /* unused */
}
......@@ -1110,8 +1103,6 @@ rtl_cache_deactivate (
*
* ================================================================= */
extern void ensureCacheSingleton();
/** rtl_cache_create()
*/
rtl_cache_type *
......@@ -1379,7 +1370,7 @@ SAL_CALL rtl_cache_free (
* @precond g_cache_list.m_lock initialized
*/
static void
rtl_cache_wsupdate_init (void);
rtl_cache_wsupdate_init();
/** rtl_cache_wsupdate_wait()
......@@ -1395,7 +1386,7 @@ rtl_cache_wsupdate_wait (
*
*/
static void
rtl_cache_wsupdate_fini (void);
rtl_cache_wsupdate_fini();
/* ================================================================= */
......@@ -1407,7 +1398,7 @@ static void *
rtl_cache_wsupdate_all (void * arg);
static void
rtl_cache_wsupdate_init (void)
rtl_cache_wsupdate_init()
{
RTL_MEMORY_LOCK_ACQUIRE(&(g_cache_list.m_lock));
g_cache_list.m_update_done = 0;
......@@ -1426,8 +1417,8 @@ rtl_cache_wsupdate_wait (unsigned int seconds)
{
if (seconds > 0)
{
struct timeval now;
struct timespec wakeup;
timeval now;
timespec wakeup;
gettimeofday(&now, 0);
wakeup.tv_sec = now.tv_sec + (seconds);
......@@ -1441,7 +1432,7 @@ rtl_cache_wsupdate_wait (unsigned int seconds)
}
static void
rtl_cache_wsupdate_fini (void)
rtl_cache_wsupdate_fini()
{
RTL_MEMORY_LOCK_ACQUIRE(&(g_cache_list.m_lock));
g_cache_list.m_update_done = 1;
......@@ -1460,7 +1451,7 @@ static DWORD WINAPI
rtl_cache_wsupdate_all (void * arg);
static void
rtl_cache_wsupdate_init (void)
rtl_cache_wsupdate_init()
{
DWORD dwThreadId;
......@@ -1485,7 +1476,7 @@ rtl_cache_wsupdate_wait (unsigned int seconds)
}
static void
rtl_cache_wsupdate_fini (void)
rtl_cache_wsupdate_fini()
{
RTL_MEMORY_LOCK_ACQUIRE(&(g_cache_list.m_lock));
g_cache_list.m_update_done = 1;
......@@ -1572,7 +1563,8 @@ static DWORD WINAPI
#endif /* SAL_UNX || SAL_W32 */
rtl_cache_wsupdate_all (void * arg)
{
unsigned int seconds = (unsigned int)SAL_INT_CAST(sal_uIntPtr, arg);
unsigned int seconds = sal::static_int_cast< unsigned int >(
reinterpret_cast< sal_uIntPtr >(arg));
RTL_MEMORY_LOCK_ACQUIRE(&(g_cache_list.m_lock));
while (!g_cache_list.m_update_done)
......@@ -1603,7 +1595,7 @@ rtl_cache_wsupdate_all (void * arg)
* ================================================================= */
void
rtl_cache_init (void)
rtl_cache_init()
{
{
/* list of caches */
......@@ -1705,7 +1697,7 @@ rtl_cache_init (void)
/* ================================================================= */
void
rtl_cache_fini (void)
rtl_cache_fini()
{
if (gp_cache_arena != 0)
{
......
......@@ -26,22 +26,17 @@
*
************************************************************************/
#ifndef INCLUDED_RTL_ALLOC_CACHE_H
#define INCLUDED_RTL_ALLOC_CACHE_H
#ifndef INCLUDED_RTL_ALLOC_CACHE_HXX
#define INCLUDED_RTL_ALLOC_CACHE_HXX
#include "sal/types.h"
#include "rtl/alloc.h"
#include "alloc_impl.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "alloc_impl.hxx"
/** rtl_cache_stat_type
* @internal
*/
typedef struct rtl_cache_stat_st rtl_cache_stat_type;
struct rtl_cache_stat_st
struct rtl_cache_stat_type
{
sal_uInt64 m_alloc;
sal_uInt64 m_free;
......@@ -54,8 +49,7 @@ struct rtl_cache_stat_st
/** rtl_cache_bufctl_type
* @internal
*/
typedef struct rtl_cache_bufctl_st rtl_cache_bufctl_type;
struct rtl_cache_bufctl_st
struct rtl_cache_bufctl_type
{
rtl_cache_bufctl_type * m_next; /* linkage */
......@@ -67,8 +61,7 @@ struct rtl_cache_bufctl_st
/** rtl_cache_slab_type
* @internal
*/
typedef struct rtl_cache_slab_st rtl_cache_slab_type;
struct rtl_cache_slab_st
struct rtl_cache_slab_type
{
rtl_cache_slab_type * m_slab_next; /* slab linkage */
rtl_cache_slab_type * m_slab_prev; /* slab linkage */
......@@ -86,8 +79,7 @@ struct rtl_cache_slab_st
*/
#define RTL_CACHE_MAGAZINE_SIZE 61
typedef struct rtl_cache_magazine_st rtl_cache_magazine_type;
struct rtl_cache_magazine_st
struct rtl_cache_magazine_type
{
rtl_cache_magazine_type * m_mag_next; /* depot linkage */
......@@ -101,8 +93,7 @@ struct rtl_cache_magazine_st
/** rtl_cache_depot_type
* @internal
*/
typedef struct rtl_cache_depot_st rtl_cache_depot_type;
struct rtl_cache_depot_st
struct rtl_cache_depot_type
{
/* magazine list */
rtl_cache_magazine_type * m_mag_next; /* linkage */
......@@ -175,11 +166,6 @@ struct rtl_cache_st
rtl_cache_stat_type m_cpu_stats;
};
#ifdef __cplusplus
}
#endif
#endif /* INCLUDED_RTL_ALLOC_CACHE_H */
#endif /* INCLUDED_RTL_ALLOC_CACHE_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -28,10 +28,8 @@
#include <rtl/instance.hxx>
#include "internal/rtl_locale_init.h"
#include "internal/rtllifecycle.h"
extern "C" void rtl_memory_fini();
extern "C" void rtl_memory_init();
namespace
{
struct rtlMemorySingleton
......@@ -48,13 +46,12 @@ namespace
class theMemorySingleton
: public rtl::Static<rtlMemorySingleton, theMemorySingleton>{};
}
extern "C" void ensureMemorySingleton()
void ensureMemorySingleton()
{
theMemorySingleton::get();
}
extern "C" void rtl_cache_fini();
extern "C" void rtl_cache_init();
namespace
{
struct rtlCacheSingleton
......@@ -71,13 +68,12 @@ namespace
class theCacheSingleton
: public rtl::Static<rtlCacheSingleton, theCacheSingleton>{};
}
extern "C" void ensureCacheSingleton()
void ensureCacheSingleton()
{
theCacheSingleton::get();
}
extern "C" void rtl_arena_fini();
extern "C" void rtl_arena_init();
namespace
{
struct rtlArenaSingleton
......@@ -94,7 +90,8 @@ namespace
class theArenaSingleton
: public rtl::Static<rtlArenaSingleton, theArenaSingleton>{};
}
extern "C" void ensureArenaSingleton()
void ensureArenaSingleton()
{
theArenaSingleton::get();
}
......
......@@ -26,7 +26,7 @@
*
************************************************************************/
#include "alloc_impl.h"
#include "alloc_impl.hxx"
#include "rtl/alloc.h"
#include <sal/macros.h>
#include <osl/diagnose.h>
......@@ -34,10 +34,12 @@
#include <string.h>
#include <stdio.h>
#include "internal/rtllifecycle.h"
AllocMode alloc_mode = AMode_UNSET;
#if !defined(FORCE_SYSALLOC)
static void determine_alloc_mode(void)
static void determine_alloc_mode()
{
OSL_ASSERT(alloc_mode == AMode_UNSET);
alloc_mode = (getenv("G_SLICE") == NULL ? AMode_CUSTOM : AMode_SYSTEM);
......@@ -92,8 +94,6 @@ static rtl_cache_type * g_alloc_table[RTL_MEMORY_CACHED_LIMIT >> RTL_MEMALIGN_SH
static rtl_arena_type * gp_alloc_arena = 0;
extern void ensureMemorySingleton();
/* ================================================================= *
*
* custom allocator implemenation.
......@@ -194,7 +194,7 @@ void * SAL_CALL rtl_reallocateMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXT
*
* ================================================================= */
void rtl_memory_init (void)
void rtl_memory_init()
{
#if !defined(FORCE_SYSALLOC)
{
......@@ -239,7 +239,7 @@ void rtl_memory_init (void)
/* ================================================================= */
void rtl_memory_fini (void)
void rtl_memory_fini()
{
#if !defined(FORCE_SYSALLOC)
int i, n;
......
......@@ -26,16 +26,11 @@
*
************************************************************************/
#ifndef INCLUDED_RTL_ALLOC_IMPL_H
#define INCLUDED_RTL_ALLOC_IMPL_H
#ifndef INCLUDED_RTL_ALLOC_IMPL_HXX
#define INCLUDED_RTL_ALLOC_IMPL_HXX
#include "sal/types.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Alignment macros
*/
#if SAL_TYPES_ALIGNMENT4 > 1
......@@ -275,10 +270,6 @@ typedef enum { AMode_CUSTOM, AMode_SYSTEM, AMode_UNSET } AllocMode;
extern AllocMode alloc_mode;
#ifdef __cplusplus
}
#endif
#endif /* INCLUDED_RTL_ALLOC_IMPL_H */
#endif /* INCLUDED_RTL_ALLOC_IMPL_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -32,7 +32,7 @@
#include "rtl/alloc.h"
#include "internal/once.h"
#include "internal/rtl_locale_init.h"
#include "internal/rtllifecycle.h"
static sal_Int32 RTL_HASHTABLE_SIZE[] =
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment