Differences From Artifact [9f958f8552]:
- File
src/objc_sync.m
— part of check-in
[5337be0924]
at
2009-05-25 17:00:32
on branch trunk
— Improve objc_sync.m.
* Use inline functions to improve code readability.
* Fix a wrong lock.
* Initialize it in +[initialize] of OFObject. (user: js, size: 4157) [annotate] [blame] [check-ins using]
To Artifact [469f559547]:
- File src/objc_sync.m — part of check-in [5bd604a8f8] at 2009-06-01 01:31:31 on branch trunk — Fix recursive locking. (user: js, size: 4578) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
9 10 11 12 13 14 15 16 17 18 19 20 21 22 | * the packaging of this file. */ #include "config.h" #include <stddef.h> #include <stdlib.h> #ifndef _WIN32 #include <pthread.h> #endif #import <objc/objc.h> | > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | * the packaging of this file. */ #include "config.h" #include <stddef.h> #include <stdlib.h> #include <assert.h> #ifndef _WIN32 #include <pthread.h> #endif #import <objc/objc.h> |
︙ | ︙ | |||
138 139 140 141 142 143 144 | if (!mutex_lock(&mutex)) return 1; for (i = 0; i < num_locks; i++) { if (locks[i].obj == obj) { if (thread_is_current(locks[i].thread)) locks[i].recursion++; | | > > > > > > > > > > > > > | > | 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | if (!mutex_lock(&mutex)) return 1; for (i = 0; i < num_locks; i++) { if (locks[i].obj == obj) { if (thread_is_current(locks[i].thread)) locks[i].recursion++; else { /* Make sure objc_sync_exit doesn't free it */ locks[i].count++; /* Unlock so objc_sync_exit can return */ if (!mutex_unlock(&mutex)) return 1; if (!mutex_lock(&locks[i].mutex)) { mutex_unlock(&mutex); return 1; } if (!mutex_lock(&mutex)) return 1; assert(locks[i].recursion == 0); /* Update lock's active thread */ locks[i].thread = thread_current(); } if (!mutex_unlock(&mutex)) return 1; return 0; } } |
︙ | ︙ | |||
224 225 226 227 228 229 230 | mutex_unlock(&mutex); return 1; } locks[i].count--; if (locks[i].count == 0) { | | > > > | | > | 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | mutex_unlock(&mutex); return 1; } locks[i].count--; if (locks[i].count == 0) { struct locks_s *new_locks = NULL; if (!mutex_free(&locks[i].mutex)) { mutex_unlock(&mutex); return 1; } num_locks--; locks[i] = locks[num_locks]; if (num_locks == 0) { free(locks); new_locks = NULL; } else if ((new_locks = realloc(locks, num_locks * sizeof(struct locks_s))) == NULL) { mutex_unlock(&mutex); return 1; } locks = new_locks; } |
︙ | ︙ |