libctru icon indicating copy to clipboard operation
libctru copied to clipboard

Add timeout versions for LightLock, RecursiveLock, and LightSemaphore

Open piepie62 opened this issue 2 years ago • 2 comments

piepie62 avatar May 02 '23 21:05 piepie62

I'm curious as to which use case prompted this PR.

fincs avatar May 05 '23 17:05 fincs

Some questions:

I have a slightly different implementation a while back: source

It doesn't yet have decreasing timeout on looped arbitrate attempts, which I tried to remedy in this version (from branch)

There are some other differences though:

  • I used ARBITRATION_WAIT_IF_LESS_THAN_TIMEOUT instead of ARBITRATION_WAIT_IF_LESS_THAN, not sure if it matters.
  • On timeout or error, for LightLock, the waiting thread count is released by 1 before returning: source, I don't see similar code in your PR.
  • Similarly for LightSemaphore, the number of threads acquiring the lock is released by 1 before returning: source. Again In your PR the status is returned before doing the associated adjustment.

So the question:

Are those adjustment unnecessary (or incorrect) in my version? I do use the code in a homebrew and it works afaict..

@fincs

As for use case, I just wanted something that matches the behavior of svcWaitSynchronization as I have macro to switch between either svc sync or libctru sync for testing purpose.

xzn avatar Jan 07 '24 17:01 xzn