MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / pthread_rwlock_tryrdlock

Function pthread_rwlock_tryrdlock

include/hamlib/winpthreads.h:447–468  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

445
446
447static int pthread_rwlock_tryrdlock(pthread_rwlock_t *l)
448{
449 /* Get the current state of the lock */
450 void *state = *(void **) l;
451
452 if (!state)
453 {
454 /* Unlocked to locked */
455 if (!InterlockedCompareExchangePointer((volatile PVOID *) l, (void *)0x11, NULL)) return 0;
456 return EBUSY;
457 }
458
459 /* A single writer exists */
460 if (state == (void *) 1) return EBUSY;
461
462 /* Multiple writers exist? */
463 if ((uintptr_t) state & 14) return EBUSY;
464
465 if (InterlockedCompareExchangePointer((volatile PVOID *) l, (void *) ((uintptr_t)state + 16), state) == state) return 0;
466
467 return EBUSY;
468}
469
470static int pthread_rwlock_trywrlock(pthread_rwlock_t *l)
471{

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected