mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Add new class from macos-x
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27585 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
921f8bd46a
commit
9ce6f3cc46
5 changed files with 238 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2009-01-12 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/GNUmakefile:
|
||||||
|
* Headers/Foundation/NSGarbageCollector.h:
|
||||||
|
* Source/NSGarbageCollector.m:
|
||||||
|
* Headers/Foundation/Foundation.h:
|
||||||
|
Add new MacOS-X class.
|
||||||
|
|
||||||
2009-01-12 Richard Frith-Macdonald <rfm@gnu.org>
|
2009-01-12 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSSocketPort.m:
|
* Source/NSSocketPort.m:
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
#import <Foundation/NSFileHandle.h>
|
#import <Foundation/NSFileHandle.h>
|
||||||
#import <Foundation/NSFileManager.h>
|
#import <Foundation/NSFileManager.h>
|
||||||
#import <Foundation/NSFormatter.h>
|
#import <Foundation/NSFormatter.h>
|
||||||
|
#import <Foundation/NSGarbageCollector.h>
|
||||||
#import <Foundation/NSGeometry.h>
|
#import <Foundation/NSGeometry.h>
|
||||||
#import <Foundation/NSHashTable.h>
|
#import <Foundation/NSHashTable.h>
|
||||||
#import <Foundation/NSHost.h>
|
#import <Foundation/NSHost.h>
|
||||||
|
|
90
Headers/Foundation/NSGarbageCollector.h
Normal file
90
Headers/Foundation/NSGarbageCollector.h
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/** Interface for NSGarbageCollector for GNUStep
|
||||||
|
Copyright (C) 2009 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
Created: Jan 2009
|
||||||
|
|
||||||
|
This file is part of the GNUstep Base Library.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02111 USA.
|
||||||
|
|
||||||
|
AutogsdocSource: NSGarbageCollector.m
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NSGarbageCollector_h_GNUSTEP_BASE_INCLUDE
|
||||||
|
#define _NSGarbageCollector_h_GNUSTEP_BASE_INCLUDE
|
||||||
|
#import <GNUstepBase/GSVersionMacros.h>
|
||||||
|
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
|
||||||
|
|
||||||
|
#import <Foundation/NSObject.h>
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@interface NSGarbageCollector : NSObject
|
||||||
|
|
||||||
|
/** Returns the garbage collector instance ... there is only one.<br />
|
||||||
|
* Returns nil if the process is not using garbage collection.
|
||||||
|
*/
|
||||||
|
+ (id) defaultCollector;
|
||||||
|
|
||||||
|
/** Collects some memory.
|
||||||
|
*/
|
||||||
|
- (void) collectIfNeeded;
|
||||||
|
|
||||||
|
/** Collects all collectable memory.
|
||||||
|
*/
|
||||||
|
- (void) collectExhaustively;
|
||||||
|
|
||||||
|
/** Disables garbage collection until a corresponding call to -enable is made.
|
||||||
|
*/
|
||||||
|
- (void) disable;
|
||||||
|
|
||||||
|
/** Disables collection for the area of memory pointed at.
|
||||||
|
*/
|
||||||
|
- (void) disableCollectorForPointer: (void *)ptr;
|
||||||
|
|
||||||
|
/** Enables garbage collection prevously disabled by a calle to -disable
|
||||||
|
*/
|
||||||
|
- (void) enable;
|
||||||
|
|
||||||
|
/** Enables collection for the area of memory pointed at.
|
||||||
|
*/
|
||||||
|
- (void) enableCollectorForPointer: (void *)ptr;
|
||||||
|
|
||||||
|
/** Returns yes if there is a garbage collection progress.
|
||||||
|
*/
|
||||||
|
- (BOOL) isCollecting;
|
||||||
|
|
||||||
|
/** Retunrs YES if garbage collecting is currently enabled.
|
||||||
|
*/
|
||||||
|
- (BOOL) isEnabled;
|
||||||
|
|
||||||
|
/** Returns a zone for holding non-collectable pointers.<br />
|
||||||
|
*/
|
||||||
|
- (NSZone*) zone;
|
||||||
|
@end
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
|
@ -194,6 +194,7 @@ NSException.m \
|
||||||
NSFileHandle.m \
|
NSFileHandle.m \
|
||||||
NSFileManager.m \
|
NSFileManager.m \
|
||||||
NSFormatter.m \
|
NSFormatter.m \
|
||||||
|
NSGarbageCollector.m \
|
||||||
NSGeometry.m \
|
NSGeometry.m \
|
||||||
NSHashTable.m \
|
NSHashTable.m \
|
||||||
NSHost.m \
|
NSHost.m \
|
||||||
|
@ -336,6 +337,7 @@ NSExpression.h \
|
||||||
NSFileHandle.h \
|
NSFileHandle.h \
|
||||||
NSFileManager.h \
|
NSFileManager.h \
|
||||||
NSFormatter.h \
|
NSFormatter.h \
|
||||||
|
NSGarbageCollector.h \
|
||||||
NSGeometry.h \
|
NSGeometry.h \
|
||||||
NSHashTable.h \
|
NSHashTable.h \
|
||||||
NSHost.h \
|
NSHost.h \
|
||||||
|
|
137
Source/NSGarbageCollector.m
Normal file
137
Source/NSGarbageCollector.m
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
/** Implementation for NSGarbageCollector for GNUStep
|
||||||
|
Copyright (C) 2009 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
Created: Jan 2009
|
||||||
|
|
||||||
|
This file is part of the GNUstep Base Library.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02111 USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "Foundation/NSGarbageCollector.h"
|
||||||
|
#import "Foundation/NSLock.h"
|
||||||
|
#import "Foundation/NSZone.h"
|
||||||
|
|
||||||
|
#if GS_WITH_GC
|
||||||
|
|
||||||
|
#include <gc.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@implementation NSGarbageCollector
|
||||||
|
|
||||||
|
static NSGarbageCollector *collector = nil;
|
||||||
|
static NSLock *lock = nil;
|
||||||
|
static unsigned disabled = 0;
|
||||||
|
|
||||||
|
+ (id) defaultCollector
|
||||||
|
{
|
||||||
|
return collector;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if GS_WITH_GC
|
||||||
|
+ (void) initialize
|
||||||
|
{
|
||||||
|
collector = [self alloc];
|
||||||
|
lock = [NSLock new];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
- (void) collectIfNeeded
|
||||||
|
{
|
||||||
|
#if GS_WITH_GC
|
||||||
|
GC_collect_a_little();
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) collectExhaustively
|
||||||
|
{
|
||||||
|
#if GS_WITH_GC
|
||||||
|
GC_gcollect();
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) disable
|
||||||
|
{
|
||||||
|
#if GS_WITH_GC
|
||||||
|
[lock lock];
|
||||||
|
GC_disable();
|
||||||
|
disabled++;
|
||||||
|
[lock unlock];
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) disableCollectorForPointer: (void *)ptr
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) enable
|
||||||
|
{
|
||||||
|
#if GS_WITH_GC
|
||||||
|
[lock lock];
|
||||||
|
if (disabled)
|
||||||
|
{
|
||||||
|
GC_enable();
|
||||||
|
disabled--;
|
||||||
|
}
|
||||||
|
[lock unlock];
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) enableCollectorForPointer: (void *)ptr
|
||||||
|
{
|
||||||
|
// FIXME
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) init
|
||||||
|
{
|
||||||
|
if (self != collector)
|
||||||
|
{
|
||||||
|
[self dealloc];
|
||||||
|
self = nil;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isCollecting
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isEnabled
|
||||||
|
{
|
||||||
|
if (disabled)
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSZone*) zone
|
||||||
|
{
|
||||||
|
return GSAtomicMallocZone();
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue