Index: src/runtime/arc.m ================================================================== --- src/runtime/arc.m +++ src/runtime/arc.m @@ -29,13 +29,14 @@ struct weak_ref { id **locations; size_t count; }; -#import "globals.h" -#define weak_refs objc_globals.weak_refs -#define weak_refs_lock objc_globals.weak_refs_lock +static struct objc_hashtable *hashtable; +#ifdef OF_HAVE_THREADS +static of_spinlock_t spinlock; +#endif static uint32_t obj_hash(const void *obj) { return (uint32_t)(uintptr_t)obj; @@ -47,14 +48,14 @@ return (obj1 == obj2); } OF_CONSTRUCTOR() { - weak_refs = objc_hashtable_new(obj_hash, obj_equal, 2); + hashtable = objc_hashtable_new(obj_hash, obj_equal, 2); #ifdef OF_HAVE_THREADS - if (!of_spinlock_new(&weak_refs_lock)) + if (!of_spinlock_new(&spinlock)) OBJC_ERROR("Failed to create spinlock!") #endif } id @@ -121,20 +122,20 @@ objc_storeWeak(id *object, id value) { struct weak_ref *old; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&weak_refs_lock)) + if (!of_spinlock_lock(&spinlock)) OBJC_ERROR("Failed to lock spinlock!") #endif if (*object != nil && - (old = objc_hashtable_get(weak_refs, *object)) != NULL) { + (old = objc_hashtable_get(hashtable, *object)) != NULL) { for (size_t i = 0; i < old->count; i++) { if (old->locations[i] == object) { if (--old->count == 0) { - objc_hashtable_delete(weak_refs, + objc_hashtable_delete(hashtable, *object); free(old->locations); free(old); } else { id **locations; @@ -156,18 +157,18 @@ } } if (value != nil && class_respondsToSelector(object_getClass(value), @selector(allowsWeakReference)) && [value allowsWeakReference]) { - struct weak_ref *ref = objc_hashtable_get(weak_refs, value); + struct weak_ref *ref = objc_hashtable_get(hashtable, value); if (ref == NULL) { if ((ref = calloc(1, sizeof(*ref))) == NULL) OBJC_ERROR("Not enough memory to allocate weak " "reference!"); - objc_hashtable_set(weak_refs, value, ref); + objc_hashtable_set(hashtable, value, ref); } if ((ref->locations = realloc(ref->locations, (ref->count + 1) * sizeof(id *))) == NULL) OBJC_ERROR("Not enough memory to allocate weak " @@ -178,11 +179,11 @@ value = nil; *object = value; #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&weak_refs_lock)) + if (!of_spinlock_unlock(&spinlock)) OBJC_ERROR("Failed to unlock spinlock!") #endif return value; } @@ -192,19 +193,19 @@ { id value = nil; struct weak_ref *ref; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&weak_refs_lock)) + if (!of_spinlock_lock(&spinlock)) OBJC_ERROR("Failed to lock spinlock!") #endif - if ((ref = objc_hashtable_get(weak_refs, *object)) != NULL) + if ((ref = objc_hashtable_get(hashtable, *object)) != NULL) value = *object; #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&weak_refs_lock)) + if (!of_spinlock_unlock(&spinlock)) OBJC_ERROR("Failed to unlock spinlock!") #endif if (class_respondsToSelector(object_getClass(value), @selector(retainWeakReference)) && [value retainWeakReference]) @@ -242,15 +243,15 @@ objc_moveWeak(id *dest, id *src) { struct weak_ref *ref; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&weak_refs_lock)) + if (!of_spinlock_lock(&spinlock)) OBJC_ERROR("Failed to lock spinlock!") #endif - if ((ref = objc_hashtable_get(weak_refs, *src)) != NULL) { + if ((ref = objc_hashtable_get(hashtable, *src)) != NULL) { for (size_t i = 0; i < ref->count; i++) { if (ref->locations[i] == src) { ref->locations[i] = dest; break; } @@ -259,11 +260,11 @@ *dest = *src; *src = nil; #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&weak_refs_lock)) + if (!of_spinlock_unlock(&spinlock)) OBJC_ERROR("Failed to unlock spinlock!") #endif } void @@ -270,23 +271,23 @@ objc_zero_weak_references(id value) { struct weak_ref *ref; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&weak_refs_lock)) + if (!of_spinlock_lock(&spinlock)) OBJC_ERROR("Failed to lock spinlock!") #endif - if ((ref = objc_hashtable_get(weak_refs, value)) != NULL) { + if ((ref = objc_hashtable_get(hashtable, value)) != NULL) { for (size_t i = 0; i < ref->count; i++) *ref->locations[i] = nil; - objc_hashtable_delete(weak_refs, value); + objc_hashtable_delete(hashtable, value); free(ref->locations); free(ref); } #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&weak_refs_lock)) + if (!of_spinlock_unlock(&spinlock)) OBJC_ERROR("Failed to unlock spinlock!") #endif } Index: src/runtime/category.m ================================================================== --- src/runtime/category.m +++ src/runtime/category.m @@ -21,12 +21,11 @@ #include #import "runtime.h" #import "runtime-private.h" -#import "globals.h" -#define categories objc_globals.categories +static struct objc_hashtable *categories = NULL; static void register_selectors(struct objc_abi_category *cat) { for (struct objc_abi_method_list *ml = cat->instance_methods; Index: src/runtime/class.m ================================================================== --- src/runtime/class.m +++ src/runtime/class.m @@ -24,18 +24,17 @@ #include #import "runtime.h" #import "runtime-private.h" -#import "globals.h" -#define classes objc_globals.classes -#define classes_cnt objc_globals.classes_cnt -#define load_queue objc_globals.load_queue -#define load_queue_cnt objc_globals.load_queue_cnt -#define empty_dtable objc_globals.empty_dtable -#define lookups_till_fast_path objc_globals.lookups_till_fast_path -#define fast_path objc_globals.fast_path +static struct objc_hashtable *classes = NULL; +static unsigned classes_cnt = 0; +static Class *load_queue = NULL; +static size_t load_queue_cnt = 0; +static struct objc_dtable *empty_dtable = NULL; +static unsigned lookups_till_fast_path = 128; +static struct objc_sparsearray *fast_path = NULL; static void register_class(struct objc_abi_class *cls) { if (classes == NULL) Index: src/runtime/dtable.m ================================================================== --- src/runtime/dtable.m +++ src/runtime/dtable.m @@ -20,70 +20,71 @@ #include #import "runtime.h" #import "runtime-private.h" -#import "globals.h" -#define empty_dtable_level2 objc_globals.empty_dtable_level2 -#define empty_dtable_level3 objc_globals.empty_dtable_level3 +static struct objc_dtable_level2 *empty_level2 = NULL; +#ifdef OF_SELUID24 +static struct objc_dtable_level3 *empty_level3 = NULL; +#endif static void init(void) { - empty_dtable_level2 = malloc(sizeof(struct objc_dtable_level2)); - if (empty_dtable_level2 == NULL) + empty_level2 = malloc(sizeof(struct objc_dtable_level2)); + if (empty_level2 == NULL) OBJC_ERROR("Not enough memory to allocate dtable!"); #ifdef OF_SELUID24 - empty_dtable_level3 = malloc(sizeof(struct objc_dtable_level3)); - if (empty_dtable_level3 == NULL) + empty_level3 = malloc(sizeof(struct objc_dtable_level3)); + if (empty_level3 == NULL) OBJC_ERROR("Not enough memory to allocate dtable!"); #endif #ifdef OF_SELUID24 for (uint_fast16_t i = 0; i < 256; i++) { - empty_dtable_level2->buckets[i] = empty_dtable_level3; - empty_dtable_level3->buckets[i] = (IMP)0; + empty_level2->buckets[i] = empty_level3; + empty_level3->buckets[i] = (IMP)0; } #else for (uint_fast16_t i = 0; i < 256; i++) - empty_dtable_level2->buckets[i] = (IMP)0; + empty_level2->buckets[i] = (IMP)0; #endif } struct objc_dtable * objc_dtable_new(void) { struct objc_dtable *dtable; #ifdef OF_SELUID24 - if (empty_dtable_level2 == NULL || empty_dtable_level3 == NULL) + if (empty_level2 == NULL || empty_level3 == NULL) init(); #else - if (empty_dtable_level2 == NULL) + if (empty_level2 == NULL) init(); #endif if ((dtable = malloc(sizeof(struct objc_dtable))) == NULL) OBJC_ERROR("Not enough memory to allocate dtable!"); for (uint_fast16_t i = 0; i < 256; i++) - dtable->buckets[i] = empty_dtable_level2; + dtable->buckets[i] = empty_level2; return dtable; } void objc_dtable_copy(struct objc_dtable *dst, struct objc_dtable *src) { for (uint_fast16_t i = 0; i < 256; i++) { - if (src->buckets[i] == empty_dtable_level2) + if (src->buckets[i] == empty_level2) continue; #ifdef OF_SELUID24 for (uint_fast16_t j = 0; j < 256; j++) { - if (src->buckets[i]->buckets[j] == empty_dtable_level3) + if (src->buckets[i]->buckets[j] == empty_level3) continue; for (uint_fast16_t k = 0; k < 256; k++) { IMP obj; uint32_t idx; @@ -123,29 +124,29 @@ #else uint8_t i = idx >> 8; uint8_t j = idx; #endif - if (dtable->buckets[i] == empty_dtable_level2) { + if (dtable->buckets[i] == empty_level2) { struct objc_dtable_level2 *level2 = malloc(sizeof(struct objc_dtable_level2)); if (level2 == NULL) OBJC_ERROR("Not enough memory to insert into dtable!"); for (uint_fast16_t l = 0; l < 256; l++) #ifdef OF_SELUID24 - level2->buckets[l] = empty_dtable_level3; + level2->buckets[l] = empty_level3; #else level2->buckets[l] = (IMP)0; #endif dtable->buckets[i] = level2; } #ifdef OF_SELUID24 - if (dtable->buckets[i]->buckets[j] == empty_dtable_level3) { + if (dtable->buckets[i]->buckets[j] == empty_level3) { struct objc_dtable_level3 *level3 = malloc(sizeof(struct objc_dtable_level3)); if (level3 == NULL) OBJC_ERROR("Not enough memory to insert into dtable!"); @@ -164,17 +165,16 @@ void objc_dtable_free(struct objc_dtable *dtable) { for (uint_fast16_t i = 0; i < 256; i++) { - if (dtable->buckets[i] == empty_dtable_level2) + if (dtable->buckets[i] == empty_level2) continue; #ifdef OF_SELUID24 for (uint_fast16_t j = 0; j < 256; j++) - if (dtable->buckets[i]->buckets[j] != - empty_dtable_level3) + if (dtable->buckets[i]->buckets[j] != empty_level3) free(dtable->buckets[i]->buckets[j]); #endif free(dtable->buckets[i]); } @@ -183,17 +183,17 @@ } void objc_dtable_cleanup(void) { - if (empty_dtable_level2 != NULL) - free(empty_dtable_level2); + if (empty_level2 != NULL) + free(empty_level2); #ifdef OF_SELUID24 - if (empty_dtable_level3 != NULL) - free(empty_dtable_level3); + if (empty_level3 != NULL) + free(empty_level3); #endif - empty_dtable_level2 = NULL; + empty_level2 = NULL; #ifdef OF_SELUID24 - empty_dtable_level3 = NULL; + empty_level3 = NULL; #endif } DELETED src/runtime/globals.h Index: src/runtime/globals.h ================================================================== --- src/runtime/globals.h +++ src/runtime/globals.h @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "runtime-private.h" - -#ifdef OF_HAVE_THREADS -# import "threading.h" -#endif - -/* All globals used by the runtime */ -struct objc_globals { - /* arc.m */ - struct objc_hashtable *weak_refs; -#ifdef OF_HAVE_THREADS - of_spinlock_t weak_refs_lock; -#endif - - /* category.m */ - struct objc_hashtable *categories; - - /* class.m */ - struct objc_hashtable *classes; - unsigned classes_cnt; - Class *load_queue; - size_t load_queue_cnt; - struct objc_dtable *empty_dtable; - unsigned lookups_till_fast_path; - struct objc_sparsearray *fast_path; - - /* dtable.m */ - struct objc_dtable_level2 *empty_dtable_level2; -#ifdef OF_SELUID24 - struct objc_dtable_level3 *empty_dtable_level3; -#endif - - /* lookup.m */ - IMP forward_handler; - IMP forward_handler_stret; - - /* misc.m */ - objc_enumeration_mutation_handler enumeration_mutation_handler; - - /* property.m */ -#ifdef OF_HAVE_THREADS -# define NUM_PROPERTY_LOCKS 8 /* needs to be a power of 2 */ - of_spinlock_t property_locks[NUM_PROPERTY_LOCKS]; -#endif - - /* selector.m */ - struct objc_hashtable *selectors; - uint32_t selectors_cnt; - struct objc_sparsearray *selector_names; - void **ptrs_to_free; - size_t ptrs_to_free_cnt; - - /* static-instances.m */ - struct objc_abi_static_instances **static_instances; - size_t static_instances_cnt; - - /* synchronized.m */ -#ifdef OF_HAVE_THREADS - struct synchronized_lock { - id object; - int count; - of_rmutex_t rmutex; - struct synchronized_lock *next; - } *synchronized_locks; - of_mutex_t synchronized_locks_lock; -#endif - - /* threading.m */ -#ifdef OF_HAVE_THREADS - of_rmutex_t global_mutex; - of_once_t global_once_control; -#endif -}; - -extern struct objc_globals objc_globals; Index: src/runtime/init.m ================================================================== --- src/runtime/init.m +++ src/runtime/init.m @@ -17,19 +17,10 @@ #include "config.h" #import "runtime.h" #import "runtime-private.h" -#import "globals.h" - -struct objc_globals objc_globals = { -#ifdef OF_HAVE_THREADS - .global_once_control = OF_ONCE_INIT, -#endif - .lookups_till_fast_path = 128 -}; - void __objc_exec_class(void *module_) { struct objc_abi_module *module = module_; Index: src/runtime/lookup.m ================================================================== --- src/runtime/lookup.m +++ src/runtime/lookup.m @@ -30,13 +30,12 @@ + (BOOL)resolveClassMethod: (SEL)selector; + (BOOL)resolveInstanceMethod: (SEL)selector; @end -#import "globals.h" -#define forward_handler objc_globals.forward_handler -#define forward_handler_stret objc_globals.forward_handler_stret +static IMP forward_handler = (IMP)0; +static IMP forward_handler_stret = (IMP)0; static IMP common_method_not_found(id obj, SEL sel, IMP (*lookup)(id, SEL), IMP forward) { /* Index: src/runtime/misc.m ================================================================== --- src/runtime/misc.m +++ src/runtime/misc.m @@ -20,12 +20,11 @@ #include #include "runtime.h" #include "runtime-private.h" -#import "globals.h" -#define enumeration_mutation_handler objc_globals.enumeration_mutation_handler +static objc_enumeration_mutation_handler enumeration_mutation_handler = NULL; void objc_enumerationMutation(id obj) { if (enumeration_mutation_handler != NULL) Index: src/runtime/property.m ================================================================== --- src/runtime/property.m +++ src/runtime/property.m @@ -21,22 +21,22 @@ #import "runtime.h" #import "runtime-private.h" #import "OFObject.h" -#import "globals.h" -#define property_locks objc_globals.property_locks - #ifdef OF_HAVE_THREADS # import "threading.h" -# define SPINLOCK_HASH(p) \ - ((unsigned)((uintptr_t)p >> 4) & (NUM_PROPERTY_LOCKS - 1)) +# define NUM_SPINLOCKS 8 /* needs to be a power of 2 */ +# define SPINLOCK_HASH(p) ((unsigned)((uintptr_t)p >> 4) & (NUM_SPINLOCKS - 1)) +static of_spinlock_t spinlocks[NUM_SPINLOCKS]; +#endif +#ifdef OF_HAVE_THREADS OF_CONSTRUCTOR() { - for (size_t i = 0; i < NUM_PROPERTY_LOCKS; i++) - if (!of_spinlock_new(&property_locks[i])) + for (size_t i = 0; i < NUM_SPINLOCKS; i++) + if (!of_spinlock_new(&spinlocks[i])) OBJC_ERROR("Failed to initialize spinlocks!") } #endif id @@ -45,15 +45,15 @@ if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(ptr); - OF_ENSURE(of_spinlock_lock(&property_locks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); @try { return [[*ptr retain] autorelease]; } @finally { - OF_ENSURE(of_spinlock_unlock(&property_locks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); } #else return [[*ptr retain] autorelease]; #endif } @@ -68,11 +68,11 @@ if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(ptr); - OF_ENSURE(of_spinlock_lock(&property_locks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); @try { #endif id old = *ptr; switch (copy) { @@ -87,11 +87,11 @@ } [old release]; #ifdef OF_HAVE_THREADS } @finally { - OF_ENSURE(of_spinlock_unlock(&property_locks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); } #endif return; } @@ -120,15 +120,15 @@ { if (atomic) { #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(src); - OF_ENSURE(of_spinlock_lock(&property_locks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS - OF_ENSURE(of_spinlock_unlock(&property_locks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); #endif return; } @@ -141,17 +141,17 @@ { if (atomic) { #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(src); - OF_ENSURE(of_spinlock_lock(&property_locks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS - OF_ENSURE(of_spinlock_unlock(&property_locks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); #endif return; } memcpy(dest, src, size); } Index: src/runtime/selector.m ================================================================== --- src/runtime/selector.m +++ src/runtime/selector.m @@ -31,16 +31,15 @@ #else # define SEL_MAX 0xFFFF # define SEL_SIZE 2 #endif -#import "globals.h" -#define selectors objc_globals.selectors -#define selectors_cnt objc_globals.selectors_cnt -#define selector_names objc_globals.selector_names -#define ptrs_to_free objc_globals.ptrs_to_free -#define ptrs_to_free_cnt objc_globals.ptrs_to_free_cnt +static struct objc_hashtable *selectors = NULL; +static uint32_t selectors_cnt = 0; +static struct objc_sparsearray *selector_names = NULL; +static void **free_list = NULL; +static size_t free_list_cnt = 0; void objc_register_selector(struct objc_abi_selector *sel) { struct objc_selector *rsel; @@ -88,16 +87,16 @@ if ((sel->name = of_strdup(name)) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); sel->types = NULL; - if ((ptrs_to_free = realloc(ptrs_to_free, - sizeof(void *) * (ptrs_to_free_cnt + 2))) == NULL) + if ((free_list = realloc(free_list, + sizeof(void *) * (free_list_cnt + 2))) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); - ptrs_to_free[ptrs_to_free_cnt++] = sel; - ptrs_to_free[ptrs_to_free_cnt++] = (char *)sel->name; + free_list[free_list_cnt++] = sel; + free_list[free_list_cnt++] = (char *)sel->name; objc_register_selector(sel); objc_global_mutex_unlock(); return (SEL)sel; @@ -137,18 +136,18 @@ objc_unregister_all_selectors(void) { objc_hashtable_free(selectors); objc_sparsearray_free(selector_names); - if (ptrs_to_free != NULL) { - for (size_t i = 0; i < ptrs_to_free_cnt; i++) - free(ptrs_to_free[i]); + if (free_list != NULL) { + for (size_t i = 0; i < free_list_cnt; i++) + free(free_list[i]); - free(ptrs_to_free); + free(free_list); } selectors = NULL; selectors_cnt = 0; selector_names = NULL; - ptrs_to_free = NULL; - ptrs_to_free_cnt = 0; + free_list = NULL; + free_list_cnt = 0; } Index: src/runtime/static-instances.m ================================================================== --- src/runtime/static-instances.m +++ src/runtime/static-instances.m @@ -20,13 +20,12 @@ #include #import "runtime.h" #import "runtime-private.h" -#import "globals.h" -#define static_instances objc_globals.static_instances -#define static_instances_cnt objc_globals.static_instances_cnt +static struct objc_abi_static_instances **static_instances = NULL; +static size_t static_instances_cnt = 0; void objc_init_static_instances(struct objc_abi_symtab *symtab) { struct objc_abi_static_instances **si; Index: src/runtime/synchronized.m ================================================================== --- src/runtime/synchronized.m +++ src/runtime/synchronized.m @@ -20,20 +20,25 @@ #include #import "runtime.h" #import "runtime-private.h" -#import "globals.h" -#define synchronized_locks objc_globals.synchronized_locks -#define synchronized_locks_lock objc_globals.synchronized_locks_lock - #ifdef OF_HAVE_THREADS # import "threading.h" +static struct lock_s { + id object; + int count; + of_rmutex_t rmutex; + struct lock_s *next; +} *locks = NULL; + +static of_mutex_t mutex; + OF_CONSTRUCTOR() { - if (!of_mutex_new(&synchronized_locks_lock)) + if (!of_mutex_new(&mutex)) OBJC_ERROR("Failed to create mutex!") } #endif int @@ -41,23 +46,23 @@ { if (object == nil) return 0; #ifdef OF_HAVE_THREADS - struct synchronized_lock *lock; + struct lock_s *lock; - if (!of_mutex_lock(&synchronized_locks_lock)) + if (!of_mutex_lock(&mutex)) OBJC_ERROR("Failed to lock mutex!"); /* Look if we already have a lock */ - for (lock = synchronized_locks; lock != NULL; lock = lock->next) { + for (lock = locks; lock != NULL; lock = lock->next) { if (lock->object != object) continue; lock->count++; - if (!of_mutex_unlock(&synchronized_locks_lock)) + if (!of_mutex_unlock(&mutex)) OBJC_ERROR("Failed to unlock mutex!"); if (!of_rmutex_lock(&lock->rmutex)) OBJC_ERROR("Failed to lock mutex!"); @@ -71,15 +76,15 @@ if (!of_rmutex_new(&lock->rmutex)) OBJC_ERROR("Failed to create mutex!"); lock->object = object; lock->count = 1; - lock->next = synchronized_locks; + lock->next = locks; - synchronized_locks = lock; + locks = lock; - if (!of_mutex_unlock(&synchronized_locks_lock)) + if (!of_mutex_unlock(&mutex)) OBJC_ERROR("Failed to unlock mutex!"); if (!of_rmutex_lock(&lock->rmutex)) OBJC_ERROR("Failed to lock mutex!"); #endif @@ -92,16 +97,16 @@ { if (object == nil) return 0; #ifdef OF_HAVE_THREADS - struct synchronized_lock *lock, *last = NULL; + struct lock_s *lock, *last = NULL; - if (!of_mutex_lock(&synchronized_locks_lock)) + if (!of_mutex_lock(&mutex)) OBJC_ERROR("Failed to lock mutex!"); - for (lock = synchronized_locks; lock != NULL; lock = lock->next) { + for (lock = locks; lock != NULL; lock = lock->next) { if (lock->object != object) { last = lock; continue; } @@ -112,17 +117,17 @@ if (!of_rmutex_free(&lock->rmutex)) OBJC_ERROR("Failed to destroy mutex!"); if (last != NULL) last->next = lock->next; - if (synchronized_locks == lock) - synchronized_locks = lock->next; + if (locks == lock) + locks = lock->next; free(lock); } - if (!of_mutex_unlock(&synchronized_locks_lock)) + if (!of_mutex_unlock(&mutex)) OBJC_ERROR("Failed to unlock mutex!"); return 0; } Index: src/runtime/threading.m ================================================================== --- src/runtime/threading.m +++ src/runtime/threading.m @@ -21,13 +21,12 @@ #import "runtime.h" #import "runtime-private.h" #import "threading.h" -#import "globals.h" -#define global_mutex objc_globals.global_mutex -#define global_once_control objc_globals.global_once_control +static of_rmutex_t global_mutex; +static of_once_t once_control = OF_ONCE_INIT; static void init(void) { if (!of_rmutex_new(&global_mutex)) @@ -35,11 +34,11 @@ } void objc_global_mutex_lock(void) { - of_once(&global_once_control, init); + of_once(&once_control, init); if (!of_rmutex_lock(&global_mutex)) OBJC_ERROR("Failed to lock global mutex!"); }