Changes by wacko@power1.snu.ac.kr (Yoo C. Chung). See ChangeLog Jan 20,21

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2203 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Andrew McCallum 1997-03-03 19:51:04 +00:00
parent c07f920c70
commit c5b0cb101c
8 changed files with 113 additions and 38 deletions

View file

@ -3,6 +3,58 @@ Mon Mar 3 14:41:01 1997 Andrew McCallum <mccallum@jprc.com>
* src/NSHost.m, src/include/NSHost.h: New files from Luke Howard
<lukeh@xedoc.com.au>.
Tue Jan 21 11:18:32 1997 Yoo C. Chung <wacko@power1.snu.ac.kr>
* checks/thread-except.m: New file.
* checks/Makefile.in (SRCS): Added thread-except.m.
* src/NSAssertionHandler.m ([NSAssertionHandler +currentHandler]):
Handle multiple threads.
* src/NSException.m: Removed e_handlers.
([NSException -raise]): Support multiple threads.
(_NSAddHandler): Likewise.
(_NSRemoveHandler): Likewise.
* src/NSThread.m ([NSThread -init]): Init _exception_handler.
([NSThread -exceptionHandler]): New method.
([NSThread -setExceptionHandler:]): Likewise.
* src/include/NSThread.h (NSThread): Added _exception_handler and
new methods exceptionHandler and setExceptionHandler.
Mon Jan 20 09:46:00 1997 Yoo C. Chung <wacko@power1.snu.ac.kr>
* src/NSException.m: Use linked list instead of NSArray. Fit
lines within 80 columns.
* src/NSZone.m (nmalloc): Use CHUNKSIZE to get new block size
instead of SIZE.
Mon Jan 20 00:15:39 1997 Yoo C. Chung <wacko@power1.snu.ac.kr>
* src/NSAllocateObject.m: Include NSZone.h.
* src/NSZone.m: Changed ffree_NSZone and nfree_NSZone to ffree_zone
and nfree_zone. Changed lock functions return types to ints.
(become_threaded): Set mutex functions.
(NSZoneMemInUse): Properly check buffer.
(nmalloc): Removed unnecessary declaration of block.
(NSCreateZone): Moved assignment of block out of exception handled
area.
(NSCreateZone): Fixed typo (objc_mutex_deallocate instead of
objc_mutex_dealloc).
(NSZoneMemInUse): Consider cases when memory is in buffer.
* src/NSData.m ([NSData -description]): Frees malloced memory.
* src/NSPage.m (NSAllocateMemoryPages): Return NULL if we fail to
allocate memory.
* src/NSObject.m (NSShouldRetainWithZone): Check match for
NSDefaultMallocZone().
Fri Jan 17 20:08:00 1997 Yoo C. Chung <wacko@power1.snu.ac.kr>
* src/o_x_bas.m.in (o_@XX@_zone): Use NSZoneFromPointer().

View file

@ -15,7 +15,9 @@ The currently released version of the library is
the way various other names were changed.
@item The library now requires a patch to gcc-2.7.2. The patch adds
thread-safe features to the GNU Objective C runtime.
thread-safe features to the GNU Objective C runtime. Each thread has
its own exception handler and assertion handler, thanks to Yoo C. Chung
<wacko@power1.snu.ac.kr>.
@item Distributed Objects is much improved. Exceptions in the server
are sent back to the client. Ungracefully closed connections are

View file

@ -29,6 +29,7 @@
#include <objc/thr.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSException.h>
#include <Foundation/NSAutoreleasePool.h> // for struct autorelease_thread_vars
typedef enum
@ -42,6 +43,7 @@ typedef enum
{
@public
objc_thread_t _thread_id;
NSHandler *_exception_handler;
NSMutableDictionary *_thread_dictionary;
struct autorelease_thread_vars _autorelease_vars;
}
@ -57,6 +59,10 @@ typedef enum
+ (void) sleepUntilDate: (NSDate*)date;
+ (void) exit;
- (NSHandler*)exceptionHandler;
- (void)setExceptionHandler: (NSHandler*)handler;
@end
/* Notification Strings. */

View file

@ -21,18 +21,28 @@
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <Foundation/NSException.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSString.h>
#include <Foundation/NSThread.h>
@implementation NSAssertionHandler
/* Key for thread dictionary. */
static NSString *dict_key = @"_NSAssertionHandler";
+ (NSAssertionHandler *)currentHandler
{
// FIXME: current handler should come from current thread dictionary;
static NSAssertionHandler *only_one = nil;
if (!only_one)
only_one = [NSAssertionHandler new];
return only_one;
NSMutableDictionary *dict;
NSAssertionHandler *handler;
dict = [[NSThread currentThread] threadDictionary];
handler = [dict objectForKey: dict_key];
if (handler == nil)
{
handler = [[NSAssertionHandler alloc] init];
[dict setObject: handler forKey: dict_key];
}
return handler;
}
- (void)handleFailureInFunction:(NSString *)functionName

View file

@ -26,21 +26,16 @@
#include <Foundation/NSString.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSValue.h>
#include <Foundation/NSThread.h>
#include <Foundation/NSDictionary.h>
#include <assert.h>
NSString *NSGenericException
= @"NSGenericException";
NSString *NSGenericException = @"NSGenericException";
NSString *NSInternalInconsistencyException
= @"NSInternalInconsistencyException";
NSString *NSInvalidArgumentException = @"NSInvalidArgumentException";
NSString *NSMallocException = @"NSMallocException";
NSString *NSRangeException = @"NSRangeException";
/* FIXME: Not thread safe - probably need one for each thread. */
static NSMutableArray *e_queue;
NSUncaughtExceptionHandler *_NSUncaughtExceptionHandler;
static volatile void
@ -57,7 +52,9 @@ _NSFoundationUncaughtExceptionHandler(NSException *exception)
@implementation NSException
+ (NSException *)exceptionWithName:(NSString *)name reason:(NSString *)reason userInfo:(NSDictionary *)userInfo
+ (NSException *)exceptionWithName:(NSString *)name
reason:(NSString *)reason
userInfo:(NSDictionary *)userInfo
{
return [[[self alloc] initWithName:name reason:reason
userInfo:userInfo] autorelease];
@ -89,7 +86,8 @@ _NSFoundationUncaughtExceptionHandler(NSException *exception)
[except raise];
}
- (id)initWithName:(NSString *)name reason:(NSString *)reason userInfo:(NSDictionary *)userInfo
- (id)initWithName:(NSString *)name reason:(NSString *)reason
userInfo:(NSDictionary *)userInfo
{
self = [super init];
e_name = [name retain];
@ -101,23 +99,21 @@ _NSFoundationUncaughtExceptionHandler(NSException *exception)
- (volatile void)raise
{
NSThread *thread;
NSHandler *handler;
if (_NSUncaughtExceptionHandler == NULL)
_NSUncaughtExceptionHandler = _NSFoundationUncaughtExceptionHandler;
_NSUncaughtExceptionHandler = _NSFoundationUncaughtExceptionHandler;
if (!e_queue) {
thread = [NSThread currentThread];
handler = [thread exceptionHandler];
if (handler == NULL) {
_NSUncaughtExceptionHandler(self);
return;
}
if ([e_queue count] == 0) {
_NSUncaughtExceptionHandler(self);
return;
}
[[e_queue lastObject] getValue:&handler];
[thread setExceptionHandler: handler->next];
handler->exception = self;
[e_queue removeLastObject];
longjmp(handler->jumpState, 1);
}
@ -177,20 +173,18 @@ _NSFoundationUncaughtExceptionHandler(NSException *exception)
void
_NSAddHandler( NSHandler *handler )
{
if (!e_queue)
e_queue = [[NSMutableArray alloc] initWithCapacity:8];
NSThread *thread;
[e_queue addObject:
[NSValue value: &handler
withObjCType: @encode(NSHandler*)]];
thread = [NSThread currentThread];
handler->next = [thread exceptionHandler];
[thread setExceptionHandler: handler];
}
void
_NSRemoveHandler( NSHandler *handler )
{
// FIXME: Should be NSAssert??
assert(e_queue);
assert([e_queue count] != 0);
[e_queue removeLastObject];
}
NSThread *thread;
thread = [NSThread currentThread];
[thread setExceptionHandler: ([thread exceptionHandler])->next];
}

View file

@ -74,6 +74,7 @@ static BOOL entered_multi_threaded_state;
/* initialize our ivars. */
_thread_dictionary = nil; // Initialize this later only when needed
_exception_handler = NULL;
init_autorelease_thread_vars (&_autorelease_vars);
/* Make it easy and fast to get this NSThread object from the thread. */
@ -188,4 +189,14 @@ static BOOL entered_multi_threaded_state;
objc_thread_exit ();
}
- (NSHandler*)exceptionHandler
{
return _exception_handler;
}
- (void)setExceptionHandler: (NSHandler*)handler
{
_exception_handler = handler;
}
@end

View file

@ -456,7 +456,6 @@ segindex (size_t size)
{
assert(size%MINCHUNK == 0);
if (size < CLTOSZ(8))
return size/MINCHUNK;
else if (size < CLTOSZ(16))
@ -786,7 +785,7 @@ nmalloc (NSZone *zone, size_t size)
if (zptr->blocks->size-zptr->blocks->top < chunksize)
/* Get new block. */
{
size_t blocksize = roundupto(size+NF_HEAD, zone->gran);
size_t blocksize = roundupto(chunksize+NF_HEAD, zone->gran);
/* Any clean way to make gcc shut up here? */
NS_DURING

View file

@ -98,7 +98,8 @@ basic.m \
release.m \
nsscanner.m \
nsdate.m \
awake.m
awake.m \
thread-except.m
tcpport: FORCE
(cd ../src; $(MAKE))