Index: src/runtime/arc.m ================================================================== --- src/runtime/arc.m +++ src/runtime/arc.m @@ -29,14 +29,13 @@ struct weak_ref { id **locations; size_t count; }; -static struct objc_hashtable *hashtable; -#ifdef OF_HAVE_THREADS -static of_spinlock_t spinlock; -#endif +#import "globals.h" +#define weak_refs objc_globals.weak_refs +#define weak_refs_lock objc_globals.weak_refs_lock static uint32_t obj_hash(const void *obj) { return (uint32_t)(uintptr_t)obj; @@ -48,14 +47,14 @@ return (obj1 == obj2); } OF_CONSTRUCTOR() { - hashtable = objc_hashtable_new(obj_hash, obj_equal, 2); + weak_refs = objc_hashtable_new(obj_hash, obj_equal, 2); #ifdef OF_HAVE_THREADS - if (!of_spinlock_new(&spinlock)) + if (!of_spinlock_new(&weak_refs_lock)) OBJC_ERROR("Failed to create spinlock!") #endif } id @@ -122,20 +121,20 @@ objc_storeWeak(id *object, id value) { struct weak_ref *old; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&spinlock)) + if (!of_spinlock_lock(&weak_refs_lock)) OBJC_ERROR("Failed to lock spinlock!") #endif if (*object != nil && - (old = objc_hashtable_get(hashtable, *object)) != NULL) { + (old = objc_hashtable_get(weak_refs, *object)) != NULL) { for (size_t i = 0; i < old->count; i++) { if (old->locations[i] == object) { if (--old->count == 0) { - objc_hashtable_delete(hashtable, + objc_hashtable_delete(weak_refs, *object); free(old->locations); free(old); } else { id **locations; @@ -157,18 +156,18 @@ } } if (value != nil && class_respondsToSelector(object_getClass(value), @selector(allowsWeakReference)) && [value allowsWeakReference]) { - struct weak_ref *ref = objc_hashtable_get(hashtable, value); + struct weak_ref *ref = objc_hashtable_get(weak_refs, value); if (ref == NULL) { if ((ref = calloc(1, sizeof(*ref))) == NULL) OBJC_ERROR("Not enough memory to allocate weak " "reference!"); - objc_hashtable_set(hashtable, value, ref); + objc_hashtable_set(weak_refs, value, ref); } if ((ref->locations = realloc(ref->locations, (ref->count + 1) * sizeof(id *))) == NULL) OBJC_ERROR("Not enough memory to allocate weak " @@ -179,11 +178,11 @@ value = nil; *object = value; #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&spinlock)) + if (!of_spinlock_unlock(&weak_refs_lock)) OBJC_ERROR("Failed to unlock spinlock!") #endif return value; } @@ -193,19 +192,19 @@ { id value = nil; struct weak_ref *ref; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&spinlock)) + if (!of_spinlock_lock(&weak_refs_lock)) OBJC_ERROR("Failed to lock spinlock!") #endif - if ((ref = objc_hashtable_get(hashtable, *object)) != NULL) + if ((ref = objc_hashtable_get(weak_refs, *object)) != NULL) value = *object; #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&spinlock)) + if (!of_spinlock_unlock(&weak_refs_lock)) OBJC_ERROR("Failed to unlock spinlock!") #endif if (class_respondsToSelector(object_getClass(value), @selector(retainWeakReference)) && [value retainWeakReference]) @@ -243,15 +242,15 @@ objc_moveWeak(id *dest, id *src) { struct weak_ref *ref; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&spinlock)) + if (!of_spinlock_lock(&weak_refs_lock)) OBJC_ERROR("Failed to lock spinlock!") #endif - if ((ref = objc_hashtable_get(hashtable, *src)) != NULL) { + if ((ref = objc_hashtable_get(weak_refs, *src)) != NULL) { for (size_t i = 0; i < ref->count; i++) { if (ref->locations[i] == src) { ref->locations[i] = dest; break; } @@ -260,11 +259,11 @@ *dest = *src; *src = nil; #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&spinlock)) + if (!of_spinlock_unlock(&weak_refs_lock)) OBJC_ERROR("Failed to unlock spinlock!") #endif } void @@ -271,23 +270,23 @@ objc_zero_weak_references(id value) { struct weak_ref *ref; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&spinlock)) + if (!of_spinlock_lock(&weak_refs_lock)) OBJC_ERROR("Failed to lock spinlock!") #endif - if ((ref = objc_hashtable_get(hashtable, value)) != NULL) { + if ((ref = objc_hashtable_get(weak_refs, value)) != NULL) { for (size_t i = 0; i < ref->count; i++) *ref->locations[i] = nil; - objc_hashtable_delete(hashtable, value); + objc_hashtable_delete(weak_refs, value); free(ref->locations); free(ref); } #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&spinlock)) + if (!of_spinlock_unlock(&weak_refs_lock)) OBJC_ERROR("Failed to unlock spinlock!") #endif } Index: src/runtime/category.m ================================================================== --- src/runtime/category.m +++ src/runtime/category.m @@ -21,11 +21,12 @@ #include #import "runtime.h" #import "runtime-private.h" -static struct objc_hashtable *categories = NULL; +#import "globals.h" +#define categories objc_globals.categories 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,17 +24,18 @@ #include #import "runtime.h" #import "runtime-private.h" -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; +#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 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,71 +20,70 @@ #include #import "runtime.h" #import "runtime-private.h" -static struct objc_dtable_level2 *empty_level2 = NULL; -#ifdef OF_SELUID24 -static struct objc_dtable_level3 *empty_level3 = NULL; -#endif +#import "globals.h" +#define empty_dtable_level2 objc_globals.empty_dtable_level2 +#define empty_dtable_level3 objc_globals.empty_dtable_level3 static void init(void) { - empty_level2 = malloc(sizeof(struct objc_dtable_level2)); - if (empty_level2 == NULL) + empty_dtable_level2 = malloc(sizeof(struct objc_dtable_level2)); + if (empty_dtable_level2 == NULL) OBJC_ERROR("Not enough memory to allocate dtable!"); #ifdef OF_SELUID24 - empty_level3 = malloc(sizeof(struct objc_dtable_level3)); - if (empty_level3 == NULL) + empty_dtable_level3 = malloc(sizeof(struct objc_dtable_level3)); + if (empty_dtable_level3 == NULL) OBJC_ERROR("Not enough memory to allocate dtable!"); #endif #ifdef OF_SELUID24 for (uint_fast16_t i = 0; i < 256; i++) { - empty_level2->buckets[i] = empty_level3; - empty_level3->buckets[i] = (IMP)0; + empty_dtable_level2->buckets[i] = empty_dtable_level3; + empty_dtable_level3->buckets[i] = (IMP)0; } #else for (uint_fast16_t i = 0; i < 256; i++) - empty_level2->buckets[i] = (IMP)0; + empty_dtable_level2->buckets[i] = (IMP)0; #endif } struct objc_dtable * objc_dtable_new(void) { struct objc_dtable *dtable; #ifdef OF_SELUID24 - if (empty_level2 == NULL || empty_level3 == NULL) + if (empty_dtable_level2 == NULL || empty_dtable_level3 == NULL) init(); #else - if (empty_level2 == NULL) + if (empty_dtable_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_level2; + dtable->buckets[i] = empty_dtable_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_level2) + if (src->buckets[i] == empty_dtable_level2) continue; #ifdef OF_SELUID24 for (uint_fast16_t j = 0; j < 256; j++) { - if (src->buckets[i]->buckets[j] == empty_level3) + if (src->buckets[i]->buckets[j] == empty_dtable_level3) continue; for (uint_fast16_t k = 0; k < 256; k++) { IMP obj; uint32_t idx; @@ -124,29 +123,29 @@ #else uint8_t i = idx >> 8; uint8_t j = idx; #endif - if (dtable->buckets[i] == empty_level2) { + if (dtable->buckets[i] == empty_dtable_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_level3; + level2->buckets[l] = empty_dtable_level3; #else level2->buckets[l] = (IMP)0; #endif dtable->buckets[i] = level2; } #ifdef OF_SELUID24 - if (dtable->buckets[i]->buckets[j] == empty_level3) { + if (dtable->buckets[i]->buckets[j] == empty_dtable_level3) { struct objc_dtable_level3 *level3 = malloc(sizeof(struct objc_dtable_level3)); if (level3 == NULL) OBJC_ERROR("Not enough memory to insert into dtable!"); @@ -165,16 +164,17 @@ void objc_dtable_free(struct objc_dtable *dtable) { for (uint_fast16_t i = 0; i < 256; i++) { - if (dtable->buckets[i] == empty_level2) + if (dtable->buckets[i] == empty_dtable_level2) continue; #ifdef OF_SELUID24 for (uint_fast16_t j = 0; j < 256; j++) - if (dtable->buckets[i]->buckets[j] != empty_level3) + if (dtable->buckets[i]->buckets[j] != + empty_dtable_level3) free(dtable->buckets[i]->buckets[j]); #endif free(dtable->buckets[i]); } @@ -183,17 +183,17 @@ } void objc_dtable_cleanup(void) { - if (empty_level2 != NULL) - free(empty_level2); + if (empty_dtable_level2 != NULL) + free(empty_dtable_level2); #ifdef OF_SELUID24 - if (empty_level3 != NULL) - free(empty_level3); + if (empty_dtable_level3 != NULL) + free(empty_dtable_level3); #endif - empty_level2 = NULL; + empty_dtable_level2 = NULL; #ifdef OF_SELUID24 - empty_level3 = NULL; + empty_dtable_level3 = NULL; #endif } ADDED src/runtime/globals.h Index: src/runtime/globals.h ================================================================== --- src/runtime/globals.h +++ src/runtime/globals.h @@ -0,0 +1,93 @@ +/* + * 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 @@ -16,10 +16,19 @@ #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,12 +30,13 @@ + (BOOL)resolveClassMethod: (SEL)selector; + (BOOL)resolveInstanceMethod: (SEL)selector; @end -static IMP forward_handler = (IMP)0; -static IMP forward_handler_stret = (IMP)0; +#import "globals.h" +#define forward_handler objc_globals.forward_handler +#define forward_handler_stret objc_globals.forward_handler_stret 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,11 +20,12 @@ #include #include "runtime.h" #include "runtime-private.h" -static objc_enumeration_mutation_handler enumeration_mutation_handler = NULL; +#import "globals.h" +#define enumeration_mutation_handler objc_globals.enumeration_mutation_handler 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 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 +# define SPINLOCK_HASH(p) \ + ((unsigned)((uintptr_t)p >> 4) & (NUM_PROPERTY_LOCKS - 1)) -#ifdef OF_HAVE_THREADS OF_CONSTRUCTOR() { - for (size_t i = 0; i < NUM_SPINLOCKS; i++) - if (!of_spinlock_new(&spinlocks[i])) + for (size_t i = 0; i < NUM_PROPERTY_LOCKS; i++) + if (!of_spinlock_new(&property_locks[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(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&property_locks[hash])); @try { return [[*ptr retain] autorelease]; } @finally { - OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&property_locks[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(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&property_locks[hash])); @try { #endif id old = *ptr; switch (copy) { @@ -87,11 +87,11 @@ } [old release]; #ifdef OF_HAVE_THREADS } @finally { - OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&property_locks[hash])); } #endif return; } @@ -120,15 +120,15 @@ { if (atomic) { #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(src); - OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&property_locks[hash])); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS - OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&property_locks[hash])); #endif return; } @@ -141,17 +141,17 @@ { if (atomic) { #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(src); - OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&property_locks[hash])); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS - OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&property_locks[hash])); #endif return; } memcpy(dest, src, size); } Index: src/runtime/selector.m ================================================================== --- src/runtime/selector.m +++ src/runtime/selector.m @@ -31,15 +31,16 @@ #else # define SEL_MAX 0xFFFF # define SEL_SIZE 2 #endif -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; +#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 void objc_register_selector(struct objc_abi_selector *sel) { struct objc_selector *rsel; @@ -87,16 +88,16 @@ if ((sel->name = of_strdup(name)) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); sel->types = NULL; - if ((free_list = realloc(free_list, - sizeof(void *) * (free_list_cnt + 2))) == NULL) + if ((ptrs_to_free = realloc(ptrs_to_free, + sizeof(void *) * (ptrs_to_free_cnt + 2))) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); - free_list[free_list_cnt++] = sel; - free_list[free_list_cnt++] = (char *)sel->name; + ptrs_to_free[ptrs_to_free_cnt++] = sel; + ptrs_to_free[ptrs_to_free_cnt++] = (char *)sel->name; objc_register_selector(sel); objc_global_mutex_unlock(); return (SEL)sel; @@ -136,18 +137,18 @@ objc_unregister_all_selectors(void) { objc_hashtable_free(selectors); objc_sparsearray_free(selector_names); - if (free_list != NULL) { - for (size_t i = 0; i < free_list_cnt; i++) - free(free_list[i]); + if (ptrs_to_free != NULL) { + for (size_t i = 0; i < ptrs_to_free_cnt; i++) + free(ptrs_to_free[i]); - free(free_list); + free(ptrs_to_free); } selectors = NULL; selectors_cnt = 0; selector_names = NULL; - free_list = NULL; - free_list_cnt = 0; + ptrs_to_free = NULL; + ptrs_to_free_cnt = 0; } Index: src/runtime/static-instances.m ================================================================== --- src/runtime/static-instances.m +++ src/runtime/static-instances.m @@ -20,12 +20,13 @@ #include #import "runtime.h" #import "runtime-private.h" -static struct objc_abi_static_instances **static_instances = NULL; -static size_t static_instances_cnt = 0; +#import "globals.h" +#define static_instances objc_globals.static_instances +#define static_instances_cnt objc_globals.static_instances_cnt 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,25 +20,20 @@ #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(&mutex)) + if (!of_mutex_new(&synchronized_locks_lock)) OBJC_ERROR("Failed to create mutex!") } #endif int @@ -46,23 +41,23 @@ { if (object == nil) return 0; #ifdef OF_HAVE_THREADS - struct lock_s *lock; + struct synchronized_lock *lock; - if (!of_mutex_lock(&mutex)) + if (!of_mutex_lock(&synchronized_locks_lock)) OBJC_ERROR("Failed to lock mutex!"); /* Look if we already have a lock */ - for (lock = locks; lock != NULL; lock = lock->next) { + for (lock = synchronized_locks; lock != NULL; lock = lock->next) { if (lock->object != object) continue; lock->count++; - if (!of_mutex_unlock(&mutex)) + if (!of_mutex_unlock(&synchronized_locks_lock)) OBJC_ERROR("Failed to unlock mutex!"); if (!of_rmutex_lock(&lock->rmutex)) OBJC_ERROR("Failed to lock mutex!"); @@ -76,15 +71,15 @@ if (!of_rmutex_new(&lock->rmutex)) OBJC_ERROR("Failed to create mutex!"); lock->object = object; lock->count = 1; - lock->next = locks; + lock->next = synchronized_locks; - locks = lock; + synchronized_locks = lock; - if (!of_mutex_unlock(&mutex)) + if (!of_mutex_unlock(&synchronized_locks_lock)) OBJC_ERROR("Failed to unlock mutex!"); if (!of_rmutex_lock(&lock->rmutex)) OBJC_ERROR("Failed to lock mutex!"); #endif @@ -97,16 +92,16 @@ { if (object == nil) return 0; #ifdef OF_HAVE_THREADS - struct lock_s *lock, *last = NULL; + struct synchronized_lock *lock, *last = NULL; - if (!of_mutex_lock(&mutex)) + if (!of_mutex_lock(&synchronized_locks_lock)) OBJC_ERROR("Failed to lock mutex!"); - for (lock = locks; lock != NULL; lock = lock->next) { + for (lock = synchronized_locks; lock != NULL; lock = lock->next) { if (lock->object != object) { last = lock; continue; } @@ -117,17 +112,17 @@ if (!of_rmutex_free(&lock->rmutex)) OBJC_ERROR("Failed to destroy mutex!"); if (last != NULL) last->next = lock->next; - if (locks == lock) - locks = lock->next; + if (synchronized_locks == lock) + synchronized_locks = lock->next; free(lock); } - if (!of_mutex_unlock(&mutex)) + if (!of_mutex_unlock(&synchronized_locks_lock)) OBJC_ERROR("Failed to unlock mutex!"); return 0; } Index: src/runtime/threading.m ================================================================== --- src/runtime/threading.m +++ src/runtime/threading.m @@ -21,12 +21,13 @@ #import "runtime.h" #import "runtime-private.h" #import "threading.h" -static of_rmutex_t global_mutex; -static of_once_t once_control = OF_ONCE_INIT; +#import "globals.h" +#define global_mutex objc_globals.global_mutex +#define global_once_control objc_globals.global_once_control static void init(void) { if (!of_rmutex_new(&global_mutex)) @@ -34,11 +35,11 @@ } void objc_global_mutex_lock(void) { - of_once(&once_control, init); + of_once(&global_once_control, init); if (!of_rmutex_lock(&global_mutex)) OBJC_ERROR("Failed to lock global mutex!"); }