Commit fbe39e48 by Ben Elliston Committed by Ben Elliston

config-lang.in: Do not output the name of the selected thread file when building the front-end.

Sun Sep 13 08:13:39 1998  Ben Elliston  <bje@cygnus.com>
	* objc/config-lang.in: Do not output the name of the selected
	thread file when building the front-end.  The Makefile for the
	runtime library will do this.
	* objc/Make-lang.in: Do not build the runtime library or install
	the Objective C header files.  The Makefile for the runtime
	library will do this.
	* objc/Makefile.in (all.indirect): Only build the front-end.
	(compiler): Rename to `frontend'.
	(obj-runtime): Remove target.
	(copy-headers): Likewise.
	(clean): No need to remove `libobjc.a' any longer.

From-SVN: r22459
parent e6a480d3
......@@ -229,6 +229,22 @@ Sun Sep 13 04:37:28 1998 David S. Miller <davem@pierdol.cobaltmicro.com>
the next pointer of the most recently deleted insn when we skip
over a NOTE.
Sun Sep 13 08:13:39 1998 Ben Elliston <bje@cygnus.com>
* objc/config-lang.in: Do not output the name of the selected
thread file when building the front-end. The Makefile for the
runtime library will do this.
* objc/Make-lang.in: Do not build the runtime library or install
the Objective C header files. The Makefile for the runtime
library will do this.
* objc/Makefile.in (all.indirect): Only build the front-end.
(compiler): Rename to `frontend'.
(obj-runtime): Remove target.
(copy-headers): Likewise.
(clean): No need to remove `libobjc.a' any longer.
Sat Sep 12 11:37:19 1998 Michael Meissner <meissner@cygnus.com>
* rs6000.h ({ASM,CPP}_CPU_SPEC): Add support for all machines
......
# GNU Objective C Runtime Makefile
# GNU Objective C frontend Makefile
# Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
#
# This file is part of GNU CC.
......@@ -17,21 +17,19 @@
# Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# This makefile is run by the parent dir's makefile.
# thisdir1=`pwd`; \
# srcdir1=`cd $(srcdir); pwd`; \
# cd objc; \
# $(MAKE) $(MAKEFLAGS) -f $$srcdir1/objc/Makefile libobjc.a \
# srcdir=$$srcdir1 tooldir=$(tooldir) AR="$(AR)" AR_FLAGS="$(AR_FLAGS)" \
# GCC_FOR_TARGET="$$thisdir1/xgcc -B$$thisdir1/" \
# GCC_CFLAGS="$(GCC_CFLAGS)" incinstalldir=$$thisdir1/include
# OBJC_THREAD_FILE="$(OBJC_THREAD_FILE)"
# Two targets are used by ../Makefile: `all' and `mostlyclean'.
# The Makefile built from this file lives in the objc language subdirectory.
# Its purpose is to provide support for:
#
# 1. recursion where necessary, and only then (building .o's), and
# 2. building and debugging cc1objc from the language subdirectory.
#
# The parent Makefile handles all other chores, with help from the language
# Makefile fragment.
#
# The targets for external use are `all' and `mostlyclean'.
SHELL=/bin/sh
.SUFFIXES: .m
OPTIMIZE= -O
srcdir = .
......@@ -56,48 +54,17 @@ all: all.indirect
####build overrides
#
OBJC_H = hash.h objc-list.h sarray.h objc.h objc-api.h \
NXConstStr.h Object.h Protocol.h encoding.h typedstream.h thr.h
# Now figure out from those variables how to compile and link.
all.indirect: Makefile compiler objc-runtime
all.indirect: Makefile frontend
compiler:
frontend:
cd ..; $(MAKE) cc1obj$(exeext)
objc-runtime:
cd ..; $(MAKE) libobjc.a
# copy objc headers to installation include directory
copy-headers:
-rm -fr $(incinstalldir)/objc
-mkdir $(incinstalldir)/objc
for file in $(OBJC_H); do \
realfile=$(srcdir)/$${file}; \
cp $${realfile} $(incinstalldir)/objc; \
chmod a+r $(incinstalldir)/objc/$${file}; \
done
Makefile: $(srcdir)/Makefile.in $(srcdir)/../configure
cd ..; $(SHELL) config.status
doc: info dvi html
info: objc-features.info
dvi: objc-features.dvi
html: objc-features_toc.html
objc-features.info: $(srcdir)/objc-features.texi
makeinfo $(srcdir)/objc-features.texi
objc-features.dvi: $(srcdir)/objc-features.texi
texi2dvi $(srcdir)/objc-features.texi
objc-features_toc.html: objc-features.texi
texi2html -split_node $(srcdir)/objc-features.texi
mostlyclean:
-rm -f *.o libobjc* xforward fflags *.aux *.cp *.dvi *.fn *.info \
*.ky *.log *.pg *.toc *.tp *.vr *.html
-rm -f *.o xforward fflags
clean: mostlyclean
distclean: mostlyclean
extraclean: mostlyclean
......
/* Interface for the NXConstantString class for Objective-C.
Copyright (C) 1995 Free Software Foundation, Inc.
Contributed by Pieter J. Schoenmakers <tiggr@es.ele.tue.nl>
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
GNU CC 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 General Public
License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files
compiled with GCC to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#ifndef __nxconstantstring_INCLUDE_GNU
#define __nxconstantstring_INCLUDE_GNU
#include "objc/Object.h"
@interface NXConstantString: Object
{
char *c_string;
unsigned int len;
}
-(const char *) cString;
-(unsigned int) length;
@end
#endif
/* Implementation of the NXConstantString class for Objective-C.
Copyright (C) 1995 Free Software Foundation, Inc.
Contributed by Pieter J. Schoenmakers <tiggr@es.ele.tue.nl>
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
GNU CC 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 General Public
License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files
compiled with GCC to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#include "objc/NXConstStr.h"
@implementation NXConstantString
-(const char *) cString
{
return (c_string);
} /* -cString */
-(unsigned int) length
{
return (len);
} /* -length */
@end
/* Interface for the Object class for Objective-C.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
GNU CC 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 General Public
License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled
with GCC to produce an executable, this does not cause the resulting
executable to be covered by the GNU General Public License. This
exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
#ifndef __object_INCLUDE_GNU
#define __object_INCLUDE_GNU
#include <objc/objc.h>
#include <objc/typedstream.h>
/*
* All classes are derived from Object. As such,
* this is the overhead tacked onto those objects.
*/
@interface Object
{
Class isa; /* A pointer to the instance's class structure */
}
/* Initializing classes and instances */
+ initialize;
- - init;
/* Creating, freeing, and copying instances */
+ + new;
+ + alloc;
- - free;
- - copy;
- - shallowCopy;
- - deepen;
- - deepCopy;
/* Identifying classes */
- (Class)class;
- (Class)superClass;
- (MetaClass)metaClass;
- (const char *)name;
/* Identifying and comparing objects */
- - self;
- (unsigned int)hash;
- (BOOL)isEqual:anObject;
- (int)compare:anotherObject;
/* Testing object type */
- (BOOL)isMetaClass;
- (BOOL)isClass;
- (BOOL)isInstance;
/* Testing inheritance relationships */
- (BOOL)isKindOf:(Class)aClassObject;
- (BOOL)isMemberOf:(Class)aClassObject;
- (BOOL)isKindOfClassNamed:(const char *)aClassName;
- (BOOL)isMemberOfClassNamed:(const char *)aClassName;
/* Testing class functionality */
+ (BOOL)instancesRespondTo:(SEL)aSel;
- (BOOL)respondsTo:(SEL)aSel;
/* Testing protocol conformance */
- (BOOL)conformsTo:(Protocol*)aProtocol;
/* Introspection */
+ (IMP)instanceMethodFor:(SEL)aSel;
- (IMP)methodFor:(SEL)aSel;
+ (struct objc_method_description *)descriptionForInstanceMethod:(SEL)aSel;
- (struct objc_method_description *)descriptionForMethod:(SEL)aSel;
/* Sending messages determined at run time */
- - perform:(SEL)aSel;
- - perform:(SEL)aSel with:anObject;
- - perform:(SEL)aSel with:anObject1 with:anObject2;
/* Forwarding */
- (retval_t)forward:(SEL)aSel :(arglist_t)argFrame;
- (retval_t)performv:(SEL)aSel :(arglist_t)argFrame;
/* Posing */
+ + poseAs:(Class)aClassObject;
- (Class)transmuteClassTo:(Class)aClassObject;
/* Enforcing intentions */
- - subclassResponsibility:(SEL)aSel;
- - notImplemented:(SEL)aSel;
- - shouldNotImplement:(SEL)aSel;
/* Error handling */
- - doesNotRecognize:(SEL)aSel;
- - error:(const char *)aString, ...;
/* Archiving */
+ (int)version;
+ + setVersion:(int)aVersion;
+ (int)streamVersion: (TypedStream*)aStream;
- - read: (TypedStream*)aStream;
- - write: (TypedStream*)aStream;
- - awake;
@end
#endif
/* The implementation of class Object for Objective-C.
Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
GNU CC 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 General Public
License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled
with GCC to produce an executable, this does not cause the resulting
executable to be covered by the GNU General Public License. This
exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
#include <stdarg.h>
#include "objc/Object.h"
#include "objc/Protocol.h"
#include "objc/objc-api.h"
extern int errno;
#define MAX_CLASS_NAME_LEN 256
@implementation Object
+ + initialize
{
return self;
}
- init
{
return self;
}
+ new
{
return [[self alloc] init];
}
+ alloc
{
return class_create_instance(self);
}
- free
{
return object_dispose(self);
}
- copy
{
return [[self shallowCopy] deepen];
}
- shallowCopy
{
return object_copy(self);
}
- deepen
{
return self;
}
- deepCopy
{
return [self copy];
}
- (Class)class
{
return object_get_class(self);
}
- (Class)superClass
{
return object_get_super_class(self);
}
- (MetaClass)metaClass
{
return object_get_meta_class(self);
}
- (const char *)name
{
return object_get_class_name(self);
}
- self
{
return self;
}
- (unsigned int)hash
{
return (size_t)self;
}
- (BOOL)isEqual:anObject
{
return self==anObject;
}
- (int)compare:anotherObject;
{
if ([self isEqual:anotherObject])
return 0;
// Ordering objects by their address is pretty useless,
// so subclasses should override this is some useful way.
else if (self > anotherObject)
return 1;
else
return -1;
}
- (BOOL)isMetaClass
{
return NO;
}
- (BOOL)isClass
{
return object_is_class(self);
}
- (BOOL)isInstance
{
return object_is_instance(self);
}
- (BOOL)isKindOf:(Class)aClassObject
{
Class class;
for (class = self->isa; class!=Nil; class = class_get_super_class(class))
if (class==aClassObject)
return YES;
return NO;
}
- (BOOL)isMemberOf:(Class)aClassObject
{
return self->isa==aClassObject;
}
- (BOOL)isKindOfClassNamed:(const char *)aClassName
{
Class class;
if (aClassName!=NULL)
for (class = self->isa; class!=Nil; class = class_get_super_class(class))
if (!strcmp(class_get_class_name(class), aClassName))
return YES;
return NO;
}
- (BOOL)isMemberOfClassNamed:(const char *)aClassName
{
return ((aClassName!=NULL)
&&!strcmp(class_get_class_name(self->isa), aClassName));
}
+ (BOOL)instancesRespondTo:(SEL)aSel
{
return class_get_instance_method(self, aSel)!=METHOD_NULL;
}
- (BOOL)respondsTo:(SEL)aSel
{
return ((object_is_instance(self)
?class_get_instance_method(self->isa, aSel)
:class_get_class_method(self->isa, aSel))!=METHOD_NULL);
}
+ (IMP)instanceMethodFor:(SEL)aSel
{
return method_get_imp(class_get_instance_method(self, aSel));
}
// Indicates if the receiving class or instance conforms to the given protocol
// not usually overridden by subclasses
//
// Modified 9/5/94 to always search the class object's protocol list, rather
// than the meta class.
+ (BOOL) conformsTo: (Protocol*)aProtocol
{
int i;
struct objc_protocol_list* proto_list;
id parent;
for (proto_list = ((Class)self)->protocols;
proto_list; proto_list = proto_list->next)
{
for (i=0; i < proto_list->count; i++)
{
if ([proto_list->list[i] conformsTo: aProtocol])
return YES;
}
}
if ((parent = [self superClass]))
return [parent conformsTo: aProtocol];
else
return NO;
}
- (BOOL) conformsTo: (Protocol*)aProtocol
{
return [[self class] conformsTo:aProtocol];
}
- (IMP)methodFor:(SEL)aSel
{
return (method_get_imp(object_is_instance(self)
?class_get_instance_method(self->isa, aSel)
:class_get_class_method(self->isa, aSel)));
}
+ (struct objc_method_description *)descriptionForInstanceMethod:(SEL)aSel
{
return ((struct objc_method_description *)
class_get_instance_method(self, aSel));
}
- (struct objc_method_description *)descriptionForMethod:(SEL)aSel
{
return ((struct objc_method_description *)
(object_is_instance(self)
?class_get_instance_method(self->isa, aSel)
:class_get_class_method(self->isa, aSel)));
}
- perform:(SEL)aSel
{
IMP msg = objc_msg_lookup(self, aSel);
if (!msg)
return [self error:"invalid selector passed to %s", sel_get_name(_cmd)];
return (*msg)(self, aSel);
}
- perform:(SEL)aSel with:anObject
{
IMP msg = objc_msg_lookup(self, aSel);
if (!msg)
return [self error:"invalid selector passed to %s", sel_get_name(_cmd)];
return (*msg)(self, aSel, anObject);
}
- perform:(SEL)aSel with:anObject1 with:anObject2
{
IMP msg = objc_msg_lookup(self, aSel);
if (!msg)
return [self error:"invalid selector passed to %s", sel_get_name(_cmd)];
return (*msg)(self, aSel, anObject1, anObject2);
}
- (retval_t)forward:(SEL)aSel :(arglist_t)argFrame
{
return (retval_t)[self doesNotRecognize: aSel];
}
- (retval_t)performv:(SEL)aSel :(arglist_t)argFrame
{
return objc_msg_sendv(self, aSel, argFrame);
}
+ poseAs:(Class)aClassObject
{
return class_pose_as(self, aClassObject);
}
- (Class)transmuteClassTo:(Class)aClassObject
{
if (object_is_instance(self))
if (class_is_class(aClassObject))
if (class_get_instance_size(aClassObject)==class_get_instance_size(isa))
if ([self isKindOf:aClassObject])
{
Class old_isa = isa;
isa = aClassObject;
return old_isa;
}
return nil;
}
- subclassResponsibility:(SEL)aSel
{
return [self error:"subclass should override %s", sel_get_name(aSel)];
}
- notImplemented:(SEL)aSel
{
return [self error:"method %s not implemented", sel_get_name(aSel)];
}
- shouldNotImplement:(SEL)aSel
{
return [self error:"%s should not implement %s",
object_get_class_name(self), sel_get_name(aSel)];
}
- doesNotRecognize:(SEL)aSel
{
return [self error:"%s does not recognize %s",
object_get_class_name(self), sel_get_name(aSel)];
}
#ifdef __alpha__
extern size_t strlen(const char*);
#endif
- - error:(const char *)aString, ...
{
#define FMT "error: %s (%s)\n%s\n"
char fmt[(strlen((char*)FMT)+strlen((char*)object_get_class_name(self))
+((aString!=NULL)?strlen((char*)aString):0)+8)];
va_list ap;
sprintf(fmt, FMT, object_get_class_name(self),
object_is_instance(self)?"instance":"class",
(aString!=NULL)?aString:"");
va_start(ap, aString);
objc_verror(self, OBJC_ERR_UNKNOWN, fmt, ap);
va_end(ap);
return nil;
#undef FMT
}
+ (int)version
{
return class_get_version(self);
}
+ setVersion:(int)aVersion
{
class_set_version(self, aVersion);
return self;
}
+ (int)streamVersion: (TypedStream*)aStream
{
if (aStream->mode == OBJC_READONLY)
return objc_get_stream_class_version (aStream, self);
else
return class_get_version (self);
}
// These are used to write or read the instance variables
// declared in this particular part of the object. Subclasses
// should extend these, by calling [super read/write: aStream]
// before doing their own archiving. These methods are private, in
// the sense that they should only be called from subclasses.
- read: (TypedStream*)aStream
{
// [super read: aStream];
return self;
}
- write: (TypedStream*)aStream
{
// [super write: aStream];
return self;
}
- awake
{
// [super awake];
return self;
}
@end
/* Declare the class Protocol for Objective C programs.
Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files
compiled with GCC to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#ifndef __Protocol_INCLUDE_GNU
#define __Protocol_INCLUDE_GNU
#include "objc/Object.h"
@interface Protocol : Object
{
@private
char *protocol_name;
struct objc_protocol_list *protocol_list;
struct objc_method_description_list *instance_methods, *class_methods;
}
/* Obtaining attributes intrinsic to the protocol */
- (const char *)name;
/* Testing protocol conformance */
- (BOOL) conformsTo: (Protocol *)aProtocolObject;
/* Looking up information specific to a protocol */
- (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel;
- (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel;
@end
#endif __Protocol_INCLUDE_GNU
/* This file contains the implementation of class Protocol.
Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files
compiled with GCC to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#include "objc/Protocol.h"
#include "objc/objc-api.h"
/* Method description list */
struct objc_method_description_list {
int count;
struct objc_method_description list[1];
};
@implementation Protocol
{
@private
char *protocol_name;
struct objc_protocol_list *protocol_list;
struct objc_method_description_list *instance_methods, *class_methods;
}
/* Obtaining attributes intrinsic to the protocol */
- (const char *)name
{
return protocol_name;
}
/* Testing protocol conformance */
- (BOOL) conformsTo: (Protocol *)aProtocolObject
{
int i;
struct objc_protocol_list* proto_list;
if (!strcmp(aProtocolObject->protocol_name, self->protocol_name))
return YES;
for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
{
for (i=0; i < proto_list->count; i++)
{
if ([proto_list->list[i] conformsTo: aProtocolObject])
return YES;
}
}
return NO;
}
/* Looking up information specific to a protocol */
- (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel
{
int i;
struct objc_protocol_list* proto_list;
const char* name = sel_get_name (aSel);
struct objc_method_description *result;
for (i = 0; i < instance_methods->count; i++)
{
if (!strcmp ((char*)instance_methods->list[i].name, name))
return &(instance_methods->list[i]);
}
for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
{
for (i=0; i < proto_list->count; i++)
{
if ((result = [proto_list->list[i]
descriptionForInstanceMethod: aSel]))
return result;
}
}
return NULL;
}
- (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel;
{
int i;
struct objc_protocol_list* proto_list;
const char* name = sel_get_name (aSel);
struct objc_method_description *result;
for (i = 0; i < class_methods->count; i++)
{
if (!strcmp ((char*)class_methods->list[i].name, name))
return &(class_methods->list[i]);
}
for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
{
for (i=0; i < proto_list->count; i++)
{
if ((result = [proto_list->list[i]
descriptionForClassMethod: aSel]))
return result;
}
}
return NULL;
}
@end
==============================================================================
README - Wed Nov 29 15:16:24 EST 1995
------------------------------------------------------------------------------
Limited documentation is available in the THREADS file.
This version has been tested on Sun Solaris, SGI Irix, and Windows NT.
It should also work on any single threaded system.
Thanks go to the following people for help test and debug the library:
Scott Christley, scottc@ocbi.com
Andrew McCallum, mccallum@cs.rochester.edu
galen
gchunt@cs.rochester.edu
Any questions, bug reports, etc should be directed to:
Scott Christley, scottc@ocbi.com
Please do not bug Galen with email as he no longer supports the code.
==============================================================================
Changes from prior releases (in revered chronological order):
------------------------------------------------------------------------------
* Fixed bug in copy part of sarray_realloc. I had an < which should
have been <=. (Bug report from Scott).
------------------------------------------------------------------------------
* Support for DEC OSF/1 is definitely broken. My programs always
seg-fault when I link with libpthreads.a.
* Thread id's are no longer int's, but are instead of type
_objc_thread_t which is typedef'ed from a void *. An invalid thread
id is denoted by NULL and not -1 as before.
------------------------------------------------------------------------------
* Renamed thread-winnt.c to thread-win32.c to better reflect support
for the API on both Windows NT and Windows 95 platforms.
(Who knows, maybe even Win32s :-).
* Fixed bugs in Win32 support as per report from Scott Christley.
* Fixed bug in sarray_get as per report from Scott Christley.
This readme refers to the file thr-mach.c.
Under mach, thread priorities are kinda strange-- any given thread has
a MAXIMUM priority and a BASE priority. The BASE priority is the
current priority of the thread and the MAXIMUM is the maximum possible
priority the thread can assume. The developer can lower, but never
raise the maximum priority.
The gcc concept of thread priorities is that they run at one of three
levels; interactive, background, and low.
Under mach, this is translated to:
interactive -- set priority to maximum
background -- set priority to 2/3 of maximum
low -- set priority to 1/3 of maximum
This means that it is possible for a thread with the priority of
interactive to actually run at a lower priority than another thread
with a background, or even low, priority if the developer has modified
the maximum priority.
# Top level configure fragment for the GNU Objective-C Runtime Library.
# Copyright (C) 1997 Free Software Foundation, Inc.
# Copyright (C) 1997, 1998 Free Software Foundation, Inc.
#This file is part of GNU CC.
......@@ -32,6 +32,4 @@ compilers="cc1obj\$(exeext)"
stagestuff=""
diff_excludes=""
echo "Using \`$srcdir/objc/thr-${thread_file}.c' as Objective-C Runtime thread file."
diff_excludes="-x objc-parse.c -x objc-parse.y "
/* Encoding of types for Objective C.
Copyright (C) 1993, 1997 Free Software Foundation, Inc.
Author: Kresten Krab Thorup
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files
compiled with GCC to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#ifndef __encoding_INCLUDE_GNU
#define __encoding_INCLUDE_GNU
#include <ctype.h>
#include "objc/objc-api.h"
#define _C_CONST 'r'
#define _C_IN 'n'
#define _C_INOUT 'N'
#define _C_OUT 'o'
#define _C_BYCOPY 'O'
#define _C_ONEWAY 'V'
#define _C_GCINVISIBLE '!'
#define _F_CONST 0x01
#define _F_IN 0x01
#define _F_OUT 0x02
#define _F_INOUT 0x03
#define _F_BYCOPY 0x04
#define _F_ONEWAY 0x08
#define _F_GCINVISIBLE 0x10
int objc_aligned_size (const char* type);
int objc_sizeof_type (const char* type);
int objc_alignof_type (const char* type);
int objc_aligned_size (const char* type);
int objc_promoted_size (const char* type);
const char* objc_skip_type_qualifiers (const char* type);
const char* objc_skip_typespec (const char* type);
const char* objc_skip_offset (const char* type);
const char* objc_skip_argspec (const char* type);
int method_get_number_of_arguments (struct objc_method*);
int method_get_sizeof_arguments (struct objc_method*);
char* method_get_first_argument (struct objc_method*,
arglist_t argframe,
const char** type);
char* method_get_next_argument (arglist_t argframe,
const char **type);
char* method_get_nth_argument (struct objc_method* m,
arglist_t argframe,
int arg,
const char **type);
unsigned objc_get_type_qualifiers (const char* type);
struct objc_struct_layout
{
const char *original_type;
const char *type;
const char *prev_type;
unsigned int record_size;
unsigned int record_align;
};
void objc_layout_structure (const char *type,
struct objc_struct_layout *layout);
BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout);
void objc_layout_finish_structure (struct objc_struct_layout *layout,
unsigned int *size,
unsigned int *align);
void objc_layout_structure_get_info (struct objc_struct_layout *layout,
unsigned int *offset,
unsigned int *align,
const char **type);
#endif /* __encoding_INCLUDE_GNU */
/* Hash tables for Objective C internal structures
Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files
compiled with GCC to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#include "assert.h"
#include "objc/hash.h"
#include "runtime.h" /* for DEBUG_PRINTF */
/* These two macros determine when a hash table is full and
by how much it should be expanded respectively.
These equations are percentages. */
#define FULLNESS(cache) \
((((cache)->size * 75) / 100) <= (cache)->used)
#define EXPANSION(cache) \
((cache)->size * 2)
cache_ptr
hash_new (unsigned int size, hash_func_type hash_func,
compare_func_type compare_func)
{
cache_ptr cache;
/* Pass me a value greater than 0 and a power of 2. */
assert (size);
assert (!(size & (size - 1)));
/* Allocate the cache structure. calloc insures
its initialization for default values. */
cache = (cache_ptr) objc_calloc (1, sizeof (struct cache));
assert (cache);
/* Allocate the array of buckets for the cache.
calloc initializes all of the pointers to NULL. */
cache->node_table
= (node_ptr *) objc_calloc (size, sizeof (node_ptr));
assert (cache->node_table);
cache->size = size;
/* This should work for all processor architectures? */
cache->mask = (size - 1);
/* Store the hashing function so that codes can be computed. */
cache->hash_func = hash_func;
/* Store the function that compares hash keys to
determine if they are equal. */
cache->compare_func = compare_func;
return cache;
}
void
hash_delete (cache_ptr cache)
{
node_ptr node;
node_ptr next_node;
unsigned int i;
/* Purge all key/value pairs from the table. */
/* Step through the nodes one by one and remove every node WITHOUT
using hash_next. this makes hash_delete much more efficient. */
for (i = 0;i < cache->size;i++) {
if ((node = cache->node_table[i])) {
/* an entry in the hash table has been found, now step through the
nodes next in the list and free them. */
while ((next_node = node->next)) {
hash_remove (cache,node->key);
node = next_node;
}
hash_remove (cache,node->key);
}
}
/* Release the array of nodes and the cache itself. */
objc_free(cache->node_table);
objc_free(cache);
}
void
hash_add (cache_ptr *cachep, const void *key, void *value)
{
size_t indx = (*(*cachep)->hash_func)(*cachep, key);
node_ptr node = (node_ptr) objc_calloc (1, sizeof (struct cache_node));
assert (node);
/* Initialize the new node. */
node->key = key;
node->value = value;
node->next = (*cachep)->node_table[indx];
/* Debugging.
Check the list for another key. */
#ifdef DEBUG
{ node_ptr node1 = (*cachep)->node_table[indx];
while (node1) {
assert (node1->key != key);
node1 = node1->next;
}
}
#endif
/* Install the node as the first element on the list. */
(*cachep)->node_table[indx] = node;
/* Bump the number of entries in the cache. */
++(*cachep)->used;
/* Check the hash table's fullness. We're going
to expand if it is above the fullness level. */
if (FULLNESS (*cachep)) {
/* The hash table has reached its fullness level. Time to
expand it.
I'm using a slow method here but is built on other
primitive functions thereby increasing its
correctness. */
node_ptr node1 = NULL;
cache_ptr new = hash_new (EXPANSION (*cachep),
(*cachep)->hash_func,
(*cachep)->compare_func);
DEBUG_PRINTF ("Expanding cache %#x from %d to %d\n",
*cachep, (*cachep)->size, new->size);
/* Copy the nodes from the first hash table to the new one. */
while ((node1 = hash_next (*cachep, node1)))
hash_add (&new, node1->key, node1->value);
/* Trash the old cache. */
hash_delete (*cachep);
/* Return a pointer to the new hash table. */
*cachep = new;
}
}
void
hash_remove (cache_ptr cache, const void *key)
{
size_t indx = (*cache->hash_func)(cache, key);
node_ptr node = cache->node_table[indx];
/* We assume there is an entry in the table. Error if it is not. */
assert (node);
/* Special case. First element is the key/value pair to be removed. */
if ((*cache->compare_func)(node->key, key)) {
cache->node_table[indx] = node->next;
objc_free(node);
} else {
/* Otherwise, find the hash entry. */
node_ptr prev = node;
BOOL removed = NO;
do {
if ((*cache->compare_func)(node->key, key)) {
prev->next = node->next, removed = YES;
objc_free(node);
} else
prev = node, node = node->next;
} while (!removed && node);
assert (removed);
}
/* Decrement the number of entries in the hash table. */
--cache->used;
}
node_ptr
hash_next (cache_ptr cache, node_ptr node)
{
/* If the scan is being started then reset the last node
visitied pointer and bucket index. */
if (!node)
cache->last_bucket = 0;
/* If there is a node visited last then check for another
entry in the same bucket; Otherwise step to the next bucket. */
if (node) {
if (node->next)
/* There is a node which follows the last node
returned. Step to that node and retun it. */
return node->next;
else
++cache->last_bucket;
}
/* If the list isn't exhausted then search the buckets for
other nodes. */
if (cache->last_bucket < cache->size) {
/* Scan the remainder of the buckets looking for an entry
at the head of the list. Return the first item found. */
while (cache->last_bucket < cache->size)
if (cache->node_table[cache->last_bucket])
return cache->node_table[cache->last_bucket];
else
++cache->last_bucket;
/* No further nodes were found in the hash table. */
return NULL;
} else
return NULL;
}
/* Given KEY, return corresponding value for it in CACHE.
Return NULL if the KEY is not recorded. */
void *
hash_value_for_key (cache_ptr cache, const void *key)
{
node_ptr node = cache->node_table[(*cache->hash_func)(cache, key)];
void *retval = NULL;
if (node)
do {
if ((*cache->compare_func)(node->key, key)) {
retval = node->value;
break;
} else
node = node->next;
} while (!retval && node);
return retval;
}
/* Given KEY, return YES if it exists in the CACHE.
Return NO if it does not */
BOOL
hash_is_key_in_hash (cache_ptr cache, const void *key)
{
node_ptr node = cache->node_table[(*cache->hash_func)(cache, key)];
if (node)
do {
if ((*cache->compare_func)(node->key, key))
return YES;
else
node = node->next;
} while (node);
return NO;
}
/* Hash tables for Objective C method dispatch.
Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files
compiled with GCC to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#ifndef __hash_INCLUDE_GNU
#define __hash_INCLUDE_GNU
#include <stddef.h>
#include <objc/objc.h>
/*
* This data structure is used to hold items
* stored in a hash table. Each node holds
* a key/value pair.
*
* Items in the cache are really of type void *.
*/
typedef struct cache_node
{
struct cache_node *next; /* Pointer to next entry on the list.
NULL indicates end of list. */
const void *key; /* Key used to locate the value. Used
to locate value when more than one
key computes the same hash
value. */
void *value; /* Value stored for the key. */
} *node_ptr;
/*
* This data type is the function that computes a hash code given a key.
* Therefore, the key can be a pointer to anything and the function specific
* to the key type.
*
* Unfortunately there is a mutual data structure reference problem with this
* typedef. Therefore, to remove compiler warnings the functions passed to
* hash_new will have to be casted to this type.
*/
typedef unsigned int (*hash_func_type)(void *, const void *);
/*
* This data type is the function that compares two hash keys and returns an
* integer greater than, equal to, or less than 0, according as the first
* parameter is lexicographically greater than, equal to, or less than the
* second.
*/
typedef int (*compare_func_type)(const void *, const void *);
/*
* This data structure is the cache.
*
* It must be passed to all of the hashing routines
* (except for new).
*/
typedef struct cache
{
/* Variables used to implement the hash itself. */
node_ptr *node_table; /* Pointer to an array of hash nodes. */
/* Variables used to track the size of the hash table so to determine
when to resize it. */
unsigned int size; /* Number of buckets allocated for the hash table
(number of array entries allocated for
"node_table"). Must be a power of two. */
unsigned int used; /* Current number of entries in the hash table. */
unsigned int mask; /* Precomputed mask. */
/* Variables used to implement indexing through the hash table. */
unsigned int last_bucket; /* Tracks which entry in the array where
the last value was returned. */
/* Function used to compute a hash code given a key.
This function is specified when the hash table is created. */
hash_func_type hash_func;
/* Function used to compare two hash keys to see if they are equal. */
compare_func_type compare_func;
} *cache_ptr;
/* Two important hash tables. */
extern cache_ptr module_hash_table, class_hash_table;
/* Allocate and initialize a hash table. */
cache_ptr hash_new (unsigned int size,
hash_func_type hash_func,
compare_func_type compare_func);
/* Deallocate all of the hash nodes and the cache itself. */
void hash_delete (cache_ptr cache);
/* Add the key/value pair to the hash table. If the
hash table reaches a level of fullness then it will be resized.
assert if the key is already in the hash. */
void hash_add (cache_ptr *cachep, const void *key, void *value);
/* Remove the key/value pair from the hash table.
assert if the key isn't in the table. */
void hash_remove (cache_ptr cache, const void *key);
/* Used to index through the hash table. Start with NULL
to get the first entry.
Successive calls pass the value returned previously.
** Don't modify the hash during this operation ***
Cache nodes are returned such that key or value can
be extracted. */
node_ptr hash_next (cache_ptr cache, node_ptr node);
/* Used to return a value from a hash table using a given key. */
void *hash_value_for_key (cache_ptr cache, const void *key);
/* Used to determine if the given key exists in the hash table */
BOOL hash_is_key_in_hash (cache_ptr cache, const void *key);
/************************************************
Useful hashing functions.
Declared inline for your pleasure.
************************************************/
/* Calculate a hash code by performing some
manipulation of the key pointer. (Use the lowest bits
except for those likely to be 0 due to alignment.) */
static inline unsigned int
hash_ptr (cache_ptr cache, const void *key)
{
return ((size_t)key / sizeof (void *)) & cache->mask;
}
/* Calculate a hash code by iterating over a NULL
terminate string. */
static inline unsigned int
hash_string (cache_ptr cache, const void *key)
{
unsigned int ret = 0;
unsigned int ctr = 0;
while (*(char*)key) {
ret ^= *(char*)key++ << ctr;
ctr = (ctr + 1) % sizeof (void *);
}
return ret & cache->mask;
}
/* Compare two pointers for equality. */
static inline int
compare_ptrs (const void *k1, const void *k2)
{
return !(k1 - k2);
}
/* Compare two strings. */
static inline int
compare_strings (const void *k1, const void *k2)
{
if (k1 == k2)
return 1;
else if (k1 == 0 || k2 == 0)
return 0;
else
return !strcmp (k1, k2);
}
#endif /* not __hash_INCLUDE_GNU */
; GNU Objective C Runtime DLL Export Definitions
; Copyright (C) 1997 Free Software Foundation, Inc.
; Contributed by Scott Christley <scottc@net-community.com>
;
; This file is part of GNU CC.
;
; GNU CC is free software; you can redistribute it and/or modify it under the
; terms of the GNU General Public License as published by the Free Software
; Foundation; either version 2, or (at your option) any later version.
;
; GNU CC 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 General Public License for more
; details.
;
; You should have received a copy of the GNU General Public License along with
; GNU CC; see the file COPYING. If not, write to the Free Software
; Foundation, 59 Temple Place - Suite 330,
; Boston, MA 02111-1307, USA.
LIBRARY libobjc
EXPORTS
search_for_method_in_list
objc_get_uninstalled_dtable
hash_is_key_in_hash
objc_verror
_objc_load_callback
objc_malloc
objc_atomic_malloc
objc_valloc
objc_realloc
objc_calloc
objc_free
__objc_init_thread_system
objc_mutex_allocate
objc_mutex_deallocate
objc_mutex_lock
objc_mutex_trylock
objc_mutex_unlock
objc_thread_detach
objc_thread_exit
objc_thread_get_data
objc_thread_get_priority
objc_thread_id
objc_thread_set_data
objc_thread_set_priority
objc_thread_yield
__objc_class_name_Object
__objc_class_name_Protocol
__objc_class_name_NXConstantString
objc_error
__objc_object_alloc
__objc_object_copy
__objc_object_dispose
class_create_instance
object_copy
object_dispose
__objc_init_selector_tables
__objc_register_selectors_from_class
__sel_register_typed_name
sel_get_any_typed_uid
sel_get_any_uid
sel_get_name
sel_get_type
sel_get_typed_uid
sel_get_uid
sel_is_mapped
sel_register_name
sel_register_typed_name
sel_types_match
method_get_first_argument
method_get_next_argument
method_get_nth_argument
method_get_number_of_arguments
method_get_sizeof_arguments
objc_aligned_size
objc_alignof_type
objc_get_type_qualifiers
objc_promoted_size
objc_sizeof_type
objc_skip_argspec
objc_skip_offset
objc_skip_type_qualifiers
objc_skip_typespec
__objc_read_nbyte_uint
__objc_read_nbyte_ulong
__objc_write_class
__objc_write_object
__objc_write_selector
objc_close_typed_stream
objc_end_of_typed_stream
objc_flush_typed_stream
objc_get_stream_class_version
objc_open_typed_stream
objc_open_typed_stream_for_file
objc_read_array
objc_read_char
objc_read_int
objc_read_long
objc_read_object
objc_read_selector
objc_read_short
objc_read_string
objc_read_type
objc_read_types
objc_read_unsigned_char
objc_read_unsigned_int
objc_read_unsigned_long
objc_read_unsigned_short
objc_write_array
objc_write_char
objc_write_int
objc_write_long
objc_write_object
objc_write_object_reference
objc_write_root_object
objc_write_selector
objc_write_short
objc_write_string
objc_write_string_atomic
objc_write_type
objc_write_types
objc_write_unsigned_char
objc_write_unsigned_int
objc_write_unsigned_long
objc_write_unsigned_short
__objc_exec_class
__objc_init_dispatch_tables
__objc_install_premature_dtable
__objc_print_dtable_stats
__objc_responds_to
__objc_update_dispatch_table_for_class
class_add_method_list
class_get_class_method
class_get_instance_method
get_imp
nil_method
objc_msg_lookup
objc_msg_lookup_super
objc_msg_sendv
__objc_add_class_to_hash
__objc_init_class_tables
__objc_resolve_class_links
class_pose_as
objc_get_class
objc_get_meta_class
objc_lookup_class
objc_next_class
sarray_at_put
sarray_at_put_safe
sarray_free
sarray_lazy_copy
sarray_new
sarray_realloc
sarray_remove_garbage
hash_add
hash_delete
hash_new
hash_next
hash_remove
hash_value_for_key
/* GNU Objective C Runtime DLL Entry
Copyright (C) 1997 Free Software Foundation, Inc.
Contributed by Scott Christley <scottc@net-community.com>
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
GNU CC 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 General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include <windows.h>
/*
DLL entry function for Objective-C Runtime library
This function gets called everytime a process/thread attaches to DLL
*/
WINBOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call,
LPVOID lpReserved)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
/*
This section terminates the list of imports under GCC. If you do not
include this then you will have problems when linking with DLLs.
*/
asm (".section .idata$3\n" ".long 0,0,0,0,0,0,0,0");
/* Force linking of classes required by Objective C runtime.
Copyright (C) 1997 Free Software Foundation, Inc.
Contributed by Ovidiu Predescu (ovidiu@net-community.com).
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include <objc/Object.h>
#include <objc/NXConstStr.h>
/* Generate references to Object and NXConstanstString classes since they are
needed by the runtime system to run correctly. */
void __objc_linking (void)
{
[Object name];
[NXConstantString name];
}
# GNU Objective C Runtime Makefile for compiling with djgpp
# Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
#
# This file is part of GNU CC.
#
# GNU CC is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2, or (at your option) any later version.
#
# GNU CC 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 General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# GNU CC; see the file COPYING. If not, write to the Free Software
# Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# This Makefile is configured for GnuMAKE
GCC_FOR_TARGET=gcc
.SUFFIXES: .o .m
OPTIMIZE = -O2
# Always search these dirs when compiling.
SUBDIR_INCLUDES = -I. -I.. -I../config
.c.o:
$(GCC_FOR_TARGET) $(OPTIMIZE) \
-c $(GCC_CFLAGS) $(SUBDIR_INCLUDES) $<
.m.o:
$(GCC_FOR_TARGET) $(OPTIMIZE) -fgnu-runtime \
-c $(GCC_CFLAGS) $(SUBDIR_INCLUDES) $<
OBJC_O = hash.o sarray.o class.o sendmsg.o init.o archive.o \
selector.o objects.o misc.o object.o protocol.o encoding.o thread.o
libobjc.a: $(OBJC_O)
-rm -f libobjc.a
ar rc libobjc.a $(OBJC_O)
ranlib libobjc.a
OBJC_H = hash.h objc-list.h sarray.h objc.h \
objc-api.h \
object.h protocol.h mutex.h \
typedstream.h thread.h
mostlyclean:
-rm -f *.o libobjc.a xforward fflags
clean: mostlyclean
distclean: mostlyclean
extraclean: mostlyclean
/* GNU Objective C Runtime Miscellaneous
Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
GNU CC 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 General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#define __USE_FIXED_PROTOTYPES__
#include <stdlib.h>
#include "runtime.h"
/*
** Error handler function
** NULL so that default is to just print to stderr
*/
static objc_error_handler _objc_error_handler = NULL;
/* Trigger an objc error */
void
objc_error(id object, int code, const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
objc_verror(object, code, fmt, ap);
va_end(ap);
}
/* Trigger an objc error */
void
objc_verror(id object, int code, const char* fmt, va_list ap)
{
BOOL result = NO;
/* Call the error handler if its there
Otherwise print to stderr */
if (_objc_error_handler)
result = (*_objc_error_handler)(object, code, fmt, ap);
else
vfprintf (stderr, fmt, ap);
/* Continue if the error handler says its ok
Otherwise abort the program */
if (result)
return;
else
abort();
}
/* Set the error handler */
objc_error_handler
objc_set_error_handler(objc_error_handler func)
{
objc_error_handler temp = _objc_error_handler;
_objc_error_handler = func;
return temp;
}
/*
** Standard functions for memory allocation and disposal.
** Users should use these functions in their ObjC programs so
** that they work properly with garbage collectors as well as
** can take advantage of the exception/error handling available.
*/
void *
objc_malloc(size_t size)
{
void* res = (void*) (*_objc_malloc)(size);
if(!res)
objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
return res;
}
void *
objc_atomic_malloc(size_t size)
{
void* res = (void*) (*_objc_atomic_malloc)(size);
if(!res)
objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
return res;
}
void *
objc_valloc(size_t size)
{
void* res = (void*) (*_objc_valloc)(size);
if(!res)
objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
return res;
}
void *
objc_realloc(void *mem, size_t size)
{
void* res = (void*) (*_objc_realloc)(mem, size);
if(!res)
objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
return res;
}
void *
objc_calloc(size_t nelem, size_t size)
{
void* res = (void*) (*_objc_calloc)(nelem, size);
if(!res)
objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
return res;
}
void
objc_free(void *mem)
{
(*_objc_free)(mem);
}
/*
** Hook functions for memory allocation and disposal.
** This makes it easy to substitute garbage collection systems
** such as Boehm's GC by assigning these function pointers
** to the GC's allocation routines. By default these point
** to the ANSI standard malloc, realloc, free, etc.
**
** Users should call the normal objc routines above for
** memory allocation and disposal within their programs.
*/
#if OBJC_WITH_GC
#include <gc.h>
static void *GC_calloc (size_t nelem, size_t size)
{
void* p = GC_malloc (nelem * size);
if (!p)
objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted!\n");
memset (p, 0, nelem * size);
return p;
}
static void noFree (void* p) {}
void *(*_objc_malloc)(size_t) = GC_malloc;
void *(*_objc_atomic_malloc)(size_t) = GC_malloc_atomic;
void *(*_objc_valloc)(size_t) = GC_malloc;
void *(*_objc_realloc)(void *, size_t) = GC_realloc;
void *(*_objc_calloc)(size_t, size_t) = GC_calloc;
void (*_objc_free)(void *) = noFree;
#else
void *(*_objc_malloc)(size_t) = malloc;
void *(*_objc_atomic_malloc)(size_t) = malloc;
void *(*_objc_valloc)(size_t) = malloc;
void *(*_objc_realloc)(void *, size_t) = realloc;
void *(*_objc_calloc)(size_t, size_t) = calloc;
void (*_objc_free)(void *) = free;
#endif
/* GNU Objective C Runtime nil receiver function
Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License along with
GNU CC; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
/* This is the nil method, the function that is called when the receiver
of a method is nil */
#include "runtime.h"
id
nil_method(id receiver, SEL op, ...)
{
return receiver;
}
/* Generic single linked list to keep various information
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#ifndef __GNU_OBJC_LIST_H
#define __GNU_OBJC_LIST_H
struct objc_list {
void *head;
struct objc_list *tail;
};
/* Return a cons cell produced from (head . tail) */
static inline struct objc_list*
list_cons(void* head, struct objc_list* tail)
{
struct objc_list* cell;
cell = (struct objc_list*)objc_malloc(sizeof(struct objc_list));
cell->head = head;
cell->tail = tail;
return cell;
}
/* Return the length of a list, list_length(NULL) returns zero */
static inline int
list_length(struct objc_list* list)
{
int i = 0;
while(list)
{
i += 1;
list = list->tail;
}
return i;
}
/* Return the Nth element of LIST, where N count from zero. If N
larger than the list length, NULL is returned */
static inline void*
list_nth(int index, struct objc_list* list)
{
while(index-- != 0)
{
if(list->tail)
list = list->tail;
else
return 0;
}
return list->head;
}
/* Remove the element at the head by replacing it by its successor */
static inline void
list_remove_head(struct objc_list** list)
{
if ((*list)->tail)
{
struct objc_list* tail = (*list)->tail; /* fetch next */
*(*list) = *tail; /* copy next to list head */
objc_free(tail); /* free next */
}
else /* only one element in list */
{
objc_free(*list);
(*list) = 0;
}
}
/* Remove the element with `car' set to ELEMENT */
static inline void
list_remove_elem(struct objc_list** list, void* elem)
{
while (*list) {
if ((*list)->head == elem)
list_remove_head(list);
list = &((*list)->tail);
}
}
/* Map FUNCTION over all elements in LIST */
static inline void
list_mapcar(struct objc_list* list, void(*function)(void*))
{
while(list)
{
(*function)(list->head);
list = list->tail;
}
}
/* Return element that has ELEM as car */
static inline struct objc_list**
list_find(struct objc_list** list, void* elem)
{
while(*list)
{
if ((*list)->head == elem)
return list;
list = &((*list)->tail);
}
return NULL;
}
/* Free list (backwards recursive) */
static void
list_free(struct objc_list* list)
{
if(list)
{
list_free(list->tail);
objc_free(list);
}
}
#endif __GNU_OBJC_LIST_H
/* Basic data types for Objective C.
Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files
compiled with GCC to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#ifndef __objc_INCLUDE_GNU
#define __objc_INCLUDE_GNU
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
/*
** Definition of the boolean type.
*/
#ifdef __vxworks
typedef int BOOL;
#else
typedef unsigned char BOOL;
#endif
#define YES (BOOL)1
#define NO (BOOL)0
/*
** Definition of a selector. Selectors themselves are not unique, but
** the sel_id is a unique identifier.
*/
typedef const struct objc_selector
{
void *sel_id;
const char *sel_types;
} *SEL;
inline static BOOL
sel_eq (SEL s1, SEL s2)
{
if (s1 == 0 || s2 == 0)
return s1 == s2;
else
return s1->sel_id == s2->sel_id;
}
/*
** ObjC uses this typedef for untyped instances.
*/
typedef struct objc_object {
struct objc_class* class_pointer;
} *id;
/*
** Definition of method type. When retrieving the implementation of a
** method, this is type of the pointer returned
*/
typedef id (*IMP)(id, SEL, ...);
/*
** More simple types...
*/
#define nil (id)0 /* id of Nil instance */
#define Nil (Class)0 /* id of Nil class */
typedef char *STR; /* String alias */
/*
** The compiler generates one of these structures for each class.
**
** This structure is the definition for classes.
**
** This structure is generated by the compiler in the executable and used by
** the run-time during normal messaging operations. Therefore some members
** change type. The compiler generates "char* const" and places a string in
** the following member variables: super_class.
*/
typedef struct objc_class *MetaClass;
typedef struct objc_class *Class;
struct objc_class {
MetaClass class_pointer; /* Pointer to the class's
meta class. */
struct objc_class* super_class; /* Pointer to the super
class. NULL for class
Object. */
const char* name; /* Name of the class. */
long version; /* Unknown. */
unsigned long info; /* Bit mask. See class masks
defined above. */
long instance_size; /* Size in bytes of the class.
The sum of the class
definition and all super
class definitions. */
struct objc_ivar_list* ivars; /* Pointer to a structure that
describes the instance
variables in the class
definition. NULL indicates
no instance variables. Does
not include super class
variables. */
struct objc_method_list* methods; /* Linked list of instance
methods defined for the
class. */
struct sarray * dtable; /* Pointer to instance
method dispatch table. */
struct objc_class* subclass_list; /* Subclasses */
struct objc_class* sibling_class;
struct objc_protocol_list *protocols; /* Protocols conformed to */
void* gc_object_type;
};
#ifndef __OBJC__
typedef struct objc_protocol {
struct objc_class* class_pointer;
char *protocol_name;
struct objc_protocol_list *protocol_list;
struct objc_method_description_list *instance_methods, *class_methods;
} Protocol;
#else /* __OBJC__ */
@class Protocol;
#endif
typedef void* retval_t; /* return value */
typedef void(*apply_t)(void); /* function pointer */
typedef union {
char *arg_ptr;
char arg_regs[sizeof (char*)];
} *arglist_t; /* argument frame */
IMP objc_msg_lookup(id receiver, SEL op);
#ifdef __cplusplus
}
#endif
#endif /* not __objc_INCLUDE_GNU */
/* GNU Objective C Runtime class related functions
Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License along with
GNU CC; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include "../tconfig.h" /* include defs of bzero for target */
#include "objc.h"
#include "runtime.h" /* the kitchen sink */
#if OBJC_WITH_GC
# include <gc.h>
#endif
id __objc_object_alloc(Class);
id __objc_object_dispose(id);
id __objc_object_copy(id);
id (*_objc_object_alloc)(Class) = __objc_object_alloc; /* !T:SINGLE */
id (*_objc_object_dispose)(id) = __objc_object_dispose; /* !T:SINGLE */
id (*_objc_object_copy)(id) = __objc_object_copy; /* !T:SINGLE */
id
class_create_instance(Class class)
{
id new = nil;
#if OBJC_WITH_GC
if (CLS_ISCLASS(class))
new = (id)GC_malloc_explicitly_typed (class->instance_size,
class->gc_object_type);
#else
if (CLS_ISCLASS(class))
new = (*_objc_object_alloc)(class);
#endif
if (new!=nil)
{
memset (new, 0, class->instance_size);
new->class_pointer = class;
}
return new;
}
id
object_copy(id object)
{
if ((object!=nil)&&CLS_ISCLASS(object->class_pointer))
return (*_objc_object_copy)(object);
else
return nil;
}
id
object_dispose(id object)
{
if ((object!=nil)&&CLS_ISCLASS(object->class_pointer))
{
if (_objc_object_dispose)
(*_objc_object_dispose)(object);
else
objc_free(object);
}
return nil;
}
id __objc_object_alloc(Class class)
{
return (id)objc_malloc(class->instance_size);
}
id __objc_object_dispose(id object)
{
objc_free(object);
return 0;
}
id __objc_object_copy(id object)
{
id copy = class_create_instance(object->class_pointer);
memcpy(copy, object, object->class_pointer->instance_size);
return copy;
}
/* GNU Objective C Runtime internal declarations
Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License along with
GNU CC; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#ifndef __objc_runtime_INCLUDE_GNU
#define __objc_runtime_INCLUDE_GNU
#include <stdarg.h> /* for varargs and va_list's */
#include <stdio.h>
#include <ctype.h>
#include <stddef.h> /* so noone else will get system versions */
#include "assert.h"
#include "objc/objc.h" /* core data types */
#include "objc/objc-api.h" /* runtime api functions */
#include "objc/thr.h" /* thread and mutex support */
#include "objc/hash.h" /* hash structures */
#include "objc/objc-list.h" /* linear lists */
extern void __objc_add_class_to_hash(Class); /* (objc-class.c) */
extern void __objc_init_selector_tables(); /* (objc-sel.c) */
extern void __objc_init_class_tables(); /* (objc-class.c) */
extern void __objc_init_dispatch_tables(); /* (objc-dispatch.c) */
extern void __objc_install_premature_dtable(Class); /* (objc-dispatch.c) */
extern void __objc_resolve_class_links(); /* (objc-class.c) */
extern void __objc_register_selectors_from_class(Class); /* (objc-sel.c) */
extern void __objc_update_dispatch_table_for_class (Class);/* (objc-msg.c) */
extern int __objc_init_thread_system(void); /* thread.c */
extern int __objc_fini_thread_system(void); /* thread.c */
extern void class_add_method_list(Class, MethodList_t);
/* Registering instance methods as class methods for root classes */
extern void __objc_register_instance_methods_to_class(Class);
extern Method_t search_for_method_in_list(MethodList_t list, SEL op);
/* True when class links has been resolved */
extern BOOL __objc_class_links_resolved;
/* Number of selectors stored in each of the selector tables */
extern int __objc_selector_max_index;
/* Mutex locking __objc_selector_max_index and its arrays. */
extern objc_mutex_t __objc_runtime_mutex;
/* Number of threads which are alive. */
extern int __objc_runtime_threads_alive;
#ifdef DEBUG
#define DEBUG_PRINTF(format, args...) printf (format, ## args)
#else
#define DEBUG_PRINTF(format, args...)
#endif
BOOL __objc_responds_to (id object, SEL sel); /* for internal use only! */
SEL __sel_register_typed_name (const char*, const char*,
struct objc_selector*, BOOL is_const);
#endif /* not __objc_runtime_INCLUDE_GNU */
/* Sparse Arrays for Objective C dispatch tables
Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files
compiled with GCC to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
#ifndef __sarray_INCLUDE_GNU
#define __sarray_INCLUDE_GNU
#define OBJC_SPARSE2 /* 2-level sparse array */
/* #define OBJC_SPARSE3 */ /* 3-level sparse array */
#ifdef OBJC_SPARSE2
extern const char* __objc_sparse2_id;
#endif
#ifdef OBJC_SPARSE3
extern const char* __objc_sparse3_id;
#endif
#include <stddef.h>
#include "objc/thr.h"
extern int nbuckets; /* for stats */
extern int nindices;
extern int narrays;
extern int idxsize;
#include <assert.h>
/* An unsigned integer of same size as a pointer */
#define SIZET_BITS (sizeof(size_t)*8)
#if defined(__sparc__) || defined(OBJC_SPARSE2)
#define PRECOMPUTE_SELECTORS
#endif
#ifdef OBJC_SPARSE3
/* Buckets are 8 words each */
#define BUCKET_BITS 3
#define BUCKET_SIZE (1<<BUCKET_BITS)
#define BUCKET_MASK (BUCKET_SIZE-1)
/* Indices are 16 words each */
#define INDEX_BITS 4
#define INDEX_SIZE (1<<INDEX_BITS)
#define INDEX_MASK (INDEX_SIZE-1)
#define INDEX_CAPACITY (BUCKET_SIZE*INDEX_SIZE)
#else /* OBJC_SPARSE2 */
/* Buckets are 32 words each */
#define BUCKET_BITS 5
#define BUCKET_SIZE (1<<BUCKET_BITS)
#define BUCKET_MASK (BUCKET_SIZE-1)
#endif /* OBJC_SPARSE2 */
typedef size_t sidx;
#ifdef PRECOMPUTE_SELECTORS
struct soffset {
#ifdef OBJC_SPARSE3
unsigned int unused : SIZET_BITS/4;
unsigned int eoffset : SIZET_BITS/4;
unsigned int boffset : SIZET_BITS/4;
unsigned int ioffset : SIZET_BITS/4;
#else /* OBJC_SPARSE2 */
#ifdef __sparc__
unsigned int boffset : (SIZET_BITS - 2) - BUCKET_BITS;
unsigned int eoffset : BUCKET_BITS;
unsigned int unused : 2;
#else
unsigned int boffset : SIZET_BITS/2;
unsigned int eoffset : SIZET_BITS/2;
#endif
#endif /* OBJC_SPARSE2 */
};
union sofftype {
struct soffset off;
sidx idx;
};
#endif /* not PRECOMPUTE_SELECTORS */
union sversion {
int version;
void *next_free;
};
struct sbucket {
void* elems[BUCKET_SIZE]; /* elements stored in array */
union sversion version; /* used for copy-on-write */
};
#ifdef OBJC_SPARSE3
struct sindex {
struct sbucket* buckets[INDEX_SIZE];
union sversion version; /* used for copy-on-write */
};
#endif /* OBJC_SPARSE3 */
struct sarray {
#ifdef OBJC_SPARSE3
struct sindex** indices;
struct sindex* empty_index;
#else /* OBJC_SPARSE2 */
struct sbucket** buckets;
#endif /* OBJC_SPARSE2 */
struct sbucket* empty_bucket;
union sversion version; /* used for copy-on-write */
short ref_count;
struct sarray* is_copy_of;
size_t capacity;
};
struct sarray* sarray_new(int, void* default_element);
void sarray_free(struct sarray*);
struct sarray* sarray_lazy_copy(struct sarray*);
void sarray_realloc(struct sarray*, int new_size);
void sarray_at_put(struct sarray*, sidx index, void* elem);
void sarray_at_put_safe(struct sarray*, sidx index, void* elem);
struct sarray* sarray_hard_copy(struct sarray*); /* ... like the name? */
void sarray_remove_garbage(void);
#ifdef PRECOMPUTE_SELECTORS
/* Transform soffset values to ints and vica verca */
static inline unsigned int
soffset_decode(sidx index)
{
union sofftype x;
x.idx = index;
#ifdef OBJC_SPARSE3
return x.off.eoffset
+ (x.off.boffset*BUCKET_SIZE)
+ (x.off.ioffset*INDEX_CAPACITY);
#else /* OBJC_SPARSE2 */
return x.off.eoffset + (x.off.boffset*BUCKET_SIZE);
#endif /* OBJC_SPARSE2 */
}
static inline sidx
soffset_encode(size_t offset)
{
union sofftype x;
x.off.eoffset = offset%BUCKET_SIZE;
#ifdef OBJC_SPARSE3
x.off.boffset = (offset/BUCKET_SIZE)%INDEX_SIZE;
x.off.ioffset = offset/INDEX_CAPACITY;
#else /* OBJC_SPARSE2 */
x.off.boffset = offset/BUCKET_SIZE;
#endif
return (sidx)x.idx;
}
#else /* not PRECOMPUTE_SELECTORS */
static inline size_t
soffset_decode(sidx index)
{
return index;
}
static inline sidx
soffset_encode(size_t offset)
{
return offset;
}
#endif /* not PRECOMPUTE_SELECTORS */
/* Get element from the Sparse array `array' at offset `index' */
static inline void* sarray_get(struct sarray* array, sidx index)
{
#ifdef PRECOMPUTE_SELECTORS
union sofftype x;
x.idx = index;
#ifdef OBJC_SPARSE3
return
array->
indices[x.off.ioffset]->
buckets[x.off.boffset]->
elems[x.off.eoffset];
#else /* OBJC_SPARSE2 */
return array->buckets[x.off.boffset]->elems[x.off.eoffset];
#endif /* OBJC_SPARSE2 */
#else /* not PRECOMPUTE_SELECTORS */
#ifdef OBJC_SPARSE3
return array->
indices[index/INDEX_CAPACITY]->
buckets[(index/BUCKET_SIZE)%INDEX_SIZE]->
elems[index%BUCKET_SIZE];
#else /* OBJC_SPARSE2 */
return array->buckets[index/BUCKET_SIZE]->elems[index%BUCKET_SIZE];
#endif /* not OBJC_SPARSE3 */
#endif /* not PRECOMPUTE_SELECTORS */
}
static inline void* sarray_get_safe(struct sarray* array, sidx index)
{
if(soffset_decode(index) < array->capacity)
return sarray_get(array, index);
else
return (array->empty_bucket->elems[0]);
}
#endif /* __sarray_INCLUDE_GNU */
/* GNU Objective C Runtime Thread Interface
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License along with
GNU CC; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include <pthread.h>
#include <objc/thr.h>
#include "runtime.h"
/* Key structure for maintaining thread specific storage */
static pthread_key_t _objc_thread_storage;
/* Backend initialization functions */
/* Initialize the threads subsystem. */
int
__objc_init_thread_system(void)
{
/* Initialize the thread storage key */
return pthread_keycreate(&_objc_thread_storage, NULL);
}
/* Close the threads subsystem. */
int
__objc_close_thread_system(void)
{
/* Destroy the thread storage key */
/* Not implemented yet */
/* return pthread_key_delete(&_objc_thread_storage); */
return 0;
}
/* Backend thread functions */
/* Create a new thread of execution. */
objc_thread_t
__objc_thread_detach(void (*func)(void *arg), void *arg)
{
objc_thread_t thread_id;
pthread_t new_thread_handle;
if (pthread_create(&new_thread_handle, pthread_attr_default,
(void *)func, arg) == 0)
{
/* ??? May not work! (64bit) */
thread_id = *(objc_thread_t *)&new_thread_handle;
pthread_detach(&new_thread_handle); /* Fully detach thread. */
}
else
thread_id = NULL;
return thread_id;
}
/* Set the current thread's priority. */
int
__objc_thread_set_priority(int priority)
{
int sys_priority = 0;
switch (priority)
{
case OBJC_THREAD_INTERACTIVE_PRIORITY:
sys_priority = (PRI_FG_MIN_NP + PRI_FG_MAX_NP) / 2;
break;
default:
case OBJC_THREAD_BACKGROUND_PRIORITY:
sys_priority = (PRI_BG_MIN_NP + PRI_BG_MAX_NP) / 2;
break;
case OBJC_THREAD_LOW_PRIORITY:
sys_priority = (PRI_BG_MIN_NP + PRI_BG_MAX_NP) / 2;
break;
}
/* Change the priority. */
if (pthread_setprio(pthread_self(), sys_priority) >= 0)
return 0;
else
/* Failed */
return -1;
}
/* Return the current thread's priority. */
int
__objc_thread_get_priority(void)
{
int sys_priority;
if ((sys_priority = pthread_getprio(pthread_self())) >= 0) {
if (sys_priority >= PRI_FG_MIN_NP && sys_priority <= PRI_FG_MAX_NP)
return OBJC_THREAD_INTERACTIVE_PRIORITY;
if (sys_priority >= PRI_BG_MIN_NP && sys_priority <= PRI_BG_MAX_NP)
return OBJC_THREAD_BACKGROUND_PRIORITY;
return OBJC_THREAD_LOW_PRIORITY;
}
/* Failed */
return -1;
}
/* Yield our process time to another thread. */
void
__objc_thread_yield(void)
{
pthread_yield();
}
/* Terminate the current thread. */
int
__objc_thread_exit(void)
{
/* exit the thread */
pthread_exit(&__objc_thread_exit_status);
/* Failed if we reached here */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
objc_thread_t
__objc_thread_id(void)
{
pthread_t self = pthread_self();
return (objc_thread_t) pthread_getunique_np (&self);
}
/* Sets the thread's local storage pointer. */
int
__objc_thread_set_data(void *value)
{
return pthread_setspecific(_objc_thread_storage, value);
}
/* Returns the thread's local storage pointer. */
void *
__objc_thread_get_data(void)
{
void *value = NULL;
if ( !(pthread_getspecific(_objc_thread_storage, &value)) )
return value;
return NULL;
}
/* Backend mutex functions */
/* Allocate a mutex. */
int
__objc_mutex_allocate(objc_mutex_t mutex)
{
if (pthread_mutex_init((pthread_mutex_t *)(&(mutex->backend)),
pthread_mutexattr_default))
return -1;
else
return 0;
}
/* Deallocate a mutex. */
int
__objc_mutex_deallocate(objc_mutex_t mutex)
{
if (pthread_mutex_destroy((pthread_mutex_t *)(&(mutex->backend))))
return -1;
else
return 0;
}
/* Grab a lock on a mutex. */
int
__objc_mutex_lock(objc_mutex_t mutex)
{
return pthread_mutex_lock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Try to grab a lock on a mutex. */
int
__objc_mutex_trylock(objc_mutex_t mutex)
{
if (pthread_mutex_trylock((pthread_mutex_t *)(&(mutex->backend))) != 1)
return -1;
else
return 0;
}
/* Unlock the mutex */
int
__objc_mutex_unlock(objc_mutex_t mutex)
{
return pthread_mutex_unlock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Backend condition mutex functions */
/* Allocate a condition. */
int
__objc_condition_allocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
if (pthread_cond_init((pthread_cond_t *)(&(condition->backend)), NULL))
return -1;
else
return 0;
*/
}
/* Deallocate a condition. */
int
__objc_condition_deallocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_destroy((pthread_cond_t *)(&(condition->backend)));
*/
}
/* Wait on the condition */
int
__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_wait((pthread_cond_t *)(&(condition->backend)),
(pthread_mutex_t *)(&(mutex->backend)));
*/
}
/* Wake up all threads waiting on this condition. */
int
__objc_condition_broadcast(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_broadcast((pthread_cond_t *)(&(condition->backend)));
*/
}
/* Wake up one thread waiting on this condition. */
int
__objc_condition_signal(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_signal((pthread_cond_t *)(&(condition->backend)));
*/
}
/* End of File */
/* GNU Objective C Runtime Thread Interface
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License along with
GNU CC; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include <pthread.h>
#include <objc/thr.h>
#include "runtime.h"
/* Key structure for maintiain thread specific storage */
static pthread_key_t _objc_thread_storage;
/* Backend initialization functions */
/* Initialize the threads subsystem. */
int
__objc_init_thread_system(void)
{
/* Initialize the thread storage key */
return pthread_keycreate(&_objc_thread_storage, NULL);
}
/* Close the threads subsystem. */
int
__objc_close_thread_system(void)
{
/* Destroy the thread storage key */
/* Not implemented yet */
/* return pthread_key_delete(&_objc_thread_storage); */
return 0;
}
/* Backend thread functions */
/* Create a new thread of execution. */
objc_thread_t
__objc_thread_detach(void (*func)(void *arg), void *arg)
{
objc_thread_t thread_id;
pthread_t new_thread_handle;
if (pthread_create(&new_thread_handle, pthread_attr_default,
(void *)func, arg) == 0)
{
/* ??? May not work! (64bit) */
thread_id = *(objc_thread_t *)&new_thread_handle;
pthread_detach(&new_thread_handle); /* Fully detach thread. */
}
else
thread_id = NULL;
return thread_id;
}
/* Set the current thread's priority. */
int
__objc_thread_set_priority(int priority)
{
int sys_priority = 0;
switch (priority)
{
case OBJC_THREAD_INTERACTIVE_PRIORITY:
sys_priority = (PRI_FG_MIN_NP + PRI_FG_MAX_NP) / 2;
break;
default:
case OBJC_THREAD_BACKGROUND_PRIORITY:
sys_priority = (PRI_BG_MIN_NP + PRI_BG_MAX_NP) / 2;
break;
case OBJC_THREAD_LOW_PRIORITY:
sys_priority = (PRI_BG_MIN_NP + PRI_BG_MAX_NP) / 2;
break;
}
/* Change the priority. */
if (pthread_setprio(pthread_self(), sys_priority) >= 0)
return 0;
else
/* Failed */
return -1;
}
/* Return the current thread's priority. */
int
__objc_thread_get_priority(void)
{
int sys_priority;
if ((sys_priority = pthread_getprio(pthread_self())) >= 0) {
if (sys_priority >= PRI_FG_MIN_NP && sys_priority <= PRI_FG_MAX_NP)
return OBJC_THREAD_INTERACTIVE_PRIORITY;
if (sys_priority >= PRI_BG_MIN_NP && sys_priority <= PRI_BG_MAX_NP)
return OBJC_THREAD_BACKGROUND_PRIORITY;
return OBJC_THREAD_LOW_PRIORITY;
}
/* Failed */
return -1;
}
/* Yield our process time to another thread. */
void
__objc_thread_yield(void)
{
pthread_yield();
}
/* Terminate the current thread. */
int
__objc_thread_exit(void)
{
/* exit the thread */
pthread_exit(&__objc_thread_exit_status);
/* Failed if we reached here */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
objc_thread_t
__objc_thread_id(void)
{
pthread_t self = pthread_self();
return (objc_thread_t) pthread_getuniqe_np (&self);
}
/* Sets the thread's local storage pointer. */
int
__objc_thread_set_data(void *value)
{
return pthread_setspecific(_objc_thread_storage, value);
}
/* Returns the thread's local storage pointer. */
void *
__objc_thread_get_data(void)
{
void *value = NULL;
if ( !(pthread_getspecific(_objc_thread_storage, &value)) )
return value;
return NULL;
}
/* Backend mutex functions */
/* Allocate a mutex. */
int
__objc_mutex_allocate(objc_mutex_t mutex)
{
if (pthread_mutex_init((pthread_mutex_t *)(&(mutex->backend)),
pthread_mutexattr_default))
return -1;
else
return 0;
}
/* Deallocate a mutex. */
int
__objc_mutex_deallocate(objc_mutex_t mutex)
{
if (pthread_mutex_destroy((pthread_mutex_t *)(&(mutex->backend))))
return -1;
else
return 0;
}
/* Grab a lock on a mutex. */
int
__objc_mutex_lock(objc_mutex_t mutex)
{
return pthread_mutex_lock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Try to grab a lock on a mutex. */
int
__objc_mutex_trylock(objc_mutex_t mutex)
{
if (pthread_mutex_trylock((pthread_mutex_t *)(&(mutex->backend))) != 1)
return -1;
else
return 0;
}
/* Unlock the mutex */
int
__objc_mutex_unlock(objc_mutex_t mutex)
{
return pthread_mutex_unlock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Backend condition mutex functions */
/* Allocate a condition. */
int
__objc_condition_allocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
if (pthread_cond_init((pthread_cond_t *)(&(condition->backend)), NULL))
return -1;
else
return 0;
*/
}
/* Deallocate a condition. */
int
__objc_condition_deallocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_destroy((pthread_cond_t *)(&(condition->backend)));
*/
}
/* Wait on the condition */
int
__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_wait((pthread_cond_t *)(&(condition->backend)),
(pthread_mutex_t *)(&(mutex->backend)));
*/
}
/* Wake up all threads waiting on this condition. */
int
__objc_condition_broadcast(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_broadcast((pthread_cond_t *)(&(condition->backend)));
*/
}
/* Wake up one thread waiting on this condition. */
int
__objc_condition_signal(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_signal((pthread_cond_t *)(&(condition->backend)));
*/
}
/* End of File */
/* GNU Objective C Runtime Thread Interface - SGI IRIX Implementation
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License along with
GNU CC; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include <stdlib.h>
#include <sys/types.h>
#include <sys/sysmp.h>
#include <sys/prctl.h>
#include <ulocks.h>
#include <objc/thr.h>
#include "runtime.h"
/* Key structure for maintiain thread specific storage */
static void * __objc_shared_arena_handle = NULL;
/* Backend initialization functions */
/* Initialize the threads subsystem. */
int
__objc_init_thread_system(void)
{
/* Name of IRIX arena. */
char arena_name[64];
DEBUG_PRINTF("__objc_init_thread_system\n");
/* Construct a temporary name for arena. */
sprintf(arena_name, "/usr/tmp/objc_%05u", (unsigned)getpid());
/* Up to 256 threads. Arena only for threads. */
usconfig(CONF_INITUSERS, 256);
usconfig(CONF_ARENATYPE, US_SHAREDONLY);
/* Initialize the arena */
if (!(__objc_shared_arena_handle = usinit(arena_name)))
/* Failed */
return -1;
return 0;
}
/* Close the threads subsystem. */
int
__objc_close_thread_system(void)
{
return 0;
}
/* Backend thread functions */
/* Create a new thread of execution. */
objc_thread_t
__objc_thread_detach(void (*func)(void *arg), void *arg)
{
objc_thread_t thread_id;
int sys_id;
if ((sys_id = sproc((void *)func, PR_SALL, arg)) >= 0)
thread_id = (objc_thread_t)sys_id;
else
thread_id = NULL;
return thread_id;
}
/* Set the current thread's priority. */
int
__objc_thread_set_priority(int priority)
{
/* Not implemented yet */
return -1;
}
/* Return the current thread's priority. */
int
__objc_thread_get_priority(void)
{
/* Not implemented yet */
return OBJC_THREAD_INTERACTIVE_PRIORITY;
}
/* Yield our process time to another thread. */
void
__objc_thread_yield(void)
{
sginap(0);
}
/* Terminate the current thread. */
int
__objc_thread_exit(void)
{
/* IRIX only has exit. */
exit(__objc_thread_exit_status);
/* Failed if we reached here */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
objc_thread_t
__objc_thread_id(void)
{
/* Threads are processes. */
return (objc_thread_t)get_pid();
}
/* Sets the thread's local storage pointer. */
int
__objc_thread_set_data(void *value)
{
*((void **)&PRDA->usr_prda) = value;
return 0;
}
/* Returns the thread's local storage pointer. */
void *
__objc_thread_get_data(void)
{
return *((void **)&PRDA->usr_prda);
}
/* Backend mutex functions */
/* Allocate a mutex. */
int
__objc_mutex_allocate(objc_mutex_t mutex)
{
if (!( (ulock_t)(mutex->backend) = usnewlock(__objc_shared_arena_handle) ))
return -1;
else
return 0;
}
/* Deallocate a mutex. */
int
__objc_mutex_deallocate(objc_mutex_t mutex)
{
usfreelock((ulock_t)(mutex->backend), __objc_shared_arena_handle);
return 0;
}
/* Grab a lock on a mutex. */
int
__objc_mutex_lock(objc_mutex_t mutex)
{
if (ussetlock((ulock_t)(mutex->backend)) == 0)
return -1;
else
return 0;
}
/* Try to grab a lock on a mutex. */
int
__objc_mutex_trylock(objc_mutex_t mutex)
{
if (ustestlock((ulock_t)(mutex->backend)) == 0)
return -1;
else
return 0;
}
/* Unlock the mutex */
int
__objc_mutex_unlock(objc_mutex_t mutex)
{
usunsetlock((ulock_t)(mutex->backend));
return 0;
}
/* Backend condition mutex functions */
/* Allocate a condition. */
int
__objc_condition_allocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
/* Deallocate a condition. */
int
__objc_condition_deallocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
/* Wait on the condition */
int
__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
/* Unimplemented. */
return -1;
}
/* Wake up all threads waiting on this condition. */
int
__objc_condition_broadcast(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
/* Wake up one thread waiting on this condition. */
int
__objc_condition_signal(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
/* End of File */
/* GNU Objective C Runtime Thread Implementation
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
Modified for Mach threads by Bill Bumgarner <bbum@friday.com>
Condition functions added by Mircea Oancea <mircea@first.elcom.pub.ro>
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include <mach/mach.h>
#include <mach/cthreads.h>
#include <objc/thr.h>
#include "runtime.h"
/*
Obtain the maximum thread priority that can set for t. Under the
mach threading model, it is possible for the developer to adjust the
maximum priority downward only-- cannot be raised without superuser
priviledges. Once lowered, it cannot be raised.
*/
static int __mach_get_max_thread_priority(cthread_t t, int *base)
{
thread_t threadP;
kern_return_t error;
struct thread_sched_info info;
unsigned int info_count=THREAD_SCHED_INFO_COUNT;
if (t == NULL)
return -1;
threadP = cthread_thread(t); /* get thread underlying */
error=thread_info(threadP, THREAD_SCHED_INFO,
(thread_info_t)&info, &info_count);
if (error != KERN_SUCCESS)
return -1;
if (base != NULL)
*base = info.base_priority;
return info.max_priority;
}
/* Backend initialization functions */
/* Initialize the threads subsystem. */
int
__objc_init_thread_system(void)
{
return 0;
}
/* Close the threads subsystem. */
int
__objc_close_thread_system(void)
{
return 0;
}
/* Backend thread functions */
/* Create a new thread of execution. */
objc_thread_t
__objc_thread_detach(void (*func)(void *arg), void *arg)
{
objc_thread_t thread_id;
cthread_t new_thread_handle;
/* create thread */
new_thread_handle = cthread_fork((cthread_fn_t)func, arg);
if(new_thread_handle)
{
/* this is not terribly portable */
thread_id = *(objc_thread_t *)&new_thread_handle;
cthread_detach(new_thread_handle);
}
else
thread_id = NULL;
return thread_id;
}
/* Set the current thread's priority. */
int
__objc_thread_set_priority(int priority)
{
objc_thread_t *t = objc_thread_id();
cthread_t cT = (cthread_t) t;
int maxPriority = __mach_get_max_thread_priority(cT, NULL);
int sys_priority = 0;
if (maxPriority == -1)
return -1;
switch (priority)
{
case OBJC_THREAD_INTERACTIVE_PRIORITY:
sys_priority = maxPriority;
break;
case OBJC_THREAD_BACKGROUND_PRIORITY:
sys_priority = (maxPriority * 2) / 3;
break;
case OBJC_THREAD_LOW_PRIORITY:
sys_priority = maxPriority / 3;
break;
default:
return -1;
}
if (sys_priority == 0)
return -1;
/* Change the priority */
if (cthread_priority(cT, sys_priority, 0) == KERN_SUCCESS)
return 0;
else
return -1;
}
/* Return the current thread's priority. */
int
__objc_thread_get_priority(void)
{
objc_thread_t *t = objc_thread_id();
cthread_t cT = (cthread_t) t; /* see objc_thread_id() */
int basePriority;
int maxPriority;
int sys_priority = 0;
int interactiveT, backgroundT, lowT; /* threasholds */
maxPriority = __mach_get_max_thread_priority(cT, &basePriority);
if(maxPriority == -1)
return -1;
if (basePriority > ( (maxPriority * 2) / 3))
return OBJC_THREAD_INTERACTIVE_PRIORITY;
if (basePriority > ( maxPriority / 3))
return OBJC_THREAD_BACKGROUND_PRIORITY;
return OBJC_THREAD_LOW_PRIORITY;
}
/* Yield our process time to another thread. */
void
__objc_thread_yield(void)
{
cthread_yield();
}
/* Terminate the current thread. */
int
__objc_thread_exit(void)
{
/* exit the thread */
cthread_exit(&__objc_thread_exit_status);
/* Failed if we reached here */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
objc_thread_t
__objc_thread_id(void)
{
cthread_t self = cthread_self();
return *(objc_thread_t *)&self;
}
/* Sets the thread's local storage pointer. */
int
__objc_thread_set_data(void *value)
{
cthread_set_data(cthread_self(), (any_t) value);
return 0;
}
/* Returns the thread's local storage pointer. */
void *
__objc_thread_get_data(void)
{
return (void *) cthread_data(cthread_self());
}
/* Backend mutex functions */
/* Allocate a mutex. */
int
__objc_mutex_allocate(objc_mutex_t mutex)
{
int err = 0;
mutex->backend = objc_malloc(sizeof(struct mutex));
err = mutex_init((mutex_t)(mutex->backend));
if (err != 0)
{
objc_free(mutex->backend);
return -1;
}
else
return 0;
}
/* Deallocate a mutex. */
int
__objc_mutex_deallocate(objc_mutex_t mutex)
{
mutex_clear((mutex_t)(mutex->backend));
objc_free(mutex->backend);
mutex->backend = NULL;
return 0;
}
/* Grab a lock on a mutex. */
int
__objc_mutex_lock(objc_mutex_t mutex)
{
mutex_lock((mutex_t)(mutex->backend));
return 0;
}
/* Try to grab a lock on a mutex. */
int
__objc_mutex_trylock(objc_mutex_t mutex)
{
if (mutex_try_lock((mutex_t)(mutex->backend)) == 0)
return -1;
else
return 0;
}
/* Unlock the mutex */
int
__objc_mutex_unlock(objc_mutex_t mutex)
{
mutex_unlock((mutex_t)(mutex->backend));
return 0;
}
/* Backend condition mutex functions */
/* Allocate a condition. */
int
__objc_condition_allocate(objc_condition_t condition)
{
condition->backend = objc_malloc(sizeof(struct condition));
condition_init((condition_t)(condition->backend));
return 0;
}
/* Deallocate a condition. */
int
__objc_condition_deallocate(objc_condition_t condition)
{
condition_clear((condition_t)(condition->backend));
objc_free(condition->backend);
condition->backend = NULL;
return 0;
}
/* Wait on the condition */
int
__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
condition_wait((condition_t)(condition->backend),
(mutex_t)(mutex->backend));
return 0;
}
/* Wake up all threads waiting on this condition. */
int
__objc_condition_broadcast(objc_condition_t condition)
{
condition_broadcast((condition_t)(condition->backend));
return 0;
}
/* Wake up one thread waiting on this condition. */
int
__objc_condition_signal(objc_condition_t condition)
{
condition_signal((condition_t)(condition->backend));
return 0;
}
/* End of File */
/* GNU Objective C Runtime Thread Interface - OS/2 emx Implementation
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
Contributed by Thomas Baier (baier@ci.tuwien.ac.at)
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include <objc/thr.h>
#include "runtime.h"
#define INCL_DOSSEMAPHORES
#define INCL_DOSPROCESS
/*
* conflicts with objc.h: SEL, BOOL, id
* solution: prefixing those with _OS2_ before including <os2.h>
*/
#define SEL _OS2_SEL
#define BOOL _OS2_BOOL
#define id _OS2_id
#include <os2.h>
#undef id
#undef SEL
#undef BOOL
#include <stdlib.h>
/* Backend initialization functions */
/* Initialize the threads subsystem. */
int
__objc_init_thread_system(void)
{
return 0;
}
/* Close the threads subsystem. */
int
__objc_close_thread_system(void)
{
return 0;
}
/* Backend thread functions */
/* Create a new thread of execution. */
objc_thread_t
__objc_thread_detach(void (*func)(void *arg), void *arg)
{
int thread_id = 0;
if ((thread_id = _beginthread (func,NULL,32768,arg)) < 0)
thread_id = 0;
return (objc_thread_t)thread_id;
}
/* Set the current thread's priority. */
int
__objc_thread_set_priority(int priority)
{
ULONG sys_class = 0;
ULONG sys_priority = 0;
/* OBJC_THREAD_INTERACTIVE_PRIORITY -> PRTYC_FOREGROUNDSERVER
* OBJC_THREAD_BACKGROUND_PRIORITY -> PRTYC_REGULSR
* OBJC_THREAD_LOW_PRIORITY -> PRTYC_IDLETIME */
switch (priority) {
case OBJC_THREAD_INTERACTIVE_PRIORITY:
sys_class = PRTYC_REGULAR;
sys_priority = 10;
break;
default:
case OBJC_THREAD_BACKGROUND_PRIORITY:
sys_class = PRTYC_IDLETIME;
sys_priority = 25;
break;
case OBJC_THREAD_LOW_PRIORITY:
sys_class = PRTYC_IDLETIME;
sys_priority = 0;
break;
}
/* Change priority */
if (!DosSetPriority (PRTYS_THREAD,sys_class,sys_priority,*_threadid))
return 0;
else
return -1;
}
/* Return the current thread's priority. */
int
__objc_thread_get_priority(void)
{
PTIB ptib;
PPIB ppib;
/* get information about current thread */
DosGetInfoBlocks (&ptib,&ppib);
switch (ptib->tib_ptib2->tib2_ulpri)
{
case PRTYC_IDLETIME:
case PRTYC_REGULAR:
case PRTYC_TIMECRITICAL:
case PRTYC_FOREGROUNDSERVER:
default:
return OBJC_THREAD_INTERACTIVE_PRIORITY;
}
return -1;
}
/* Yield our process time to another thread. */
void
__objc_thread_yield(void)
{
DosSleep (0);
}
/* Terminate the current thread. */
int
__objc_thread_exit(void)
{
/* terminate the thread, NEVER use DosExit () */
_endthread ();
/* Failed if we reached here */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
objc_thread_t
__objc_thread_id(void)
{
return (objc_thread_t) *_threadid;
}
/* Sets the thread's local storage pointer. */
int
__objc_thread_set_data(void *value)
{
*_threadstore () = value;
return 0;
}
/* Returns the thread's local storage pointer. */
void *
__objc_thread_get_data(void)
{
return *_threadstore ();
}
/* Backend mutex functions */
/* Allocate a mutex. */
int
__objc_mutex_allocate(objc_mutex_t mutex)
{
if (DosCreateMutexSem (NULL, (HMTX)(&(mutex->backend)),0L,0) > 0)
return -1;
else
return 0;
}
/* Deallocate a mutex. */
int
__objc_mutex_deallocate(objc_mutex_t mutex)
{
DosCloseMutexSem ((HMTX)(mutex->backend));
return 0;
}
/* Grab a lock on a mutex. */
int
__objc_mutex_lock(objc_mutex_t mutex)
{
if (DosRequestMutexSem ((HMTX)(mutex->backend),-1L) != 0)
return -1;
else
return 0;
}
/* Try to grab a lock on a mutex. */
int
__objc_mutex_trylock(objc_mutex_t mutex)
{
if (DosRequestMutexSem ((HMTX)(mutex->backend),0L) != 0)
return -1;
else
return 0;
}
/* Unlock the mutex */
int
__objc_mutex_unlock(objc_mutex_t mutex)
{
if (DosReleaseMutexSem((HMTX)(mutex->backend)) != 0)
return -1;
else
return 0;
}
/* Backend condition mutex functions */
/* Allocate a condition. */
int
__objc_condition_allocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
/* Deallocate a condition. */
int
__objc_condition_deallocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
/* Wait on the condition */
int
__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
/* Unimplemented. */
return -1;
}
/* Wake up all threads waiting on this condition. */
int
__objc_condition_broadcast(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
/* Wake up one thread waiting on this condition. */
int
__objc_condition_signal(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
/* End of File */
/* GNU Objective C Runtime Thread Interface for POSIX compliant threads
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
Modified for Linux/Pthreads by Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de)
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include <objc/thr.h>
#include "runtime.h"
#include <pthread.h>
/* Key structure for maintiain thread specific storage */
static pthread_key_t _objc_thread_storage;
/* Backend initialization functions */
/* Initialize the threads subsystem. */
int
__objc_init_thread_system(void)
{
/* Initialize the thread storage key */
return pthread_key_create(&_objc_thread_storage, NULL);
}
/* Close the threads subsystem. */
int
__objc_close_thread_system(void)
{
return 0;
}
/* Backend thread functions */
/* Create a new thread of execution. */
objc_thread_t
__objc_thread_detach(void (*func)(void *arg), void *arg)
{
objc_thread_t thread_id;
pthread_t new_thread_handle;
if ( !(pthread_create(&new_thread_handle, NULL, (void *)func, arg)) )
thread_id = *(objc_thread_t *)&new_thread_handle;
else
thread_id = NULL;
return thread_id;
}
/* Set the current thread's priority. */
int
__objc_thread_set_priority(int priority)
{
/* Not implemented yet */
return -1;
}
/* Return the current thread's priority. */
int
__objc_thread_get_priority(void)
{
/* Not implemented yet */
return -1;
}
/* Yield our process time to another thread. */
void
__objc_thread_yield(void)
{
sched_yield();
}
/* Terminate the current thread. */
int
__objc_thread_exit(void)
{
/* exit the thread */
pthread_exit(&__objc_thread_exit_status);
/* Failed if we reached here */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
objc_thread_t
__objc_thread_id(void)
{
pthread_t self = pthread_self();
return *(objc_thread_t *)&self;
}
/* Sets the thread's local storage pointer. */
int
__objc_thread_set_data(void *value)
{
return pthread_setspecific(_objc_thread_storage, value);
}
/* Returns the thread's local storage pointer. */
void *
__objc_thread_get_data(void)
{
return pthread_getspecific(_objc_thread_storage);
}
/* Backend mutex functions */
/* Allocate a mutex. */
int
__objc_mutex_allocate(objc_mutex_t mutex)
{
if (pthread_mutex_init((pthread_mutex_t *)(&(mutex->backend)), NULL))
return -1;
else
return 0;
}
/* Deallocate a mutex. */
int
__objc_mutex_deallocate(objc_mutex_t mutex)
{
if (pthread_mutex_destroy((pthread_mutex_t *)(&(mutex->backend))))
return -1;
else
return 0;
}
/* Grab a lock on a mutex. */
int
__objc_mutex_lock(objc_mutex_t mutex)
{
return pthread_mutex_lock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Try to grab a lock on a mutex. */
int
__objc_mutex_trylock(objc_mutex_t mutex)
{
return pthread_mutex_trylock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Unlock the mutex */
int
__objc_mutex_unlock(objc_mutex_t mutex)
{
return pthread_mutex_unlock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Backend condition mutex functions */
/* Allocate a condition. */
int
__objc_condition_allocate(objc_condition_t condition)
{
if (pthread_cond_init((pthread_cond_t *)(&(condition->backend)), NULL))
return -1;
else
return 0;
}
/* Deallocate a condition. */
int
__objc_condition_deallocate(objc_condition_t condition)
{
return pthread_cond_destroy((pthread_cond_t *)(&(condition->backend)));
}
/* Wait on the condition */
int
__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
return pthread_cond_wait((pthread_cond_t *)(&(condition->backend)),
(pthread_mutex_t *)(&(mutex->backend)));
}
/* Wake up all threads waiting on this condition. */
int
__objc_condition_broadcast(objc_condition_t condition)
{
return pthread_cond_broadcast((pthread_cond_t *)(&(condition->backend)));
}
/* Wake up one thread waiting on this condition. */
int
__objc_condition_signal(objc_condition_t condition)
{
return pthread_cond_signal((pthread_cond_t *)(&(condition->backend)));
}
/* End of File */
/* GNU Objective C Runtime Thread Implementation for PCThreads under Linux.
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
Contributed by Scott Christley <scottc@net-community.com>
Condition functions added by: Mircea Oancea <mircea@first.elcom.pub.ro>
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include <pcthread.h>
#include <objc/thr.h>
#include "runtime.h"
/* Key structure for maintiain thread specific storage */
static pthread_key_t _objc_thread_storage;
/* Backend initialization functions */
/* Initialize the threads subsystem. */
int
__objc_init_thread_system(void)
{
/* Initialize the thread storage key */
return pthread_key_create(&_objc_thread_storage, NULL);
}
/* Close the threads subsystem. */
int
__objc_close_thread_system(void)
{
/* Destroy the thread storage key */
/* Not implemented yet */
/* return pthread_key_delete(&_objc_thread_storage); */
return 0;
}
/* Backend thread functions */
/* Create a new thread of execution. */
objc_thread_t
__objc_thread_detach(void (*func)(void *arg), void *arg)
{
objc_thread_t thread_id;
pthread_t new_thread_handle;
if ( !(pthread_create(&new_thread_handle, NULL, (void *)func, arg)) )
thread_id = *(objc_thread_t *)&new_thread_handle;
else
thread_id = NULL;
return thread_id;
}
/* Set the current thread's priority. */
int
__objc_thread_set_priority(int priority)
{
/* Not implemented yet */
return -1;
}
/* Return the current thread's priority. */
int
__objc_thread_get_priority(void)
{
/* Not implemented yet */
return OBJC_THREAD_INTERACTIVE_PRIORITY;
}
/* Yield our process time to another thread. */
void
__objc_thread_yield(void)
{
pthread_yield(NULL);
}
/* Terminate the current thread. */
int
__objc_thread_exit(void)
{
/* exit the thread */
pthread_exit(&__objc_thread_exit_status);
/* Failed if we reached here */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
objc_thread_t
__objc_thread_id(void)
{
pthread_t self = pthread_self();
return *(objc_thread_t *)&self;
}
/* Sets the thread's local storage pointer. */
int
__objc_thread_set_data(void *value)
{
return pthread_setspecific(_objc_thread_storage, value);
}
/* Returns the thread's local storage pointer. */
void *
__objc_thread_get_data(void)
{
void *value = NULL;
if ( !(pthread_getspecific(_objc_thread_storage, &value)) )
return value;
return NULL;
}
/* Backend mutex functions */
/* Allocate a mutex. */
int
__objc_mutex_allocate(objc_mutex_t mutex)
{
if (pthread_mutex_init((pthread_mutex_t *)(&(mutex->backend)), NULL))
return -1;
else
return 0;
}
/* Deallocate a mutex. */
int
__objc_mutex_deallocate(objc_mutex_t mutex)
{
if (pthread_mutex_destroy((pthread_mutex_t *)(&(mutex->backend))))
return -1;
else
return 0;
}
/* Grab a lock on a mutex. */
int
__objc_mutex_lock(objc_mutex_t mutex)
{
return pthread_mutex_lock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Try to grab a lock on a mutex. */
int
__objc_mutex_trylock(objc_mutex_t mutex)
{
return pthread_mutex_trylock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Unlock the mutex */
int
__objc_mutex_unlock(objc_mutex_t mutex)
{
return pthread_mutex_unlock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Backend condition mutex functions */
/* Allocate a condition. */
int
__objc_condition_allocate(objc_condition_t condition)
{
if (pthread_cond_init((pthread_cond_t *)(&(condition->backend)), NULL))
return -1;
else
return 0;
}
/* Deallocate a condition. */
int
__objc_condition_deallocate(objc_condition_t condition)
{
return pthread_cond_destroy((pthread_cond_t *)(&(condition->backend)));
}
/* Wait on the condition */
int
__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
return pthread_cond_wait((pthread_cond_t *)(&(condition->backend)),
(pthread_mutex_t *)(&(mutex->backend)));
}
/* Wake up all threads waiting on this condition. */
int
__objc_condition_broadcast(objc_condition_t condition)
{
return pthread_cond_broadcast((pthread_cond_t *)(&(condition->backend)));
}
/* Wake up one thread waiting on this condition. */
int
__objc_condition_signal(objc_condition_t condition)
{
return pthread_cond_signal((pthread_cond_t *)(&(condition->backend)));
}
/* End of File */
/* GNU Objective C Runtime Thread Implementation
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License along with
GNU CC; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include <objc/thr.h>
#include "runtime.h"
/* Thread local storage for a single thread */
static void *thread_local_storage = NULL;
/* Backend initialization functions */
/* Initialize the threads subsystem. */
int
__objc_init_thread_system(void)
{
/* No thread support available */
return -1;
}
/* Close the threads subsystem. */
int
__objc_close_thread_system(void)
{
/* No thread support available */
return -1;
}
/* Backend thread functions */
/* Create a new thread of execution. */
objc_thread_t
__objc_thread_detach(void (*func)(void *arg), void *arg)
{
/* No thread support available */
return NULL;
}
/* Set the current thread's priority. */
int
__objc_thread_set_priority(int priority)
{
/* No thread support available */
return -1;
}
/* Return the current thread's priority. */
int
__objc_thread_get_priority(void)
{
return OBJC_THREAD_INTERACTIVE_PRIORITY;
}
/* Yield our process time to another thread. */
void
__objc_thread_yield(void)
{
return;
}
/* Terminate the current thread. */
int
__objc_thread_exit(void)
{
/* No thread support available */
/* Should we really exit the program */
/* exit(&__objc_thread_exit_status); */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
objc_thread_t
__objc_thread_id(void)
{
/* No thread support, use 1. */
return (objc_thread_t)1;
}
/* Sets the thread's local storage pointer. */
int
__objc_thread_set_data(void *value)
{
thread_local_storage = value;
return 0;
}
/* Returns the thread's local storage pointer. */
void *
__objc_thread_get_data(void)
{
return thread_local_storage;
}
/* Backend mutex functions */
/* Allocate a mutex. */
int
__objc_mutex_allocate(objc_mutex_t mutex)
{
return 0;
}
/* Deallocate a mutex. */
int
__objc_mutex_deallocate(objc_mutex_t mutex)
{
return 0;
}
/* Grab a lock on a mutex. */
int
__objc_mutex_lock(objc_mutex_t mutex)
{
/* There can only be one thread, so we always get the lock */
return 0;
}
/* Try to grab a lock on a mutex. */
int
__objc_mutex_trylock(objc_mutex_t mutex)
{
/* There can only be one thread, so we always get the lock */
return 0;
}
/* Unlock the mutex */
int
__objc_mutex_unlock(objc_mutex_t mutex)
{
return 0;
}
/* Backend condition mutex functions */
/* Allocate a condition. */
int
__objc_condition_allocate(objc_condition_t condition)
{
return 0;
}
/* Deallocate a condition. */
int
__objc_condition_deallocate(objc_condition_t condition)
{
return 0;
}
/* Wait on the condition */
int
__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
return 0;
}
/* Wake up all threads waiting on this condition. */
int
__objc_condition_broadcast(objc_condition_t condition)
{
return 0;
}
/* Wake up one thread waiting on this condition. */
int
__objc_condition_signal(objc_condition_t condition)
{
return 0;
}
/* End of File */
/* GNU Objective C Runtime Thread Interface
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
Conditions added by Mircea Oancea (mircea@first.elcom.pub.ro)
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU CC 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 General Public License for more
details.
You should have received a copy of the GNU General Public License along with
GNU CC; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include <objc/thr.h>
#include "runtime.h"
#include <thread.h>
#include <synch.h>
#include <errno.h>
/* Key structure for maintiain thread specific storage */
static thread_key_t __objc_thread_data_key;
/* Backend initialization functions */
/* Initialize the threads subsystem. */
int
__objc_init_thread_system(void)
{
/* Initialize the thread storage key */
if (thr_keycreate(&__objc_thread_data_key, NULL) == 0)
return 0;
else
return -1;
}
/* Close the threads subsystem. */
int
__objc_close_thread_system(void)
{
return 0;
}
/* Backend thread functions */
/* Create a new thread of execution. */
objc_thread_t
__objc_thread_detach(void (*func)(void *arg), void *arg)
{
objc_thread_t thread_id;
thread_t new_thread_id = 0;
if (thr_create(NULL, 0, (void *)func, arg,
THR_DETACHED | THR_NEW_LWP,
&new_thread_id) == 0)
thread_id = *(objc_thread_t *)&new_thread_id;
else
thread_id = NULL;
return thread_id;
}
/* Set the current thread's priority. */
int
__objc_thread_set_priority(int priority)
{
int sys_priority = 0;
switch (priority)
{
case OBJC_THREAD_INTERACTIVE_PRIORITY:
sys_priority = 300;
break;
default:
case OBJC_THREAD_BACKGROUND_PRIORITY:
sys_priority = 200;
break;
case OBJC_THREAD_LOW_PRIORITY:
sys_priority = 1000;
break;
}
/* Change priority */
if (thr_setprio(thr_self(), sys_priority) == 0)
return 0;
else
return -1;
}
/* Return the current thread's priority. */
int
__objc_thread_get_priority(void)
{
int sys_priority;
if (thr_getprio(thr_self(), &sys_priority) == 0)
{
if (sys_priority >= 250)
return OBJC_THREAD_INTERACTIVE_PRIORITY;
else if (sys_priority >= 150)
return OBJC_THREAD_BACKGROUND_PRIORITY;
return OBJC_THREAD_LOW_PRIORITY;
}
/* Couldn't get priority. */
return -1;
}
/* Yield our process time to another thread. */
void
__objc_thread_yield(void)
{
thr_yield();
}
/* Terminate the current thread. */
int
__objc_thread_exit(void)
{
/* exit the thread */
thr_exit(&__objc_thread_exit_status);
/* Failed if we reached here */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
objc_thread_t
__objc_thread_id(void)
{
return (objc_thread_t)thr_self();
}
/* Sets the thread's local storage pointer. */
int
__objc_thread_set_data(void *value)
{
if (thr_setspecific(__objc_thread_data_key, value) == 0)
return 0;
else
return -1;
}
/* Returns the thread's local storage pointer. */
void *
__objc_thread_get_data(void)
{
void *value = NULL;
if (thr_getspecific(__objc_thread_data_key, &value) == 0)
return value;
return NULL;
}
/* Backend mutex functions */
/* Allocate a mutex. */
int
__objc_mutex_allocate(objc_mutex_t mutex)
{
if (mutex_init( (mutex_t *)(&(mutex->backend)), USYNC_THREAD, 0))
return -1;
else
return 0;
}
/* Deallocate a mutex. */
int
__objc_mutex_deallocate(objc_mutex_t mutex)
{
mutex_destroy((mutex_t *)(&(mutex->backend)));
return 0;
}
/* Grab a lock on a mutex. */
int
__objc_mutex_lock(objc_mutex_t mutex)
{
if (mutex_lock((mutex_t *)(&(mutex->backend))) != 0)
return -1;
else
return 0;
}
/* Try to grab a lock on a mutex. */
int
__objc_mutex_trylock(objc_mutex_t mutex)
{
if (mutex_trylock((mutex_t *)(&(mutex->backend))) != 0)
return -1;
else
return 0;
}
/* Unlock the mutex */
int
__objc_mutex_unlock(objc_mutex_t mutex)
{
if (mutex_unlock((mutex_t *)(&(mutex->backend))) != 0)
return -1;
else
return 0;
}
/* Backend condition mutex functions */
/* Allocate a condition. */
int
__objc_condition_allocate(objc_condition_t condition)
{
return cond_init((cond_t *)(&(condition->backend)), USYNC_THREAD, NULL);
}
/* Deallocate a condition. */
int
__objc_condition_deallocate(objc_condition_t condition)
{
return cond_destroy((cond_t *)(&(condition->backend)));
}
/* Wait on the condition */
int
__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
return cond_wait((cond_t *)(&(condition->backend)),
(mutex_t *)(&(mutex->backend)));
}
/* Wake up all threads waiting on this condition. */
int
__objc_condition_broadcast(objc_condition_t condition)
{
return cond_broadcast((cond_t *)(&(condition->backend)));
}
/* Wake up one thread waiting on this condition. */
int
__objc_condition_signal(objc_condition_t condition)
{
return cond_signal((cond_t *)(&(condition->backend)));
}
/* End of File */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment