New files from Scott Christley

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@914 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mccallum 1996-02-13 15:40:05 +00:00
parent 78559c0672
commit af3f9994e4
14 changed files with 1809 additions and 5 deletions

View file

@ -1,9 +1,116 @@
#ifndef __NSLock_h_OBJECTS_INCLUDE /*
#define __NSLock_h_OBJECTS_INCLUDE NSLock.h
Definitions for locking protocol and classes
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
This file is part of the GNUstep Objective-C Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
If you are interested in a warranty or support for this source code,
contact Scott Christley <scottc@net-community.com> for more information.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _GNUstep_H_NSLock
#define _GNUstep_H_NSLock
#include <Foundation/NSObject.h>
#include <objc/thread.h>
//
// NSLocking protocol
//
@protocol NSLocking @protocol NSLocking
- (void) lock;
- (void) unlock; - (void)lock;
- (void)unlock;
@end @end
endif /* __NSLock_h_OBJECTS_INCLUDE */ //
// NSLock class
// Simplest lock for protecting critical sections of code
//
@interface NSLock : NSObject <NSLocking>
{
@private
_objc_mutex_t mutex;
}
- (BOOL)tryLock;
// NSLocking protocol
- (void)lock;
- (void)unlock;
@end
//
// NSConditionLock
// Allows locking and unlocking to be based upon a condition
//
@interface NSConditionLock : NSObject <NSLocking>
{
@private
_objc_mutex_t mutex;
int condition;
}
// Initialize lock with condition
- (id)initWithCondition:(int)value;
// Return the current condition of the lock
- (int)condition;
// Acquiring and release the lock
- (void)lockWhenCondition:(int)value;
- (void)unlockWithCondition:(int)value;
- (BOOL)tryLock;
- (BOOL)tryLockWhenCondition:(int)value;
// NSLocking protocol
- (void)lock;
- (void)unlock;
@end
//
// NSRecursiveLock
// Allows the lock to be recursively acquired by the same thread
//
// If the same thread locks the mutex (n) times then that same
// thread must also unlock it (n) times before another thread
// can acquire the lock.
//
@interface NSRecursiveLock : NSObject <NSLocking>
{
@private
_objc_mutex_t mutex;
}
- (BOOL)tryLock;
// NSLocking protocol
- (void)lock;
- (void)unlock;
@end
#endif /* _GNUstep_H_NSLock */

View file

@ -0,0 +1,68 @@
/*
NSThread.h
Control of executable units within a shared virtual memory space
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
This file is part of the GNUstep Objective-C Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
If you are interested in a warranty or support for this source code,
contact Scott Christley <scottc@net-community.com> for more information.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _GNUstep_H_NSThread
#define _GNUstep_H_NSThread
#include <Foundation/NSObject.h>
#include <objc/thread.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSDate.h>
typedef enum {
NSInteractiveThreadPriority,
NSBackgroundThreadPriority,
NSLowThreadPriority
} NSThreadPriority;
extern NSString *NSBecomingMultiThreaded;
extern NSString *NSThreadExiting;
@interface NSThread : NSObject
{
@private
_objc_thread_t thread_id;
NSMutableDictionary *thread_dictionary;
}
+ (NSThread *)currentThread;
+ (void)detachNewThreadSelector:(SEL)aSelector
toTarget:(id)aTarget
withObject:(id)anArgument;
+ (BOOL)isMultiThreaded;
- (NSMutableDictionary *)threadDictionary;
+ (void)sleepUntilDate:(NSDate *)date;
+ (void)exit;
@end
#endif _GNUstep_H_NSThread

View file

@ -0,0 +1,13 @@
/* WIN32 extra config stuff */
//
// WIN32
//
#ifdef WIN32
# include <windows.h>
# ifndef vm_page_size
# define vm_page_size 4096
# endif
# define popen _popen
#endif

View file

@ -0,0 +1,2 @@
s/@NeXT_runtime@/0/
s/@NeXT_cc@/0/

587
Source/Makefile.nt Normal file
View file

@ -0,0 +1,587 @@
# Generated from Makefile.in by configure.bat
#
# src makefile for GNU Objective-C Class library
# Copyright (C) 1995, 1996 Free Software Foundation, Inc.
#
# Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
#
# This file is part of the GNU Objective-C Class library.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
SHELL = /bin/sh
#### Start of system configuration section. ####
srcdir = .
VPATH = .
# Installation locations
prefix = /MB/Headers
exec_prefix = $(prefix)
libdir = /MB/Libraries
includedir = /MB/Headers
CC = gcc -fgnu-runtime
RANLIB = touch
INSTALL = cp
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL)
AR = lib
AROUT = -out:
ARFLAGS =
LN_S = cp
MAKEINFO = makeinfo
TEXI2DVI = texi2dvi
LEX = flex
LEXFLAGS = -L
DEFS = -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_TIMES=1 -DHAVE_VSPRINTF=1 -Dvm_page_size=4096
##################################################################
#
# NT specifics
#
WIN32_GCC_INCLUDE =
INIT_FILE = init_libObjects
INIT_FILE_OBJ = $(INIT_FILE)$(OEXT)
# File name extensions
OEXT = .obj
EXEEXT = .exe
LIBEXT = .lib
# All these are optional. You can redefine CFLAGS, CPPFLAGS and
# INCLUDEFLAGS on the command line however you like.
CFLAGS = -Wno-implicit -O
CPPFLAGS =
INCLUDEFLAGS =
#### End of system configuration section. ####
include $(srcdir)/../Makeconf
include $(srcdir)/../Version
# Grep for these names to build the legally-required "AUTHORS" file.
FILE_AUTHORS = \
"R. Andrew McCallum" \
"Kresten Krab Thorup" \
"Adam Fedor" \
"Mark Lakata" \
"Jeremy Bettis" \
"Georg Tuparev" \
"Peter Burka"
DYNAMIC_LINKER=null
NEXT_NEXT_INCLUDES = -I/usr/include
OBJECTS_NEXT_INCLUDES = -I$(srcdir)
NEXT_INCLUDES =
ALL_INCLUDE_FLAGS = -I. -I$(srcdir) $(NEXT_INCLUDES) $(INCLUDEFLAGS)
ALL_CPPFLAGS = $(ALL_INCLUDE_FLAGS) $(CPPFLAGS)
ALL_CFLAGS = $(CFLAGS)
ALL_OBJCFLAGS = $(CFLAGS) -Wno-protocol
# definitions to be passed to subdir Makefile's
MAKEDEFINES = CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' \
INCLUDEFLAGS='$(INCLUDEFLAGS)' DEFS='$(DEFS)'
.SUFFIXES: .m
.m$(OEXT):
$(CC) -c $(ALL_CPPFLAGS) $(DEFS) $(ALL_OBJCFLAGS) -o $@ $<
.c$(OEXT):
$(CC) -c $(ALL_CPPFLAGS) $(DEFS) $(ALL_CFLAGS) -o $@ $<
%_pic$(OEXT): %.m
$(CC) -c $(ALL_CPPFLAGS) -fPIC -DPIC $(DEFS) \
$(ALL_OBJCFLAGS) -o $@ $<
%_pic$(OEXT): %.c
$(CC) -c $(ALL_CPPFLAGS) -fPIC -DPIC $(DEFS) \
$(ALL_CFLAGS) -o $@ $<
# GNU Class source files
GNU_MFILES = \
Archiver.m \
Array.m \
Bag.m \
BinaryCStream.m \
BinaryTree.m \
BinaryTreeEltNode.m \
BinaryTreeNode.m \
CircularArray.m \
Coder.m \
Collection.m \
CString.m \
ConnectedCoder.m \
Connection.m \
ConstantString.m \
CStream.m \
DelegatePool.m \
Dictionary.m \
EltNodeCollector.m \
GapArray.m \
Heap.m \
IndexedCollection.m \
Invocation.m \
KeyedCollection.m \
LinkedList.m \
LinkedListEltNode.m \
LinkedListNode.m \
Lock.m \
Magnitude.m \
MallocAddress.m \
MappedCollector.m \
MemoryStream.m \
MutableCString.m \
MutableString.m \
Port.m \
Proxy.m \
Queue.m \
Random.m \
RBTree.m \
RBTreeEltNode.m \
RBTreeNode.m \
RNGAdditiveCongruential.m \
RNGBerkeley.m \
RetainingNotifier.m \
Set.m \
SocketPort.m \
SplayTree.m \
Stack.m \
StdioStream.m \
Stream.m \
String.m \
TextCStream.m \
Time.m \
stdobjects.m \
mframe.m \
objc-gnu2next.m \
eltfuncs.m
GNU_CFILES = \
behavior.c \
collhash.c \
objc-malloc.c \
o_vscanf.c
GNU_OTHER_SRCFILES =
GNU_OBJS = \
$(GNU_MFILES:.m=$(OEXT)) \
$(GNU_CFILES:.c=$(OEXT))
GNU_HEADERS = \
objects/Archiver.h \
objects/Array.h \
objects/ArrayPrivate.h \
objects/Bag.h \
objects/BinaryCStream.h \
objects/BinaryTree.h \
objects/BinaryTreeEltNode.h \
objects/BinaryTreeNode.h \
objects/CircularArray.h \
objects/CircularArrayPrivate.h \
objects/Coder.h \
objects/Coding.h \
objects/Collecting.h \
objects/Collection.h \
objects/CollectionPrivate.h \
objects/ConnectedCoder.h \
objects/Connection.h \
objects/CStream.h \
objects/CStreaming.h \
objects/DelegatePool.h \
objects/Dictionary.h \
objects/EltNodeCollector.h \
objects/EltNode-h \
objects/EltNode-m \
objects/GapArray.h \
objects/GapArrayPrivate.h \
objects/Heap.h \
objects/IndexedCollecting.h \
objects/IndexedCollection.h \
objects/IndexedCollectionPrivate.h \
objects/InvalidationListening.h \
objects/Invocation.h \
objects/KeyedCollecting.h \
objects/KeyedCollection.h \
objects/LibobjectsMain.h \
objects/LinkedList.h \
objects/LinkedListEltNode.h \
objects/LinkedListNode.h \
objects/Lock.h \
objects/Locking.h \
objects/Magnitude.h \
objects/MallocAddress.h \
objects/MappedCollector.h \
objects/MemoryStream.h \
objects/NSArray.h \
objects/NSCoder.h \
objects/NSDictionary.h \
objects/NSSet.h \
objects/NSString.h \
objects/Ordering.h \
objects/Port.h \
objects/Proxy.h \
objects/Queue.h \
objects/RBTree.h \
objects/RBTreeEltNode.h \
objects/RBTreeNode.h \
objects/RNGAdditiveCongruential.h \
objects/RNGBerkeley.h \
objects/Random.h \
objects/RandomGenerating.h \
objects/Retaining.h \
objects/RetainingNotifier.h \
objects/Set.h \
objects/SocketPort.h \
objects/SplayTree.h \
objects/Stack.h \
objects/StdioStream.h \
objects/Stream.h \
objects/Streaming.h \
objects/String.h \
objects/TextCStream.h \
objects/Time.h \
objects/ValueHolding.h \
objects/behavior.h \
objects/collhash.h \
objects/elt.h \
objects/eltfuncs.h \
objects/mframe.h \
objects/objc-gnu2next.h \
objects/objc-malloc.h \
objects/objects.h \
objects/README
# NEXTSTEP source files
NEXTSTEP_MFILES = \
HashTable.m \
List.m \
NXStringTable.m \
Storage.m
NEXTSTEP_CFILES =
NEXTSTEP_DERIVED_CFILES = \
NXStringTable_scan.c
NEXTSTEP_OTHER_SRCFILES = \
NXStringTable_scan.l
NEXTSTEP_OBJS = \
$(NEXTSTEP_MFILES:.m=$(OEXT)) \
$(NEXTSTEP_CFILES:.c=$(OEXT)) \
$(NEXTSTEP_DERIVED_CFILES:.c=$(OEXT))
NEXTSTEP_HEADERS = \
objc/HashTable.h \
objc/List.h \
objc/NXStringTable.h \
objc/Storage.h \
objc/zone.h
# GNUStep source files
GNUSTEP_MFILES = \
NSAllocateObject.m \
NSArchiver.m \
NSArray.m \
NSAssertionHandler.m \
NSAutoreleasePool.m \
NSBitmapCharSet.m \
NSBundle.m \
NSCharacterSet.m \
NSCoder.m \
NSCopyObject.m \
NSConcreteValue.m \
NSCountedSet.m \
NSData.m \
NSDate.m \
NSDeallocateObject.m \
NSDictionary.m \
NSEnumerator.m \
NSException.m \
NSGeometry.m \
NSGArchiver.m \
NSGArray.m \
NSGCountedSet.m \
NSGCString.m \
NSGData.m \
NSGDictionary.m \
NSGSet.m \
NSMethodSignature.m \
NSNumber.m \
NSObjCRuntime.m \
NSObject.m \
NSProcessInfo.m \
NSRange.m \
NSSet.m \
NSString.m \
NSTimeZone.m \
NSValue.m
NSVALUE_CLUSTER = 0 1 2 3 4
NSVALUE_OFILES = \
NSValue0$(OEXT) NSValue1$(OEXT) NSValue2$(OEXT) NSValue3$(OEXT) \
NSValue4$(OEXT)
NSVALUE_MFILES = \
NSValue0.m NSValue1.m NSValue2.m NSValue3.m \
NSValue4.m
NSNUMBER_CLUSTER = 0 1 2 3 4 5 6 7 8 9 10 11 12
NSNUMBER_OFILES = \
NSNumber0$(OEXT) NSNumber1$(OEXT) NSNumber2$(OEXT) \
NSNumber3$(OEXT) NSNumber4$(OEXT) NSNumber5$(OEXT) \
NSNumber6$(OEXT) NSNumber7$(OEXT) NSNumber8$(OEXT) \
NSNumber9$(OEXT) NSNumber10$(OEXT) NSNumber11$(OEXT) \
NSNumber12$(OEXT)
NSNUMBER_MFILES = \
NSNumber0.m NSNumber1.m NSNumber2.m NSNumber3.m \
NSNumber4.m NSNumber5.m NSNumber6.m NSNumber7.m \
NSNumber8.m NSNumber9.m NSNumber10.m NSNumber11.m \
NSNumber12.m
GNUSTEP_CFILES = \
NSZone.c \
find_exec.c \
objc-load.c
GNUSTEP_OTHER_SRCFILES = \
NSConcreteNumber.m \
NSCTemplateValue.m \
dld-load.h \
hpux-load.h \
null-load.h \
simple-load.h
GNUSTEP_OBJS = \
$(GNUSTEP_MFILES:.m=$(OEXT)) \
$(GNUSTEP_CFILES:.c=$(OEXT)) \
$(NSVALUE_OFILES) $(NSNUMBER_OFILES)
GNUSTEP_HEADERS = \
Foundation/NSArchiver.h \
Foundation/NSArray.h \
Foundation/NSAutoreleasePool.h \
Foundation/NSBitmapCharSet.h \
Foundation/NSBundle.h \
Foundation/NSCharacterSet.h \
Foundation/NSCoder.h \
Foundation/NSConcreteNumber.h \
Foundation/NSConcreteValue.h \
Foundation/NSData.h \
Foundation/NSDate.h \
Foundation/NSDictionary.h \
Foundation/NSException.h \
Foundation/NSGeometry.h \
Foundation/NSGArchiver.h \
Foundation/NSGArray.h \
Foundation/NSGCString.h \
Foundation/NSGData.h \
Foundation/NSGDictionary.h \
Foundation/NSGSet.h \
Foundation/NSInvocation.h \
Foundation/NSMethodSignature.h \
Foundation/NSObjCRuntime.h \
Foundation/NSObject.h \
Foundation/NSProcessInfo.h \
Foundation/NSRange.h \
Foundation/NSSerialization.h \
Foundation/NSSet.h \
Foundation/NSString.h \
Foundation/NSUtilities.h \
Foundation/NSValue.h \
Foundation/NSZone.h \
Foundation/objc-load.h
HEADERS_INSTALL = $(GNU_HEADERS) $(NEXTSTEP_HEADERS) $(GNUSTEP_HEADERS) objects/stdobjects.h
OBJS_INSTALL = $(GNU_OBJS) $(NEXTSTEP_OBJS) $(GNUSTEP_OBJS)
OBJS_INSTALL_PIC = $(OBJS_INSTALL:$(OEXT)=_pic$(OEXT))
DIST_FILES = \
Makefile.in AUTHORS \
objects/config.h.in objects/stdobjects.h.in \
$(GNU_MFILES) \
$(GNU_CFILES) \
$(GNU_HEADERS) \
$(GNU_OTHER_SRCFILES) \
$(NEXTSTEP_MFILES) \
$(NEXTSTEP_CFILES) \
$(NEXTSTEP_DERIVED_CFILES) \
$(NEXTSTEP_HEADERS) \
$(NEXTSTEP_OTHER_SRCFILES) \
$(GNUSTEP_MFILES) \
$(GNUSTEP_CFILES) \
$(GNUSTEP_HEADERS) \
$(GNUSTEP_OTHER_SRCFILES)
RCS_FILES = \
Makefile.in \
objects/config.h.in objects/stdobjects.h.in \
$(GNU_MFILES) \
$(GNU_CFILES) \
$(GNU_HEADERS) \
$(GNU_OTHER_SRCFILES) \
$(NEXTSTEP_MFILES) \
$(NEXTSTEP_CFILES) \
$(NEXTSTEP_HEADERS) \
$(NEXTSTEP_OTHER_SRCFILES) \
$(GNUSTEP_MFILES) \
$(GNUSTEP_CFILES) \
$(GNUSTEP_HEADERS) \
$(GNUSTEP_OTHER_SRCFILES)
all: libobjects$(LIBEXT)
libobjects.so.$(OBJECTS_VERSION): objects/stdobjects.h $(OBJS_INSTALL_PIC)
$(CC) -shared -o libobjects.so.$(OBJECTS_VERSION) \
-Wl,-soname,libobjects.so.$(OBJECTS_MAJOR_VERSION) \
$(OBJS_INSTALL_PIC)
rm -f libobjects.so.$(OBJECTS_MAJOR_VERSION)
rm -f libobjects.so
ln -s libobjects.so.$(OBJECTS_VERSION) \
libobjects.so.$(OBJECTS_MAJOR_VERSION)
ln -s libobjects.so.$(OBJECTS_MAJOR_VERSION) \
libobjects.so
libobjects$(LIBEXT): objects/stdobjects.h $(OBJS_INSTALL) $(INIT_FILE_OBJ)
$(AR) $(ARFLAGS) $(AROUT)libobjects$(LIBEXT) $(OBJS_INSTALL) $(INIT_FILE_OBJ)
$(RANLIB) libobjects$(LIBEXT)
$(INIT_FILE_OBJ): $(OBJS_INSTALL)
nm $(GNU_OBJS) | grep " __GLOBAL_" > tmpinit.c
nm $(GNUSTEP_OBJS) | grep " __GLOBAL_" >> tmpinit.c
nm $(NEXTSTEP_OBJS) | grep " __GLOBAL_" >> tmpinit.c
collect tmpinit.c $(INIT_FILE)
$(CC) -c $(ALL_CPPFLAGS) $(DEFS) $(ALL_OBJCFLAGS) $(INIT_FILE).c
rm tmpinit.c
install: installdirs all
$(INSTALL_DATA) libobjects$(LIBEXT) $(libdir)
$(RANLIB) $(libdir)/libobjects$(LIBEXT);
for %i in ( ${GNUSTEP_HEADERS} ) do \
$(INSTALL_DATA) $(srcdir)/%i $(includedir)/%i
for %i in ( ${GNU_HEADERS} ) do \
$(INSTALL_DATA) $(srcdir)/%i $(includedir)/%i
for %i in ( ${NEXTSTEP_HEADERS} ) do \
$(INSTALL_DATA) $(srcdir)/%i $(includedir)/%i
$(INSTALL_DATA) objects/stdobjects.h $(includedir)/objects
$(INSTALL_DATA) objects/config.h $(includedir)/objects
$(INSTALL_DATA) $(srcdir)/objects/README $(includedir)/Foundation
$(INSTALL_DATA) $(srcdir)/objects/README $(includedir)/objc
installdirs:
IF NOT EXIST \MB\Libraries mkdir \MB\Libraries
IF NOT EXIST \MB\Headers\Foundation mkdir \MB\Headers\Foundation
IF NOT EXIST \MB\Headers\objects mkdir \MB\Headers\objects
IF NOT EXIST \MB\Headers\objc mkdir \MB\Headers\objc
uninstall:
rm -f $(libdir)/libobjects$(LIBEXT)
rm -rf $(includedir)/objects \
$(includedir)/Foundation
for %i in ( ${NEXTSTEP_HEADERS} ) do \
rm -f $(includedir)/%i
# Creation of NSValue and NSNumber concrete classes from templates
# Compilation of class clusters
$(NSVALUE_OFILES) : NSCTemplateValue.m
for %i in ( ${NSVALUE_CLUSTER} ) do \
( cp NSCTemplateValue.m NSCTemplateValue%i.m & \
$(CC) -c $(ALL_CPPFLAGS) $(DEFS) $(ALL_OBJCFLAGS) \
-DTYPE_ORDER=%i NSCTemplateValue%i.m \
-o NSValue%i$(OEXT) & \
rm -f NSCTemplateValue%i.m )
$(NSNUMBER_OFILES) : NSConcreteNumber.m
for %i in ( ${NSNUMBER_CLUSTER} ) do \
( cp NSConcreteNumber.m NSConcreteNumber%i.m & \
$(CC) -c $(ALL_CPPFLAGS) $(DEFS) $(ALL_OBJCFLAGS) \
-DTYPE_ORDER=%i -c NSConcreteNumber%i.m \
-o NSNumber%i$(OEXT) & \
rm -f NSConcreteNumber%i.m )
NXStringTable_scan.c: NXStringTable_scan.l
$(LEX) $(LEXFLAGS) -t $(srcdir)/NXStringTable_scan.l \
> NXStringTable_scan.temp
sed "s/yy/NXlex_/g" < NXStringTable_scan.temp \
> NXStringTable_scan.c
$(RM) -f NXStringTable_scan.temp
objc-load$(OEXT): dynamic-load.h
dynamic-load.h: ../config.status
rm -f dynamic-load.h
cp $(srcdir)/$(DYNAMIC_LINKER)-load.h dynamic-load.h
objects/stdobjects.h: $(srcdir)/../Version $(srcdir)/objects/stdobjects.h.in
rm -f $(srcdir)/objects/stdobjects.h
sed -e "s/@OBJECTS_VERSION@/$(OBJECTS_VERSION)/" \
< $(srcdir)/objects/stdobjects.h.in | \
sed -e "s/@OBJECTS_MAJOR_VERSION@/$(OBJECTS_MAJOR_VERSION)/" | \
sed -e "s/@OBJECTS_MINOR_VERSION@/$(OBJECTS_MINOR_VERSION)/" | \
sed -e "s/@OBJECTS_SUBMINOR_VERSION@/$(OBJECTS_SUBMINOR_VERSION)/" | \
sed -e "s/@OBJECTS_GCC_VERSION@/$(OBJECTS_GCC_VERSION)/" \
> $(srcdir)/objects/stdobjects.h
stdobjects$(OEXT): objects/stdobjects.h
Makefile: $(srcdir)/Makefile.in ../config.status
cd ..; $(SHELL) config.status
../config.status:
cd ..; $(SHELL) configure --no-create
TAGS: $(DIST_FILES)
etags $(DIST_FILES)
AUTHORS: Makefile.in
rm -f AUTHORS
@echo Finding file authors...
@echo 'For the legal record, here is a list of who wrote what:'>AUTHORS
@for a in $(FILE_AUTHORS) \
; do \
echo >>AUTHORS; \
echo >>AUTHORS; \
echo "$${a}:" >>AUTHORS; \
egrep -l "((Written by)|(Author)).*$${a}" \
$(DIST_FILES) >>AUTHORS; \
done
mostlyclean:
rm -f core \
*~ \
objects/*~ \
Foundation/*~ \
objc/*~
clean: mostlyclean
rm -f libobjects$(LIBEXT) *$(OEXT)
rm -f $(NSVALUE_MFILES) $(NSNUMBER_MFILES)
distclean: clean
rm -f Makefile
rm -f dynamic-load.h
maintainer-clean: distclean
rm -f TAGS objects/stdobjects.h objects/config.h
copy-dist: $(DIST_FILES)
mkdir ../snap/src
mkdir ../snap/src/objects
mkdir ../snap/src/objc
mkdir ../snap/src/Foundation
for file in $(DIST_FILES); do \
ln $$file ../snap/src/$$file ; \
done
ln AUTHORS ../snap

303
Source/NSLock.m Normal file
View file

@ -0,0 +1,303 @@
/*
NSLock.m
Mutual exclusion locking classes
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
This file is part of the GNUstep Objective-C Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
If you are interested in a warranty or support for this source code,
contact Scott Christley <scottc@net-community.com> for more information.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <Foundation/NSLock.h>
//
// NSLock class
// Simplest lock for protecting critical sections of code
//
@implementation NSLock
// Class initialization
+ (void)initialize
{
if (self == [NSLock class])
{
// Initial version
[self setVersion:1];
}
}
// Default initializer
- init
{
[super init];
// Allocate the mutex from the runtime
mutex = objc_mutex_allocate();
if (!mutex)
return nil;
else
return self;
}
- (void)dealloc
{
// Ask the runtime to deallocate the mutex
// If there are outstanding locks then it will block
objc_mutex_deallocate(mutex);
[super dealloc];
}
// Try to acquire the lock
// Does not block
- (BOOL)tryLock
{
// Ask the runtime to acquire a lock on the mutex
if (objc_mutex_trylock(mutex) == -1)
return NO;
else
return YES;
}
// NSLocking protocol
- (void)lock
{
// Ask the runtime to acquire a lock on the mutex
// This will block
objc_mutex_lock(mutex);
}
- (void)unlock
{
// Ask the runtime to release a lock on the mutex
objc_mutex_unlock(mutex);
}
@end
//
// NSConditionLock
// Allows locking and unlocking to be based upon a condition
//
@implementation NSConditionLock
// Class initialization
+ (void)initialize
{
if (self == [NSConditionLock class])
{
// Initial version
[self setVersion:1];
}
}
- init
{
return [self initWithCondition:0];
}
// Default initializer
// Initialize lock with condition
- (id)initWithCondition:(int)value
{
[super init];
condition = value;
// Allocate the mutex from the runtime
mutex = objc_mutex_allocate();
if (!mutex)
return nil;
else
return self;
}
- (void)dealloc
{
// Ask the runtime to deallocate the mutex
// If there are outstanding locks then it will block
objc_mutex_deallocate(mutex);
[super dealloc];
}
// Return the current condition of the lock
- (int)condition
{
return condition;
}
// Acquiring and release the lock
- (void)lockWhenCondition:(int)value
{
BOOL done;
done = NO;
while (!done)
{
// Try to get the lock
[self lock];
// Is it in the condition we are looking for?
if (condition == value)
done = YES;
else
// Release the lock and keep waiting
[self unlock];
}
}
- (void)unlockWithCondition:(int)value
{
int depth;
// First check to make sure we have the lock
depth= objc_mutex_trylock(mutex);
// Another thread has the lock so abort
if (depth == -1)
return;
// If the depth is only 1 then we just acquired
// the lock above, bogus unlock so abort
if (depth == 1)
return;
// This is a valid unlock so set the condition
// and unlock twice
condition = value;
objc_mutex_unlock(mutex);
objc_mutex_unlock(mutex);
}
- (BOOL)tryLock
{
// Ask the runtime to acquire a lock on the mutex
if (objc_mutex_trylock(mutex) == -1)
return NO;
else
return YES;
}
- (BOOL)tryLockWhenCondition:(int)value
{
// First can we even get the lock?
if (![self tryLock])
return NO;
// If we got the lock is it the right condition?
if (condition == value)
return YES;
else
{
// Wrong condition so release the lock
[self unlock];
return NO;
}
}
// NSLocking protocol
// These methods ignore the condition
- (void)lock
{
// Ask the runtime to acquire a lock on the mutex
// This will block
objc_mutex_lock(mutex);
}
- (void)unlock
{
// Ask the runtime to release a lock on the mutex
objc_mutex_unlock(mutex);
}
@end
//
// NSRecursiveLock
// Allows the lock to be recursively acquired by the same thread
//
// If the same thread locks the mutex (n) times then that same
// thread must also unlock it (n) times before another thread
// can acquire the lock.
//
@implementation NSRecursiveLock
// Class initialization
+ (void)initialize
{
if (self == [NSRecursiveLock class])
{
// Initial version
[self setVersion:1];
}
}
// Default initializer
- init
{
[super init];
// Allocate the mutex from the runtime
mutex = objc_mutex_allocate();
if (!mutex)
return nil;
else
return self;
}
- (void)dealloc
{
// Ask the runtime to deallocate the mutex
// If there are outstanding locks then it will block.
objc_mutex_deallocate(mutex);
[super dealloc];
}
// Try to acquire the lock
// Does not block
- (BOOL)tryLock
{
// Ask the runtime to acquire a lock on the mutex
if (objc_mutex_trylock(mutex) == -1)
return NO;
else
return YES;
}
// NSLocking protocol
- (void)lock
{
// Ask the runtime to acquire a lock on the mutex
// This will block
objc_mutex_lock(mutex);
}
- (void)unlock
{
// Ask the runtime to release a lock onthe mutex
objc_mutex_unlock(mutex);
}
@end

200
Source/NSThread.m Normal file
View file

@ -0,0 +1,200 @@
/*
NSThread.m
Control of executable units within a shared virtual memory space
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
This file is part of the GNUstep Objective-C Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
If you are interested in a warranty or support for this source code,
contact Scott Christley <scottc@net-community.com> for more information.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <Foundation/NSThread.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSLock.h>
#include <Foundation/NSString.h>
// Notifications
NSString *NSBecomingMultiThreaded;
NSString *NSThreadExiting;
// Class variables
NSRecursiveLock *THREAD_LIST_LOCK;
NSMutableArray *THREAD_LIST;
BOOL ENTERED_MULTI_THREADED_STATE;
@implementation NSThread
// Private methods to set/get thread id
- (_objc_thread_t)threadId
{
return thread_id;
}
- (void)setThreadId:(_objc_thread_t)threadId
{
thread_id = threadId;
}
// Class initialization
+ (void)initialize
{
if (self == [NSThread class])
{
// Initial version
[self setVersion:1];
// Allocate global/class variables
NSBecomingMultiThreaded = [NSString
stringWithCString:"Entering multi-threaded state"];
NSThreadExiting = [NSString
stringWithCString:"Thread is exiting"];
THREAD_LIST = [NSArray array];
THREAD_LIST_LOCK = [[NSRecursiveLock alloc] init];
[THREAD_LIST_LOCK autorelease];
ENTERED_MULTI_THREADED_STATE = NO;
}
}
// Initialization
- init
{
[super init];
// Thread specific variables
thread_dictionary = [NSMutableDictionary dictionary];
return self;
}
// Creating an NSThread
+ (NSThread *)currentThread
{
NSThread *t;
_objc_thread_t tid;
id e;
// Get current thread id from runtime
tid = objc_thread_id();
// Lock the thread list so it doesn't change on us
[THREAD_LIST_LOCK lock];
// Enumerate through thread list to find the current thread
e = [THREAD_LIST objectEnumerator];
while (t = [e nextObject])
{
if ([t threadId] == tid)
{
[THREAD_LIST_LOCK unlock];
return t;
}
}
// Something is wrong if we get here
[THREAD_LIST_LOCK unlock];
return nil;
}
+ (void)detachNewThreadSelector:(SEL)aSelector
toTarget:(id)aTarget
withObject:(id)anArgument
{
NSThread *t = [[NSThread alloc] init];
_objc_thread_t tid;
// Lock the thread list so it doesn't change on us
[THREAD_LIST_LOCK lock];
// Have the runtime detach the thread
tid = objc_thread_detach(aSelector, aTarget, anArgument);
if (!tid)
{
// Couldn't detach!
[THREAD_LIST_LOCK unlock];
return;
}
// Save the thread in our thread list
[t setThreadId:tid];
[THREAD_LIST addObject:t];
[THREAD_LIST_LOCK unlock];
}
// Querying a thread
+ (BOOL)isMultiThreaded
{
return ENTERED_MULTI_THREADED_STATE;
}
- (NSMutableDictionary *)threadDictionary
{
return thread_dictionary;
}
// Delaying a thread
+ (void)sleepUntilDate:(NSDate *)date
{
// Do we need some runtime/OS support for this?
}
// Terminating a thread
// What happens if the thread doesn't call +exit?
+ (void)exit
{
NSThread *t;
_objc_thread_t tid;
id e;
BOOL found;
// Get current thread id from runtime
tid = objc_thread_id();
// Lock the thread list so it doesn't change on us
[THREAD_LIST_LOCK lock];
// Enumerate through thread list to find the current thread
e = [THREAD_LIST objectEnumerator];
found = NO;
while ((t = [e nextObject]) && (!found))
{
if ([t threadId] == tid)
found = YES;
}
// I hope we found it
if (found)
{
// Remove the thread from the list
[THREAD_LIST removeObject: t];
// Release the thread object
[t release];
}
// Unlock the thread list
[THREAD_LIST_LOCK unlock];
// Tell the runtime to exit the thread
objc_thread_exit();
}
@end

View file

@ -0,0 +1,13 @@
/* WIN32 extra config stuff */
//
// WIN32
//
#ifdef WIN32
# include <windows.h>
# ifndef vm_page_size
# define vm_page_size 4096
# endif
# define popen _popen
#endif

View file

@ -0,0 +1,2 @@
s/@NeXT_runtime@/0/
s/@NeXT_cc@/0/

212
Testing/Makefile.nt Normal file
View file

@ -0,0 +1,212 @@
#
# Tests makefile for Objective-C Class Library
# Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
#
# Written by: R. Andrew McCallum <mccallum@cs.rochester.edu>
# Dept. of Computer Science, U. of Rochester, Rochester, NY 14627
#
# This file is part of the GNU Objective-C Class Library.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
SHELL = /bin/sh
#### Start of system configuration section. ####
srcdir = .
VPATH = .
CC = gcc -fgnu-runtime
CFLAGS = -Wall -Wno-implicit -O
CPPFLAGS =
LDFLAGS =
DYNAMIC_BUNDLER_LINKER=
DYNAMIC_LDFLAGS=
DYNAMIC_CFLAGS=
DEFS = -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_TIMES=1 -DHAVE_VSPRINTF=1 -Dvm_page_size=4096
LIBS = -L../src -lobjects libobjc.lib libgcc.lib -lm
EXEEXT = .exe
OEXT = .obj
LIBEXT = .lib
#### End of system configuration section. ####
include $(srcdir)/../Makeconf
include $(srcdir)/../Version
# Not needed anymore?
NEXT_NEXT_INCLUDES = -I/usr/include
OBJECTS_NEXT_INCLUDES = -I$(srcdir)/../src
NEXT_INCLUDES =
ALL_CPPFLAGS = -I../src -I$(srcdir)/../src $(NEXT_INCLUDES) $(CPPFLAGS)
ALL_CFLAGS = $(CFLAGS)
ALL_OBJCFLAGS = $(CFLAGS) -Wno-protocol
ALL_LDFLAGS = $(LDFLAGS) $(LIBS)
.SUFFIXES: .m
.m$(OEXT):
$(CC) -c $(ALL_CPPFLAGS) $(DEFS) $(ALL_OBJCFLAGS) $< -o $*$(OEXT)
.c$(OEXT):
$(CC) -c $(ALL_CPPFLAGS) $(DEFS) $(ALL_CFLAGS) $< -o $*$(OEXT)
SRCS = \
test01.m \
test02.m \
test03.m \
test04.m \
test05.m \
test06.m \
test07.m \
test10.m \
test11.m \
test12.m \
test13.m \
pipes.m \
server.m \
client.m \
string.m \
values.m \
nsarray.m \
nsbundle.m \
nsdictionary.m \
nsset.m \
nsprocessinfo.m \
nsarchiver.m
# nsarchiving.m
HDRS = \
server.h
EXCS = $(SRCS:.m=)
BUNDLE_NAME=LoadMe
DYNAMIC_MFILES = \
LoadMe.m \
MyCategory.m \
SecondClass.m
DYNAMIC_HFILES = \
LoadMe.h \
MyCategory.h \
SecondClass.h
DYNAMIC_OFILES = $(DYNAMIC_MFILES:.m=$(OEXT))
RCS_FILES = $(SRCS) $(HDRS) $(DYNAMIC_MFILES) $(DYNAMIC_HFILES) \
Makefile.in NXStringTable.example Makefile.sed.nt
DIST_FILES = $(RCS_FILES)
# type 'make bundles' if you also want to check bundles.
all: $(EXCS)
# This works for GNU make, but not others.
# %: %$(OEXT) $(srcdir)/../src/libobjects$(LIBEXT)
# $(CC) $(ALL_CFLAGS) $< -o $@ $(ALL_LDFLAGS)
# How can I do this in a better way than the ugliness below?
# (but also have it work on old-style /bin/make)
LINK_CMD = $(CC) $(ALL_CFLAGS) $@$(OEXT) -o $@ $(ALL_LDFLAGS)
test01: test01$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
test02: test02$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
test03: test03$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
test04: test04$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
test05: test05$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
test06: test06$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
test07: test07$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
test10: test10$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
test11: test11$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
test12: test12$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
test13: test13$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
pipes: pipes$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
server: server$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
client: client$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
string: string$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
values: values$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
nsarray: nsarray$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
nsbundle: nsbundle$(OEXT) ../src/libobjects$(LIBEXT)
$(CC) $(ALL_CFLAGS) $(DYNAMIC_LDFLAGS) $@$(OEXT) -o $@ $(ALL_LDFLAGS)
nsdictionary: nsdictionary$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
nsset: nsset$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
nsprocessinfo: nsprocessinfo$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
nsarchiver: nsarchiver$(OEXT) ../src/libobjects$(LIBEXT)
$(LINK_CMD)
install:
uninstall:
echo-excs:
@echo $(EXCS)
remote: server client
# These next few lines give an example of how to compile, link and store
# a bundle.
bundles: $(BUNDLE_NAME).bundle/$(BUNDLE_NAME)
$(DYNAMIC_OFILES): $(DYNAMIC_MFILES) $(DYNAMIC_HFILES)
$(CC) -c $(ALL_CPPFLAGS) $(DEFS) $(DYNAMIC_CFLAGS) $(ALL_OBJCFLAGS) \
$(srcdir)/$*.m -o $*$(OEXT)
$(BUNDLE_NAME).bundle/$(BUNDLE_NAME): $(DYNAMIC_OFILES)
-mkdir $(BUNDLE_NAME).bundle
-mkdir $(BUNDLE_NAME).bundle/English.lproj
$(DYNAMIC_BUNDLER_LINKER) -o $(BUNDLE_NAME).bundle/$(BUNDLE_NAME) \
$(DYNAMIC_OFILES)
cp $(srcdir)/NXStringTable.example $(BUNDLE_NAME).bundle/English.lproj
mostlyclean:
rm -f core *~ test08.data textcoder.txt
clean: mostlyclean
rm -f *$(OEXT) $(EXCS)
rm -rf $(BUNDLE_NAME).bundle
distclean: clean
rm -f Makefile config.status
realclean: distclean
rm -f TAGS
copy-dist: $(DIST_FILES)
mkdir ../snap/checks
ln $(DIST_FILES) ../snap/checks
Makefile: $(srcdir)/Makefile.in
cd ..; $(SHELL) config.status

24
Testing/Philosopher.h Normal file
View file

@ -0,0 +1,24 @@
//
// Philosopher.h
//
// A class of hungry philosophers
//
#include <Foundation/NSLock.h>
#include <Foundation/NSThread.h>
// Conditions
#define NO_FOOD 1
#define FOOD_SERVED 2
@interface Philosopher : NSObject
{
int chair;
}
// Instance methods
- (void)sitAtChair:(int)position;
- (int)chair;
@end

61
Testing/Philosopher.m Normal file
View file

@ -0,0 +1,61 @@
//
// Philosopher.h
//
// A class of hungry philosophers
//
#include "Philosopher.h"
extern id forks[5];
@implementation Philosopher
// Instance methods
- (void)sitAtChair:(int)position
{
int i;
// Sit down
chair = position;
// Its a constant battle to feed yourself
while (1)
{
// Get the fork to our left
[forks[chair] lockWhenCondition:FOOD_SERVED];
// Get the fork to our right
[forks[(chair + 1) % 5] lockWhenCondition:FOOD_SERVED];
// Start eating!
printf("Philosopher %d can start eating.\n", chair);
for (i = 0;i < 100000; ++i)
{
if ((i % 10000) == 0)
printf("Philosopher %d is eating.\n", chair);
}
// Done eating
printf("Philosopher %d is done eating.\n", chair);
// Drop the fork to our left
[forks[chair] unlock];
// Drop the fork to our right
[forks[(chair + 1) % 5] unlock];
// Wait until we are hungry again
for (i = 0;i < 1000000 * (chair + 1); ++i) ;
}
// We never get here, but this is what we should do
[NSThread exit];
}
- (int)chair
{
return chair;
}
@end

View file

@ -0,0 +1,145 @@
/*
diningPhilosophers.h
Five hungry philosophers testing locks and threads
This program loops indefinitely.
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
This file is part of the GNUstep Application Kit Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
If you are interested in a warranty or support for this source code,
contact Scott Christley <scottc@net-community.com> for more information.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <Foundation/NSLock.h>
#include <Foundation/NSThread.h>
// Conditions
#define NO_FOOD 1
#define FOOD_SERVED 2
// NSLocks ... umm I mean forks
id forks[5];
//
// A class of hungry philosophers
//
@interface Philosopher : NSObject
{
int chair;
}
// Instance methods
- (void)sitAtChair:(int)position;
- (int)chair;
@end
@implementation Philosopher
// Instance methods
- (void)sitAtChair:(int)position
{
int i;
// Sit down
chair = position;
// Its a constant battle to feed yourself
while (1)
{
// Get the fork to our left
[forks[chair] lockWhenCondition:FOOD_SERVED];
// Get the fork to our right
[forks[(chair + 1) % 5] lockWhenCondition:FOOD_SERVED];
// Start eating!
printf("Philosopher %d can start eating.\n", chair);
for (i = 0;i < 100000; ++i)
{
if ((i % 10000) == 0)
printf("Philosopher %d is eating.\n", chair);
}
// Done eating
printf("Philosopher %d is done eating.\n", chair);
// Drop the fork to our left
[forks[chair] unlock];
// Drop the fork to our right
[forks[(chair + 1) % 5] unlock];
// Wait until we are hungry again
for (i = 0;i < 1000000 * (chair + 1); ++i) ;
}
// We never get here, but this is what we should do
[NSThread exit];
}
- (int)chair
{
return chair;
}
@end
//
// my main for the test app
//
int main()
{
int i;
id p[5];
#ifdef WIN32
// Initialize ourselves in Obj-C runtime
init_diningPhilosophers();
#endif
// Create the locks
for (i = 0;i < 5; ++i)
{
forks[i] = [[NSConditionLock alloc]
initWithCondition:NO_FOOD];
[forks[i] lock];
}
// Create the philosophers
for (i = 0;i < 5; ++i)
p[i] = [[Philosopher alloc] init];
// Have them sit at the table
for (i = 0;i < 5; ++i)
[NSThread detachNewThreadSelector:@selector(sitAtChair:)
toTarget:p[i] withObject:i];
// Now let them all eat
for (i = 0;i < 5; ++i)
[forks[i] unlockWithCondition:FOOD_SERVED];
while (1);
}

67
configure.bat Normal file
View file

@ -0,0 +1,67 @@
@echo off
rem
rem configure.bat
rem Configuration program for libobjects for Window NT
rem
rem Copyright (C) 1996 Free Software Foundation, Inc.
rem
rem Written by: Scott Christley <scottc@net-community.com>
rem
rem This file is part of the GNU Objective-C Class library.
rem
rem This library is free software; you can redistribute it and/or
rem modify it under the terms of the GNU Library General Public
rem License as published by the Free Software Foundation; either
rem version 2 of the License, or (at your option) any later version.
rem
rem This library is distributed in the hope that it will be useful,
rem but WITHOUT ANY WARRANTY; without even the implied warranty of
rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
rem Library General Public License for more details.
rem
rem You should have received a copy of the GNU Library General Public
rem License along with this library; if not, write to the Free
rem Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
rem
rem
rem Top level makefile
rem
echo "Top level makefile"
sed -f Makefile.sed.nt Makefile.in >Makefile
rem
rem src makefile
rem
echo "Src makefile"
cd src
sed -f Makefile.sed.nt Makefile.in >Makefile
touch 0
touch 1
touch 2
touch 3
touch 4
touch 5
touch 6
touch 7
touch 8
touch 9
touch 10
touch 11
touch 12
echo "objects subdirectory"
cd objects
rm -f config.h
sed -f config-nt.sed config.h.in >>config.h
cat config-nt.h >>config.h
cd ..
cd ..
rem
rem checks makefile
rem
echo "Checks makefile"
cd checks
sed -f Makefile.sed.nt Makefile.in >Makefile
cd ..