mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-03 10:00:51 +00:00
Remved some unused code.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28047 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c565583e6c
commit
c2bfae873f
2 changed files with 15 additions and 266 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2009-03-06 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSObject.m: Remove unused code for holding reference counts
|
||||||
|
in an external map.
|
||||||
|
|
||||||
2009-03-02 Richard Frith-Macdonald <rfm@gnu.org>
|
2009-03-02 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/GSHTTPURLHandle.m: Implement new mechanism for handling
|
* Source/GSHTTPURLHandle.m: Implement new mechanism for handling
|
||||||
|
|
|
@ -113,8 +113,7 @@ static Class NSConstantStringClass;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* allocationLock is needed when running multi-threaded for
|
* allocationLock is needed when running multi-threaded for
|
||||||
* protecting the map table of zombie information and for retain
|
* protecting the map table of zombie information.
|
||||||
* count protection (when using a map table ... REFCNT_LOCAL is NO)
|
|
||||||
*/
|
*/
|
||||||
static objc_mutex_t allocationLock = NULL;
|
static objc_mutex_t allocationLock = NULL;
|
||||||
|
|
||||||
|
@ -181,24 +180,12 @@ static void GSLogZombie(id o, SEL sel)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reference count and memory management
|
* Reference count and memory management
|
||||||
*
|
* Reference counts for object are stored
|
||||||
* If REFCNT_LOCAL is defined, reference counts for object are stored
|
* with the object.
|
||||||
* with the object, otherwise they are stored in a global map table
|
* The zone in which an object has been
|
||||||
* that has to be protected by mutexes in a multithreraded environment.
|
* allocated is stored with the object.
|
||||||
* You therefore want REFCNT_LOCAL defined for best performance.
|
|
||||||
*
|
|
||||||
* If CACHE_ZONE is defined, the zone in which an object has been
|
|
||||||
* allocated is stored with the object - this makes lookup of the
|
|
||||||
* correct zone to free memory very fast.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#if GS_WITH_GC == 0 && !defined(NeXT_RUNTIME)
|
|
||||||
#define REFCNT_LOCAL 1
|
|
||||||
#define CACHE_ZONE 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Now, if we are on a platform where we know how to do atomic
|
/* Now, if we are on a platform where we know how to do atomic
|
||||||
* read, increment, and decrement, then we define the GSATOMICREAD
|
* read, increment, and decrement, then we define the GSATOMICREAD
|
||||||
* macro and macros or functions to increment/decrement.
|
* macro and macros or functions to increment/decrement.
|
||||||
|
@ -213,8 +200,6 @@ static void GSLogZombie(id o, SEL sel)
|
||||||
#undef GSATOMICREAD
|
#undef GSATOMICREAD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(REFCNT_LOCAL)
|
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
#ifndef _WIN64
|
#ifndef _WIN64
|
||||||
#undef InterlockedIncrement
|
#undef InterlockedIncrement
|
||||||
|
@ -233,8 +218,6 @@ typedef int32_t volatile *gsatomic_t;
|
||||||
#define GSAtomicIncrement(X) InterlockedIncrement((LONG volatile*)X)
|
#define GSAtomicIncrement(X) InterlockedIncrement((LONG volatile*)X)
|
||||||
#define GSAtomicDecrement(X) InterlockedDecrement((LONG volatile*)X)
|
#define GSAtomicDecrement(X) InterlockedDecrement((LONG volatile*)X)
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#elif defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
|
#elif defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
|
||||||
/* Set up atomic read, increment and decrement for intel style linux
|
/* Set up atomic read, increment and decrement for intel style linux
|
||||||
|
@ -302,12 +285,12 @@ GSAtomicDecrement(gsatomic_t X)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(REFCNT_LOCAL) && !defined(GSATOMICREAD)
|
#if !defined(GSATOMICREAD)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Having just one allocationLock for all leads to lock contention
|
* Having just one allocationLock for all leads to lock contention
|
||||||
* if there are lots of threads doing lots of retain/release calls.
|
* if there are lots of threads doing lots of retain/release calls.
|
||||||
* To alleviate this, if using REFCNT_LOCAL, instead of a single
|
* To alleviate this, instead of a single
|
||||||
* allocationLock for all objects, we divide the object space into
|
* allocationLock for all objects, we divide the object space into
|
||||||
* chunks, each with its own lock. The chunk is selected by shifting
|
* chunks, each with its own lock. The chunk is selected by shifting
|
||||||
* off the low-order ALIGNBITS of the object's pointer (these bits
|
* off the low-order ALIGNBITS of the object's pointer (these bits
|
||||||
|
@ -336,19 +319,13 @@ static inline objc_mutex_t GSAllocationLockForObject(id p)
|
||||||
#endif
|
#endif
|
||||||
#define ALIGN __alignof__(double)
|
#define ALIGN __alignof__(double)
|
||||||
|
|
||||||
#if defined(REFCNT_LOCAL) || defined(CACHE_ZONE)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define a structure to hold information that is held locally
|
* Define a structure to hold information that is held locally
|
||||||
* (before the start) in each object.
|
* (before the start) in each object.
|
||||||
*/
|
*/
|
||||||
typedef struct obj_layout_unpadded {
|
typedef struct obj_layout_unpadded {
|
||||||
#if defined(REFCNT_LOCAL)
|
|
||||||
NSUInteger retained;
|
NSUInteger retained;
|
||||||
#endif
|
|
||||||
#if defined(CACHE_ZONE)
|
|
||||||
NSZone *zone;
|
NSZone *zone;
|
||||||
#endif
|
|
||||||
} unp;
|
} unp;
|
||||||
#define UNP sizeof(unp)
|
#define UNP sizeof(unp)
|
||||||
|
|
||||||
|
@ -358,40 +335,12 @@ typedef struct obj_layout_unpadded {
|
||||||
* structure correct.
|
* structure correct.
|
||||||
*/
|
*/
|
||||||
struct obj_layout {
|
struct obj_layout {
|
||||||
#if defined(REFCNT_LOCAL)
|
|
||||||
NSUInteger retained;
|
NSUInteger retained;
|
||||||
#endif
|
|
||||||
#if defined(CACHE_ZONE)
|
|
||||||
NSZone *zone;
|
NSZone *zone;
|
||||||
#endif
|
|
||||||
char padding[ALIGN - ((UNP % ALIGN) ? (UNP % ALIGN) : ALIGN)];
|
char padding[ALIGN - ((UNP % ALIGN) ? (UNP % ALIGN) : ALIGN)];
|
||||||
};
|
};
|
||||||
typedef struct obj_layout *obj;
|
typedef struct obj_layout *obj;
|
||||||
|
|
||||||
#endif /* defined(REFCNT_LOCAL) || defined(CACHE_ZONE) */
|
|
||||||
|
|
||||||
#if !defined(REFCNT_LOCAL)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set up map table for non-local reference counts.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define GSI_MAP_EQUAL(M, X, Y) (X.obj == Y.obj)
|
|
||||||
#define GSI_MAP_HASH(M, X) (X.uint >> 2)
|
|
||||||
#define GSI_MAP_RETAIN_KEY(M, X)
|
|
||||||
#define GSI_MAP_RELEASE_KEY(M, X)
|
|
||||||
#define GSI_MAP_RETAIN_VAL(M, X)
|
|
||||||
#define GSI_MAP_RELEASE_VAL(M, X)
|
|
||||||
#define GSI_MAP_KTYPES GSUNION_OBJ|GSUNION_INT
|
|
||||||
#define GSI_MAP_VTYPES GSUNION_INT
|
|
||||||
#define GSI_MAP_NOCLEAN 1
|
|
||||||
|
|
||||||
#include "GNUstepBase/GSIMap.h"
|
|
||||||
|
|
||||||
IF_NO_GC(static GSIMapTable_t retain_counts = {0};)
|
|
||||||
|
|
||||||
#endif /* !defined(REFCNT_LOCAL) */
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Examines the extra reference count for the object and, if non-zero
|
* Examines the extra reference count for the object and, if non-zero
|
||||||
|
@ -413,7 +362,6 @@ NSDecrementExtraRefCountWasZero(id anObject)
|
||||||
[NSException raise: NSGenericException
|
[NSException raise: NSGenericException
|
||||||
format: @"Release would release object too many times."];
|
format: @"Release would release object too many times."];
|
||||||
}
|
}
|
||||||
#if defined(REFCNT_LOCAL)
|
|
||||||
if (allocationLock != 0)
|
if (allocationLock != 0)
|
||||||
{
|
{
|
||||||
#if defined(GSATOMICREAD)
|
#if defined(GSATOMICREAD)
|
||||||
|
@ -466,49 +414,7 @@ NSDecrementExtraRefCountWasZero(id anObject)
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#endif /* !GS_WITH_GC */
|
||||||
GSIMapNode node;
|
|
||||||
|
|
||||||
if (allocationLock != 0)
|
|
||||||
{
|
|
||||||
objc_mutex_lock(allocationLock);
|
|
||||||
node = GSIMapNodeForKey(&retain_counts, (GSIMapKey)anObject);
|
|
||||||
if (node == 0)
|
|
||||||
{
|
|
||||||
objc_mutex_unlock(allocationLock);
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
if (node->value.uint == 0)
|
|
||||||
{
|
|
||||||
GSIMapRemoveKey((GSIMapTable)&retain_counts, (GSIMapKey)anObject);
|
|
||||||
objc_mutex_unlock(allocationLock);
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(node->value.uNSInteger)--;
|
|
||||||
}
|
|
||||||
objc_mutex_unlock(allocationLock);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
node = GSIMapNodeForKey(&retain_counts, (GSIMapKey)anObject);
|
|
||||||
if (node == 0)
|
|
||||||
{
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
if ((node->value.uNSInteger) == 0)
|
|
||||||
{
|
|
||||||
GSIMapRemoveKey((GSIMapTable)&retain_counts, (GSIMapKey)anObject);
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
--(node->value.uNSInteger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,43 +429,8 @@ NSExtraRefCount(id anObject)
|
||||||
#if GS_WITH_GC
|
#if GS_WITH_GC
|
||||||
return UINT_MAX - 1;
|
return UINT_MAX - 1;
|
||||||
#else /* GS_WITH_GC */
|
#else /* GS_WITH_GC */
|
||||||
#if defined(REFCNT_LOCAL)
|
|
||||||
return ((obj)anObject)[-1].retained;
|
return ((obj)anObject)[-1].retained;
|
||||||
#else
|
#endif /* GS_WITH_GC */
|
||||||
GSIMapNode node;
|
|
||||||
NSUInteger ret;
|
|
||||||
|
|
||||||
if (allocationLock != 0)
|
|
||||||
{
|
|
||||||
objc_mutex_t theLock = GSAllocationLockForObject(anObject);
|
|
||||||
|
|
||||||
objc_mutex_lock(theLock);
|
|
||||||
node = GSIMapNodeForKey(&retain_counts, (GSIMapKey)anObject);
|
|
||||||
if (node == 0)
|
|
||||||
{
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = node->value.uint;
|
|
||||||
}
|
|
||||||
objc_mutex_unlock(theLock);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
node = GSIMapNodeForKey(&retain_counts, (GSIMapKey)anObject);
|
|
||||||
if (node == 0)
|
|
||||||
{
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = node->value.uint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -574,7 +445,6 @@ NSIncrementExtraRefCount(id anObject)
|
||||||
#if GS_WITH_GC
|
#if GS_WITH_GC
|
||||||
return;
|
return;
|
||||||
#else /* GS_WITH_GC */
|
#else /* GS_WITH_GC */
|
||||||
#if defined(REFCNT_LOCAL)
|
|
||||||
if (allocationLock != 0)
|
if (allocationLock != 0)
|
||||||
{
|
{
|
||||||
#if defined(GSATOMICREAD)
|
#if defined(GSATOMICREAD)
|
||||||
|
@ -611,49 +481,6 @@ NSIncrementExtraRefCount(id anObject)
|
||||||
}
|
}
|
||||||
((obj)anObject)[-1].retained++;
|
((obj)anObject)[-1].retained++;
|
||||||
}
|
}
|
||||||
#else /* REFCNT_LOCAL */
|
|
||||||
GSIMapNode node;
|
|
||||||
|
|
||||||
if (allocationLock != 0)
|
|
||||||
{
|
|
||||||
objc_mutex_lock(allocationLock);
|
|
||||||
node = GSIMapNodeForKey(&retain_counts, (GSIMapKey)anObject);
|
|
||||||
if (node != 0)
|
|
||||||
{
|
|
||||||
if ((node->value.uNSInteger) == UINT_MAX - 1)
|
|
||||||
{
|
|
||||||
objc_mutex_unlock(allocationLock);
|
|
||||||
[NSException raise: NSInternalInconsistencyException
|
|
||||||
format:
|
|
||||||
@"NSIncrementExtraRefCount() asked to increment too far"];
|
|
||||||
}
|
|
||||||
(node->value.uNSInteger)++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GSIMapAddPair(&retain_counts, (GSIMapKey)anObject, (GSIMapVal)1);
|
|
||||||
}
|
|
||||||
objc_mutex_unlock(allocationLock);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
node = GSIMapNodeForKey(&retain_counts, (GSIMapKey)anObject);
|
|
||||||
if (node != 0)
|
|
||||||
{
|
|
||||||
if ((node->value.uNSInteger) == UINT_MAX - 1)
|
|
||||||
{
|
|
||||||
[NSException raise: NSInternalInconsistencyException
|
|
||||||
format:
|
|
||||||
@"NSIncrementExtraRefCount() asked to increment too far"];
|
|
||||||
}
|
|
||||||
(node->value.uNSInteger)++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GSIMapAddPair(&retain_counts, (GSIMapKey)anObject, (GSIMapVal)1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* REFCNT_LOCAL */
|
|
||||||
#endif /* GS_WITH_GC */
|
#endif /* GS_WITH_GC */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -739,10 +566,6 @@ NSDeallocateObject(NSObject *anObject)
|
||||||
|
|
||||||
#else /* GS_WITH_GC */
|
#else /* GS_WITH_GC */
|
||||||
|
|
||||||
#if defined(REFCNT_LOCAL) || defined(CACHE_ZONE)
|
|
||||||
|
|
||||||
#if defined(CACHE_ZONE)
|
|
||||||
|
|
||||||
inline NSZone *
|
inline NSZone *
|
||||||
GSObjCZone(NSObject *object)
|
GSObjCZone(NSObject *object)
|
||||||
{
|
{
|
||||||
|
@ -751,18 +574,6 @@ GSObjCZone(NSObject *object)
|
||||||
return ((obj)object)[-1].zone;
|
return ((obj)object)[-1].zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* defined(CACHE_ZONE) */
|
|
||||||
|
|
||||||
inline NSZone *
|
|
||||||
GSObjCZone(NSObject *object)
|
|
||||||
{
|
|
||||||
if (GSObjCClass(object) == NSConstantStringClass)
|
|
||||||
return NSDefaultMallocZone();
|
|
||||||
return NSZoneFromPointer(&((obj)object)[-1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* defined(CACHE_ZONE) */
|
|
||||||
|
|
||||||
inline NSObject *
|
inline NSObject *
|
||||||
NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone *zone)
|
NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone *zone)
|
||||||
{
|
{
|
||||||
|
@ -782,9 +593,7 @@ NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone *zone)
|
||||||
if (new != nil)
|
if (new != nil)
|
||||||
{
|
{
|
||||||
memset (new, 0, size);
|
memset (new, 0, size);
|
||||||
#if defined(CACHE_ZONE)
|
|
||||||
((obj)new)->zone = zone;
|
((obj)new)->zone = zone;
|
||||||
#endif
|
|
||||||
new = (id)&((obj)new)[1];
|
new = (id)&((obj)new)[1];
|
||||||
new->class_pointer = aClass;
|
new->class_pointer = aClass;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
@ -825,65 +634,6 @@ NSDeallocateObject(NSObject *anObject)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
inline NSZone *
|
|
||||||
GSObjCZone(NSObject *object)
|
|
||||||
{
|
|
||||||
if (GSObjCClass(object) == NSConstantStringClass)
|
|
||||||
return NSDefaultMallocZone();
|
|
||||||
return NSZoneFromPointer(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline NSObject *
|
|
||||||
NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone *zone)
|
|
||||||
{
|
|
||||||
id new;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
NSCAssert((CLS_ISCLASS(aClass)), @"Bad class for new object");
|
|
||||||
size = aClass->instance_size + extraBytes;
|
|
||||||
new = NSZoneMalloc (zone, size);
|
|
||||||
if (new != nil)
|
|
||||||
{
|
|
||||||
memset (new, 0, size);
|
|
||||||
new->class_pointer = aClass;
|
|
||||||
#ifndef NDEBUG
|
|
||||||
GSDebugAllocationAdd(aClass, new);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return new;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void
|
|
||||||
NSDeallocateObject(NSObject *anObject)
|
|
||||||
{
|
|
||||||
if ((anObject!=nil) && CLS_ISCLASS(((id)anObject)->class_pointer))
|
|
||||||
{
|
|
||||||
NSZone *z = [anObject zone];
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
GSDebugAllocationRemove(((id)anObject)->class_pointer, (id)anObject);
|
|
||||||
#endif
|
|
||||||
if (NSZombieEnabled == YES)
|
|
||||||
{
|
|
||||||
GSMakeZombie(anObject);
|
|
||||||
if (NSDeallocateZombies == YES)
|
|
||||||
{
|
|
||||||
NSZoneFree(z, anObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
((id)anObject)->class_pointer = (void*) 0xdeadface;
|
|
||||||
NSZoneFree(z, anObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* defined(REFCNT_LOCAL) || defined(CACHE_ZONE) */
|
|
||||||
|
|
||||||
#endif /* GS_WITH_GC */
|
#endif /* GS_WITH_GC */
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
|
@ -1049,7 +799,7 @@ GSDescriptionForClassMethod(pcl self, SEL aSel)
|
||||||
{
|
{
|
||||||
if (allocationLock == 0)
|
if (allocationLock == 0)
|
||||||
{
|
{
|
||||||
#if defined(REFCNT_LOCAL) && !defined(GSATOMICREAD)
|
#if !defined(GSATOMICREAD)
|
||||||
NSUInteger i;
|
NSUInteger i;
|
||||||
|
|
||||||
for (i = 0; i < LOCKCOUNT; i++)
|
for (i = 0; i < LOCKCOUNT; i++)
|
||||||
|
@ -1157,12 +907,6 @@ GSDescriptionForClassMethod(pcl self, SEL aSel)
|
||||||
autorelease_class = [NSAutoreleasePool class];
|
autorelease_class = [NSAutoreleasePool class];
|
||||||
autorelease_sel = @selector(addObject:);
|
autorelease_sel = @selector(addObject:);
|
||||||
autorelease_imp = [autorelease_class methodForSelector: autorelease_sel];
|
autorelease_imp = [autorelease_class methodForSelector: autorelease_sel];
|
||||||
#if GS_WITH_GC == 0
|
|
||||||
#if !defined(REFCNT_LOCAL)
|
|
||||||
GSIMapInitWithZoneAndCapacity(&retain_counts,
|
|
||||||
NSDefaultMallocZone(), 1024);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
NSConstantStringClass = [NSString constantStringClass];
|
NSConstantStringClass = [NSString constantStringClass];
|
||||||
GSPrivateBuildStrings();
|
GSPrivateBuildStrings();
|
||||||
[[NSNotificationCenter defaultCenter]
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue