mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-06 06:30:46 +00:00
tweak for typed memory use
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27658 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9b2f7473bd
commit
31ee1b7fed
2 changed files with 64 additions and 8 deletions
|
@ -3,6 +3,8 @@
|
||||||
* Headers/Additions/GNUstepBase/GNUstep.h:
|
* Headers/Additions/GNUstepBase/GNUstep.h:
|
||||||
Optimise retain/release management macros for the case where they
|
Optimise retain/release management macros for the case where they
|
||||||
are dealing with none-nil values.
|
are dealing with none-nil values.
|
||||||
|
* Headers/Additions/GNUstepBase/GSIMap.h:
|
||||||
|
Some changes moving towards use of typed memory for gc.
|
||||||
|
|
||||||
2009-01-22 Richard Frith-Macdonald <rfm@gnu.org>
|
2009-01-22 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#if OS_API_VERSION(GS_API_NONE,GS_API_LATEST)
|
#if OS_API_VERSION(GS_API_NONE,GS_API_LATEST)
|
||||||
|
|
||||||
#include <Foundation/NSObject.h>
|
#include <Foundation/NSObject.h>
|
||||||
|
#include <Foundation/NSGarbageCollector.h>
|
||||||
#include <Foundation/NSZone.h>
|
#include <Foundation/NSZone.h>
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
@ -198,6 +199,17 @@ extern "C" {
|
||||||
#define GSI_MAP_CLEAR_VAL(node)
|
#define GSI_MAP_CLEAR_VAL(node)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Define fake zones to be used for our nodes when GC is in use.
|
||||||
|
*/
|
||||||
|
#define GSIMapStrongKeyAndVal ((NSZone*)0)
|
||||||
|
#define GSIMapWeakKey ((NSZone*)1)
|
||||||
|
#define GSIMapWeakVal ((NSZone*)2)
|
||||||
|
#define GSIMapWeakKeyAndVal ((NSZone*)3)
|
||||||
|
|
||||||
|
static BOOL _GSIMapSetup = NO;
|
||||||
|
static NSGarbageCollector *_GSIMapGC = nil;
|
||||||
|
static NSZone *_GSIMapUnscannedZone = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Description of the datastructure
|
* Description of the datastructure
|
||||||
* --------------------------------
|
* --------------------------------
|
||||||
|
@ -417,19 +429,19 @@ GSIMapMoreNodes(GSIMapTable map, unsigned required)
|
||||||
GSIMapNode *newArray;
|
GSIMapNode *newArray;
|
||||||
size_t arraySize = (map->chunkCount+1)*sizeof(GSIMapNode);
|
size_t arraySize = (map->chunkCount+1)*sizeof(GSIMapNode);
|
||||||
|
|
||||||
#if GS_WITH_GC == 1
|
|
||||||
/*
|
/*
|
||||||
* Our nodes may be allocated from the atomic zone - but we don't want
|
* Our nodes may be allocated from the atomic zone - but we don't want
|
||||||
* them freed - so we must keep the array of pointers to memory chunks in
|
* them freed - so we must keep the array of pointers to memory chunks in
|
||||||
* scanned memory.
|
* scanned memory.
|
||||||
*/
|
*/
|
||||||
if (map->zone == GSAtomicMallocZone())
|
if (_GSIMapGC != nil)
|
||||||
{
|
{
|
||||||
newArray = (GSIMapNode*)NSAllocateCollectable(arraySize, NSScannedOption);
|
newArray = (GSIMapNode*)NSAllocateCollectable(arraySize, NSScannedOption);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
{
|
||||||
newArray = (GSIMapNode*)NSZoneMalloc(map->zone, arraySize);
|
newArray = (GSIMapNode*)NSZoneMalloc(map->zone, arraySize);
|
||||||
|
}
|
||||||
if (newArray)
|
if (newArray)
|
||||||
{
|
{
|
||||||
GSIMapNode newNodes;
|
GSIMapNode newNodes;
|
||||||
|
@ -460,7 +472,16 @@ GSIMapMoreNodes(GSIMapTable map, unsigned required)
|
||||||
chunkCount = required;
|
chunkCount = required;
|
||||||
}
|
}
|
||||||
chunkSize = chunkCount * sizeof(GSIMapNode_t);
|
chunkSize = chunkCount * sizeof(GSIMapNode_t);
|
||||||
|
if (_GSIMapGC != nil)
|
||||||
|
{
|
||||||
|
// FIXME ... use typed memory for weak pointers.
|
||||||
|
newArray
|
||||||
|
= (GSIMapNode*)NSAllocateCollectable(chunkSize, NSScannedOption);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
newNodes = (GSIMapNode)NSZoneMalloc(map->zone, chunkSize);
|
newNodes = (GSIMapNode)NSZoneMalloc(map->zone, chunkSize);
|
||||||
|
}
|
||||||
if (newNodes)
|
if (newNodes)
|
||||||
{
|
{
|
||||||
map->nodeChunks[map->chunkCount++] = newNodes;
|
map->nodeChunks[map->chunkCount++] = newNodes;
|
||||||
|
@ -617,8 +638,21 @@ GSIMapResize(GSIMapTable map, size_t new_capacity)
|
||||||
/*
|
/*
|
||||||
* Make a new set of buckets for this map
|
* Make a new set of buckets for this map
|
||||||
*/
|
*/
|
||||||
|
if (_GSIMapGC == nil)
|
||||||
|
{
|
||||||
|
/* Use the zone specified for this map.
|
||||||
|
*/
|
||||||
new_buckets = (GSIMapBucket)NSZoneCalloc(map->zone, size,
|
new_buckets = (GSIMapBucket)NSZoneCalloc(map->zone, size,
|
||||||
sizeof(GSIMapBucket_t));
|
sizeof(GSIMapBucket_t));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Use the atomic zone since everything we point to is actively
|
||||||
|
* referenced from the nodeChunks array.
|
||||||
|
*/
|
||||||
|
new_buckets = (GSIMapBucket)NSZoneCalloc(_GSIMapUnscannedZone, size,
|
||||||
|
sizeof(GSIMapBucket_t));
|
||||||
|
}
|
||||||
if (new_buckets != 0)
|
if (new_buckets != 0)
|
||||||
{
|
{
|
||||||
GSIMapRemangleBuckets(map, map->buckets, map->bucketCount, new_buckets,
|
GSIMapRemangleBuckets(map, map->buckets, map->bucketCount, new_buckets,
|
||||||
|
@ -917,7 +951,27 @@ GSIMapEmptyMap(GSIMapTable map)
|
||||||
static INLINE void
|
static INLINE void
|
||||||
GSIMapInitWithZoneAndCapacity(GSIMapTable map, NSZone *zone, size_t capacity)
|
GSIMapInitWithZoneAndCapacity(GSIMapTable map, NSZone *zone, size_t capacity)
|
||||||
{
|
{
|
||||||
|
if (_GSIMapSetup == NO)
|
||||||
|
{
|
||||||
|
_GSIMapGC = [NSGarbageCollector defaultCollector];
|
||||||
|
_GSIMapUnscannedZone = [_GSIMapGC zone];
|
||||||
|
_GSIMapSetup = YES;
|
||||||
|
}
|
||||||
|
if (_GSIMapGC != nil && (uintptr_t)zone > 3)
|
||||||
|
{
|
||||||
|
if (zone == _GSIMapUnscannedZone)
|
||||||
|
{
|
||||||
|
map->zone = GSIMapWeakKeyAndVal; // Unscanned memory
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
map->zone = GSIMapStrongKeyAndVal; // Scanned memory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
map->zone = zone;
|
map->zone = zone;
|
||||||
|
}
|
||||||
map->nodeCount = 0;
|
map->nodeCount = 0;
|
||||||
map->bucketCount = 0;
|
map->bucketCount = 0;
|
||||||
map->buckets = 0;
|
map->buckets = 0;
|
||||||
|
|
Loading…
Reference in a new issue