| OLD | NEW |
| 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 /* This Source Code Form is subject to the terms of the Mozilla Public | 2 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 * License, v. 2.0. If a copy of the MPL was not distributed with this | 3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 | 5 |
| 6 #include "primpl.h" | 6 #include "primpl.h" |
| 7 | 7 |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #if defined(HPUX) && defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) | 10 #if defined(HPUX) && defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 */ | 219 */ |
| 220 rwlock->rw_lock_cnt++; | 220 rwlock->rw_lock_cnt++; |
| 221 | 221 |
| 222 PR_Unlock(rwlock->rw_lock); | 222 PR_Unlock(rwlock->rw_lock); |
| 223 #endif | 223 #endif |
| 224 | 224 |
| 225 #ifdef _PR_RWLOCK_RANK_ORDER_DEBUG | 225 #ifdef _PR_RWLOCK_RANK_ORDER_DEBUG |
| 226 /* | 226 /* |
| 227 * update thread's lock rank | 227 * update thread's lock rank |
| 228 */ | 228 */ |
| 229 » _PR_SET_THREAD_RWLOCK_RANK(rwlock); | 229 » if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE) |
| 230 » » _PR_SET_THREAD_RWLOCK_RANK(rwlock); |
| 230 #endif | 231 #endif |
| 231 } | 232 } |
| 232 | 233 |
| 233 /* | 234 /* |
| 234 ** Write-lock the RWLock. | 235 ** Write-lock the RWLock. |
| 235 */ | 236 */ |
| 236 PR_IMPLEMENT(void) | 237 PR_IMPLEMENT(void) |
| 237 PR_RWLock_Wlock(PRRWLock *rwlock) | 238 PR_RWLock_Wlock(PRRWLock *rwlock) |
| 238 { | 239 { |
| 239 #if defined(DEBUG) | 240 #if defined(DEBUG) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 PR_ASSERT(me != NULL); | 276 PR_ASSERT(me != NULL); |
| 276 rwlock->rw_owner = me; | 277 rwlock->rw_owner = me; |
| 277 #endif | 278 #endif |
| 278 PR_Unlock(rwlock->rw_lock); | 279 PR_Unlock(rwlock->rw_lock); |
| 279 #endif | 280 #endif |
| 280 | 281 |
| 281 #ifdef _PR_RWLOCK_RANK_ORDER_DEBUG | 282 #ifdef _PR_RWLOCK_RANK_ORDER_DEBUG |
| 282 /* | 283 /* |
| 283 * update thread's lock rank | 284 * update thread's lock rank |
| 284 */ | 285 */ |
| 285 » _PR_SET_THREAD_RWLOCK_RANK(rwlock); | 286 » if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE) |
| 287 » » _PR_SET_THREAD_RWLOCK_RANK(rwlock); |
| 286 #endif | 288 #endif |
| 287 } | 289 } |
| 288 | 290 |
| 289 /* | 291 /* |
| 290 ** Unlock the RW lock. | 292 ** Unlock the RW lock. |
| 291 */ | 293 */ |
| 292 PR_IMPLEMENT(void) | 294 PR_IMPLEMENT(void) |
| 293 PR_RWLock_Unlock(PRRWLock *rwlock) | 295 PR_RWLock_Unlock(PRRWLock *rwlock) |
| 294 { | 296 { |
| 295 #if defined(DEBUG) | 297 #if defined(DEBUG) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 else if (rwlock->rw_reader_cnt > 0) | 342 else if (rwlock->rw_reader_cnt > 0) |
| 341 PR_NotifyAllCondVar(rwlock->rw_reader_waitq); | 343 PR_NotifyAllCondVar(rwlock->rw_reader_waitq); |
| 342 } | 344 } |
| 343 PR_Unlock(rwlock->rw_lock); | 345 PR_Unlock(rwlock->rw_lock); |
| 344 #endif | 346 #endif |
| 345 | 347 |
| 346 #ifdef _PR_RWLOCK_RANK_ORDER_DEBUG | 348 #ifdef _PR_RWLOCK_RANK_ORDER_DEBUG |
| 347 /* | 349 /* |
| 348 * update thread's lock rank | 350 * update thread's lock rank |
| 349 */ | 351 */ |
| 350 » _PR_UNSET_THREAD_RWLOCK_RANK(rwlock); | 352 » if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE) |
| 353 » » _PR_UNSET_THREAD_RWLOCK_RANK(rwlock); |
| 351 #endif | 354 #endif |
| 352 return; | 355 return; |
| 353 } | 356 } |
| 354 | 357 |
| 355 #ifndef _PR_RWLOCK_RANK_ORDER_DEBUG | 358 #ifndef _PR_RWLOCK_RANK_ORDER_DEBUG |
| 356 | 359 |
| 357 void _PR_InitRWLocks(void) { } | 360 void _PR_InitRWLocks(void) { } |
| 358 | 361 |
| 359 #else | 362 #else |
| 360 | 363 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 * | 425 * |
| 423 * return thread's lock rank. If thread-private-data for the lock | 426 * return thread's lock rank. If thread-private-data for the lock |
| 424 * stack is not allocated, return PR_RWLOCK_RANK_NONE. | 427 * stack is not allocated, return PR_RWLOCK_RANK_NONE. |
| 425 */ | 428 */ |
| 426 | 429 |
| 427 static PRUint32 | 430 static PRUint32 |
| 428 _PR_GET_THREAD_RWLOCK_RANK(void) | 431 _PR_GET_THREAD_RWLOCK_RANK(void) |
| 429 { | 432 { |
| 430 thread_rwlock_stack *lock_stack; | 433 thread_rwlock_stack *lock_stack; |
| 431 | 434 |
| 432 » if ((lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key)) == NULL) | 435 » lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key); |
| 436 » if (lock_stack == NULL || lock_stack->trs_index == 0) |
| 433 return (PR_RWLOCK_RANK_NONE); | 437 return (PR_RWLOCK_RANK_NONE); |
| 434 else | 438 else |
| 435 return(lock_stack->trs_stack[lock_stack->trs_index - 1]->rw_rank
); | 439 return(lock_stack->trs_stack[lock_stack->trs_index - 1]->rw_rank
); |
| 436 } | 440 } |
| 437 | 441 |
| 438 /* | 442 /* |
| 439 * _PR_UNSET_THREAD_RWLOCK_RANK | 443 * _PR_UNSET_THREAD_RWLOCK_RANK |
| 440 * | 444 * |
| 441 * remove the rwlock from the lock stack. Since locks may not be | 445 * remove the rwlock from the lock stack. Since locks may not be |
| 442 * unlocked in a FIFO order, the entire lock stack is searched. | 446 * unlocked in a FIFO order, the entire lock stack is searched. |
| 443 */ | 447 */ |
| 444 | 448 |
| 445 static void | 449 static void |
| 446 _PR_UNSET_THREAD_RWLOCK_RANK(PRRWLock *rwlock) | 450 _PR_UNSET_THREAD_RWLOCK_RANK(PRRWLock *rwlock) |
| 447 { | 451 { |
| 448 thread_rwlock_stack *lock_stack; | 452 thread_rwlock_stack *lock_stack; |
| 449 int new_index = 0, index, done = 0; | 453 int new_index = 0, index, done = 0; |
| 450 | 454 |
| 451 lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key); | 455 lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key); |
| 452 | 456 |
| 453 PR_ASSERT(lock_stack != NULL); | 457 PR_ASSERT(lock_stack != NULL); |
| 454 | 458 |
| 455 » index = lock_stack->trs_index - 1; | 459 » for (index = lock_stack->trs_index - 1; index >= 0; index--) { |
| 456 » while (index-- >= 0) { | 460 » » if (!done && (lock_stack->trs_stack[index] == rwlock)) { |
| 457 » » if ((lock_stack->trs_stack[index] == rwlock) && !done) { | |
| 458 /* | 461 /* |
| 459 * reset the slot for rwlock | 462 * reset the slot for rwlock |
| 460 */ | 463 */ |
| 461 lock_stack->trs_stack[index] = NULL; | 464 lock_stack->trs_stack[index] = NULL; |
| 462 done = 1; | 465 done = 1; |
| 463 } | 466 } |
| 464 /* | 467 /* |
| 465 * search for the lowest-numbered empty slot, above which there
are | 468 * search for the lowest-numbered empty slot, above which there
are |
| 466 * no non-empty slots | 469 * no non-empty slots |
| 467 */ | 470 */ |
| 468 » » if ((lock_stack->trs_stack[index] != NULL) && !new_index) | 471 » » if (!new_index && (lock_stack->trs_stack[index] != NULL)) |
| 469 new_index = index + 1; | 472 new_index = index + 1; |
| 470 if (done && new_index) | 473 if (done && new_index) |
| 471 break; | 474 break; |
| 472 } | 475 } |
| 473 /* | 476 /* |
| 474 * set top of stack to highest numbered empty slot | 477 * set top of stack to highest numbered empty slot |
| 475 */ | 478 */ |
| 476 lock_stack->trs_index = new_index; | 479 lock_stack->trs_index = new_index; |
| 477 | 480 |
| 478 } | 481 } |
| 479 | 482 |
| 480 #endif /* _PR_RWLOCK_RANK_ORDER_DEBUG */ | 483 #endif /* _PR_RWLOCK_RANK_ORDER_DEBUG */ |
| OLD | NEW |