| 363 | } |
| 364 | |
| 365 | void LightSemaphore_Acquire(LightSemaphore* semaphore, s32 count) |
| 366 | { |
| 367 | s32 old_count; |
| 368 | s16 num_threads_acq; |
| 369 | |
| 370 | do |
| 371 | { |
| 372 | for (;;) |
| 373 | { |
| 374 | old_count = __ldrex(&semaphore->current_count); |
| 375 | if (old_count >= count) |
| 376 | break; |
| 377 | __clrex(); |
| 378 | |
| 379 | do |
| 380 | num_threads_acq = (s16)__ldrexh((u16 *)&semaphore->num_threads_acq); |
| 381 | while (__strexh((u16 *)&semaphore->num_threads_acq, num_threads_acq + 1)); |
| 382 | |
| 383 | syncArbitrateAddress(&semaphore->current_count, ARBITRATION_WAIT_IF_LESS_THAN, count); |
| 384 | |
| 385 | do |
| 386 | num_threads_acq = (s16)__ldrexh((u16 *)&semaphore->num_threads_acq); |
| 387 | while (__strexh((u16 *)&semaphore->num_threads_acq, num_threads_acq - 1)); |
| 388 | } |
| 389 | } while (__strex(&semaphore->current_count, old_count - count)); |
| 390 | |
| 391 | __dmb(); |
| 392 | } |
| 393 | |
| 394 | int LightSemaphore_TryAcquire(LightSemaphore* semaphore, s32 count) |
| 395 | { |