Differences From Artifact [2d30e1cc90]:
- File src/runtime/threading.m — part of check-in [555445ce0a] at 2012-04-21 10:56:21 on branch runtime — Remove useless thread-checking. (user: js, size: 1819) [annotate] [blame] [check-ins using]
To Artifact [92014702e9]:
- File
src/runtime/threading.m
— part of check-in
[51b73c821c]
at
2012-04-22 16:05:21
on branch runtime
— Safer way to create the global mutex.
__attribute__((constructor)) might not have been called when the runtime
is first used. However, the first usage of the runtime is always
single-threaded, so it is safe to do it this way. (user: js, size: 1906) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <stdio.h> #include <stdlib.h> #import "runtime.h" #import "runtime-private.h" static objc_mutex_t global_mutex; BOOL objc_mutex_new(objc_mutex_t *mutex) { if (!of_mutex_new(&mutex->mutex )) return NO; | > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <stdio.h> #include <stdlib.h> #import "runtime.h" #import "runtime-private.h" static objc_mutex_t global_mutex; static BOOL global_mutex_init = NO; BOOL objc_mutex_new(objc_mutex_t *mutex) { if (!of_mutex_new(&mutex->mutex )) return NO; |
︙ | ︙ | |||
63 64 65 66 67 68 69 | BOOL objc_mutex_free(objc_mutex_t *mutex) { return of_mutex_free(&mutex->mutex); } | | > > > > > | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | BOOL objc_mutex_free(objc_mutex_t *mutex) { return of_mutex_free(&mutex->mutex); } static void objc_global_mutex_new(void) { if (!objc_mutex_new(&global_mutex)) ERROR("Failed to create global mutex!"); global_mutex_init = YES; } void objc_global_mutex_lock(void) { if (!global_mutex_init) objc_global_mutex_new(); if (!objc_mutex_lock(&global_mutex)) ERROR("Failed to lock global mutex!"); } void objc_global_mutex_unlock(void) { |
︙ | ︙ |