From 02b740e7f7140758806a14880481c58cf35bdc00 Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 20 Nov 2003 23:22:30 +0000 Subject: [PATCH] objc4-237.tar.gz --- Makefile | 13 -------- runtime/objc-private.h | 5 ---- runtime/objc-runtime.m | 2 -- runtime/objc-sel-table.h | 24 +++++++++++++++ runtime/objc-sync.m | 65 +++++++++++++++++++++++----------------- 5 files changed, 62 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index 36ecd5f..3b33ca1 100644 --- a/Makefile +++ b/Makefile @@ -119,19 +119,6 @@ CFLAGS += $(ARCH_FLAGS) LDFLAGS += $(ARCH_FLAGS) -dynamiclib -dynamic -compatibility_version 1 -current_version $(CURRENT_PROJECT_VERSION) endif -ifeq "$(PLATFORM)" "Darwin" -# Determine Mac OS X version -# 6.x = Jaguar, 7.x = Panther -ifeq "$(OS_VERSION)" "" - OS_VERSION = $(shell uname -r) -endif -DARWIN_MAJOR_VERSION = $(word 1, $(subst ., ,$(OS_VERSION))) -DARWIN_MINOR_VERSION = $(word 2, $(subst ., ,$(OS_VERSION))) -ifeq "$(DARWIN_MAJOR_VERSION)" "7" -CFLAGS += -DMACOSX_PANTHER -endif -endif - CFLAGS += $(OTHER_CFLAGS) $(RC_CFLAGS) LDFLAGS += $(OTHER_LDFLAGS) diff --git a/runtime/objc-private.h b/runtime/objc-private.h index b15a828..6c09b7d 100644 --- a/runtime/objc-private.h +++ b/runtime/objc-private.h @@ -55,12 +55,7 @@ #import -#ifdef MACOSX_PANTHER #import -#else - // pre-Panther - #import -#endif /* Opaque cookie used in _getObjc... routines. File format independant. diff --git a/runtime/objc-runtime.m b/runtime/objc-runtime.m index 5498f60..bb204b8 100644 --- a/runtime/objc-runtime.m +++ b/runtime/objc-runtime.m @@ -1760,7 +1760,6 @@ static void _objc_map_image(headerType *mh, unsigned long vmaddr_slide) trace(0xb101, 0, 0, 0); -#ifdef MACOSX_PANTHER // Check if all loaded libraries up to and including this one are prebound // SPI introduced in Panther (Mac OS X 10.3) all_modules_prebound = _dyld_all_twolevel_modules_prebound(); @@ -1772,7 +1771,6 @@ static void _objc_map_image(headerType *mh, unsigned long vmaddr_slide) warned = all_modules_prebound; } } -#endif // Register any categories and/or classes and/or selectors this image contains _objc_add_categories_from_image (hInfo); diff --git a/runtime/objc-sel-table.h b/runtime/objc-sel-table.h index 66d7401..b62295d 100644 --- a/runtime/objc-sel-table.h +++ b/runtime/objc-sel-table.h @@ -1,3 +1,27 @@ +/* + * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ /* Last update: cjk - 16 October 2000 * To construct this list, I enabled the code in the search function which * is marked DUMP_SELECTORS, and launched a few apps with stdout redirected diff --git a/runtime/objc-sync.m b/runtime/objc-sync.m index 945e5e8..86be2a1 100644 --- a/runtime/objc-sync.m +++ b/runtime/objc-sync.m @@ -23,7 +23,7 @@ * @APPLE_LICENSE_HEADER_END@ */ // -// objc_sync.h +// objc_sync.m // // Copyright (c) 2002 Apple Computer, Inc. All rights reserved. // @@ -32,8 +32,6 @@ #include #include #include -#define PTHREAD_MUTEX_RECURSIVE 2 -#include #include #include "objc-sync.h" @@ -71,18 +69,21 @@ done: struct SyncData { - struct SyncData* nextData; - id object; - unsigned int lockCount; + struct SyncData* nextData; // only accessed while holding sTableLock + id object; // only accessed while holding sTableLock + unsigned int lockCount; // only accessed while holding sTableLock pthread_mutex_t mutex; pthread_cond_t conditionVariable; }; typedef struct SyncData SyncData; + static pthread_mutex_t sTableLock = PTHREAD_MUTEX_INITIALIZER; static SyncData* sDataList = NULL; -static SyncData* id2data(id object) +enum usage { ACQUIRE, RELEASE, CHECK }; + +static SyncData* id2data(id object, enum usage why) { SyncData* result = NULL; int err; @@ -106,7 +107,11 @@ static SyncData* id2data(id object) firstUnused = p; } - // if no corresponding SyncData found, but an unused one was found, use it + // no SyncData currently associated with object + if ( (why == RELEASE) || (why == CHECK) ) + goto done; + + // an unused one was found, use it if ( firstUnused != NULL ) { result = firstUnused; result->object = object; @@ -129,6 +134,21 @@ static SyncData* id2data(id object) sDataList = result; done: + if ( result != NULL ) { + switch ( why ) { + case ACQUIRE: + result->lockCount++; + break; + case RELEASE: + result->lockCount--; + if ( result->lockCount == 0 ) + result->object = NULL; // now recycled + break; + case CHECK: + // do nothing + break; + } + } pthread_mutex_unlock(&sTableLock); return result; } @@ -142,14 +162,12 @@ int objc_sync_enter(id obj) { int result = OBJC_SYNC_SUCCESS; - SyncData* data = id2data(obj); + SyncData* data = id2data(obj, ACQUIRE); require_action_string(data != NULL, done, result = OBJC_SYNC_NOT_INITIALIZED, "id2data failed"); result = pthread_mutex_lock(&data->mutex); require_noerr_string(result, done, "pthread_mutex_lock failed"); - - data->lockCount++; // note: lockCount is only modified when corresponding mutex is held - + done: return result; } @@ -161,15 +179,8 @@ int objc_sync_exit(id obj) { int result = OBJC_SYNC_SUCCESS; - SyncData* data; - data = id2data(obj); // XXX should assert that we didn't create it - require_action_string(data != NULL, done, result = OBJC_SYNC_NOT_INITIALIZED, "id2data failed"); - - int oldLockCount = data->lockCount--; - if ( oldLockCount == 1 ) { - // XXX should move off the main chain to speed id2data searches - data->object = NULL; // recycle data - } + SyncData* data = id2data(obj, RELEASE); + require_action_string(data != NULL, done, result = OBJC_SYNC_NOT_OWNING_THREAD_ERROR, "id2data failed"); result = pthread_mutex_unlock(&data->mutex); require_noerr_string(result, done, "pthread_mutex_unlock failed"); @@ -188,8 +199,8 @@ int objc_sync_wait(id obj, long long milliSecondsMaxWait) { int result = OBJC_SYNC_SUCCESS; - SyncData* data = id2data(obj); - require_action_string(data != NULL, done, result = OBJC_SYNC_NOT_INITIALIZED, "id2data failed"); + SyncData* data = id2data(obj, CHECK); + require_action_string(data != NULL, done, result = OBJC_SYNC_NOT_OWNING_THREAD_ERROR, "id2data failed"); // XXX need to retry cond_wait under out-of-our-control failures @@ -223,8 +234,8 @@ int objc_sync_notify(id obj) { int result = OBJC_SYNC_SUCCESS; - SyncData* data = id2data(obj); - require_action_string(data != NULL, done, result = OBJC_SYNC_NOT_INITIALIZED, "id2data failed"); + SyncData* data = id2data(obj, CHECK); + require_action_string(data != NULL, done, result = OBJC_SYNC_NOT_OWNING_THREAD_ERROR, "id2data failed"); result = pthread_cond_signal(&data->conditionVariable); require_noerr_string(result, done, "pthread_cond_signal failed"); @@ -243,8 +254,8 @@ int objc_sync_notifyAll(id obj) { int result = OBJC_SYNC_SUCCESS; - SyncData* data = id2data(obj); - require_action_string(data != NULL, done, result = OBJC_SYNC_NOT_INITIALIZED, "id2data failed"); + SyncData* data = id2data(obj, CHECK); + require_action_string(data != NULL, done, result = OBJC_SYNC_NOT_OWNING_THREAD_ERROR, "id2data failed"); result = pthread_cond_broadcast(&data->conditionVariable); require_noerr_string(result, done, "pthread_cond_broadcast failed"); -- 2.45.2