1995-03-17 23:53:43 +00:00
|
|
|
|
/* Interface for NSAutoreleasePool for GNUStep
|
1997-01-05 22:49:30 +00:00
|
|
|
|
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
1995-07-01 19:01:11 +00:00
|
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1995-07-01 19:01:11 +00:00
|
|
|
|
Date: 1995
|
1995-03-17 23:53:43 +00:00
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1995-03-17 23:53:43 +00:00
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library 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 Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
1995-03-17 23:53:43 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1996-04-17 19:36:35 +00:00
|
|
|
|
#ifndef __NSAutoreleasePool_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
|
#define __NSAutoreleasePool_h_GNUSTEP_BASE_INCLUDE
|
1995-03-17 23:53:43 +00:00
|
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
|
#include <Foundation/NSObject.h>
|
1995-03-17 23:53:43 +00:00
|
|
|
|
|
1996-07-15 18:41:44 +00:00
|
|
|
|
@class NSAutoreleasePool;
|
2000-11-22 08:41:07 +00:00
|
|
|
|
@class NSThread;
|
1996-07-15 18:41:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Each thread has its own copy of these variables.
|
|
|
|
|
A pointer to this structure is an ivar of NSThread. */
|
2002-06-06 14:02:59 +00:00
|
|
|
|
typedef struct autorelease_thread_vars
|
1996-07-15 18:41:44 +00:00
|
|
|
|
{
|
|
|
|
|
/* The current, default NSAutoreleasePool for the calling thread;
|
|
|
|
|
the one that will hold objects that are arguments to
|
|
|
|
|
[NSAutoreleasePool +addObject:]. */
|
|
|
|
|
NSAutoreleasePool *current_pool;
|
|
|
|
|
|
|
|
|
|
/* The total number of objects autoreleased since the thread was
|
|
|
|
|
started, or since -resetTotalAutoreleasedObjects was called
|
1999-04-19 14:29:52 +00:00
|
|
|
|
in this thread. (if compiled in) */
|
1996-07-15 18:41:44 +00:00
|
|
|
|
unsigned total_objects_count;
|
|
|
|
|
|
|
|
|
|
/* A cache of NSAutoreleasePool's already alloc'ed. Caching old pools
|
|
|
|
|
instead of deallocating and re-allocating them will save time. */
|
|
|
|
|
id *pool_cache;
|
|
|
|
|
int pool_cache_size;
|
|
|
|
|
int pool_cache_count;
|
2002-06-06 14:02:59 +00:00
|
|
|
|
} thread_vars_struct;
|
1996-07-15 18:41:44 +00:00
|
|
|
|
|
|
|
|
|
/* Initialize an autorelease_thread_vars structure for a new thread.
|
1997-01-05 22:49:30 +00:00
|
|
|
|
This function is called in NSThread each time an NSThread is created.
|
|
|
|
|
TV should be of type `struct autorelease_thread_vars *' */
|
1997-01-05 23:19:22 +00:00
|
|
|
|
#define init_autorelease_thread_vars(TV) memset (TV, 0, sizeof (typeof (*TV)))
|
1997-01-05 22:49:30 +00:00
|
|
|
|
|
1996-07-15 18:41:44 +00:00
|
|
|
|
|
|
|
|
|
|
1996-05-12 00:39:49 +00:00
|
|
|
|
/* Each pool holds its objects-to-be-released in a linked-list of
|
|
|
|
|
these structures. */
|
2002-06-06 14:02:59 +00:00
|
|
|
|
typedef struct autorelease_array_list
|
1995-03-17 23:53:43 +00:00
|
|
|
|
{
|
1996-03-30 22:20:43 +00:00
|
|
|
|
struct autorelease_array_list *next;
|
|
|
|
|
unsigned size;
|
|
|
|
|
unsigned count;
|
|
|
|
|
id objects[0];
|
2002-06-06 14:02:59 +00:00
|
|
|
|
} array_list_struct;
|
1996-03-30 22:20:43 +00:00
|
|
|
|
|
1996-07-15 18:41:44 +00:00
|
|
|
|
|
1996-03-30 22:20:43 +00:00
|
|
|
|
@interface NSAutoreleasePool : NSObject
|
|
|
|
|
{
|
|
|
|
|
/* For re-setting the current pool when we are dealloc'ed. */
|
|
|
|
|
NSAutoreleasePool *_parent;
|
1996-07-15 18:41:44 +00:00
|
|
|
|
/* This pointer to our child pool is necessary for co-existing
|
|
|
|
|
with exceptions. */
|
1996-03-30 22:20:43 +00:00
|
|
|
|
NSAutoreleasePool *_child;
|
1996-07-15 18:41:44 +00:00
|
|
|
|
/* A collection of the objects to be released. */
|
1996-03-30 22:20:43 +00:00
|
|
|
|
struct autorelease_array_list *_released;
|
|
|
|
|
struct autorelease_array_list *_released_head;
|
|
|
|
|
/* The total number of objects autoreleased in this pool. */
|
|
|
|
|
unsigned _released_count;
|
1999-05-06 20:24:50 +00:00
|
|
|
|
/* The method to add an object to this pool */
|
1999-09-16 07:21:34 +00:00
|
|
|
|
void (*_addImp)(id, SEL, id);
|
1995-03-17 23:53:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-12-17 14:31:42 +00:00
|
|
|
|
+ (void) addObject: (id)anObj;
|
|
|
|
|
- (void) addObject: (id)anObj;
|
1995-03-17 23:53:43 +00:00
|
|
|
|
|
1998-11-10 20:16:33 +00:00
|
|
|
|
#ifndef NO_GNUSTEP
|
1995-04-14 15:01:37 +00:00
|
|
|
|
+ (void) enableRelease: (BOOL)enable;
|
2001-05-10 20:00:02 +00:00
|
|
|
|
+ (void) freeCache; /* Free cache of unused pools in this thread. */
|
1995-04-14 15:01:37 +00:00
|
|
|
|
+ (void) setPoolCountThreshhold: (unsigned)c;
|
1999-09-16 07:21:34 +00:00
|
|
|
|
+ (unsigned) autoreleaseCountForObject: (id)anObject;
|
2000-11-22 08:41:07 +00:00
|
|
|
|
+ (void) _endThread: (NSThread*)thread; /* Don't call this directly. */
|
1999-04-19 14:29:52 +00:00
|
|
|
|
/*
|
|
|
|
|
* The next two methods have no effect unless you define COUNT_ALL to be
|
|
|
|
|
* 1 in NSAutoreleasepool.m - doing so incurs a thread lookup overhead
|
|
|
|
|
* each time an object is autoreleased.
|
|
|
|
|
*/
|
1996-03-30 22:20:43 +00:00
|
|
|
|
+ (void) resetTotalAutoreleasedObjects;
|
|
|
|
|
+ (unsigned) totalAutoreleasedObjects;
|
1998-11-10 20:16:33 +00:00
|
|
|
|
#endif
|
1995-03-17 23:53:43 +00:00
|
|
|
|
@end
|
|
|
|
|
|
1996-04-17 19:36:35 +00:00
|
|
|
|
#endif /* __NSAutoreleasePool_h_GNUSTEP_BASE_INCLUDE */
|