MCPcopy Create free account
hub / github.com/catboost/catboost / FutexWait

Method FutexWait

library/cpp/lfalloc/lf_allocX64.h:568–605  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

566 }
567
568 void FutexWait()
569 {
570#ifdef _win_
571 if (!LFCheckedWinVersion) {
572 OSVERSIONINFOA ver;
573 memset(&ver, 0, sizeof(ver));
574 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
575 GetVersionExA(&ver);
576 LFHasFutex = (ver.dwMajorVersion > 6) || (ver.dwMajorVersion == 6 && ver.dwMinorVersion >= 2);
577 LFCheckedWinVersion = true;
578 }
579 if (LFHasFutex) {
580 if (LockVar == LF_LOCK_LOCKED) {
581 DoCas(&LockVar, LF_LOCK_FUTEX_WAIT, LF_LOCK_LOCKED);
582 }
583 if (LockVar == LF_LOCK_FUTEX_WAIT) {
584 char* lockedValue = LF_LOCK_FUTEX_WAIT;
585 WaitOnAddress(&LockVar, &lockedValue, sizeof(LockVar), INFINITE);
586 }
587 } else {
588 SwitchToThread();
589 }
590#elif defined(_linux_)
591 if (LFHasFutex) {
592 if (LockVar == LF_LOCK_LOCKED) {
593 DoCas(&LockVar, LF_LOCK_FUTEX_WAIT, LF_LOCK_LOCKED);
594 }
595 if (LockVar == LF_LOCK_FUTEX_WAIT) {
596 // linux allow only int variables checks, here we pretend low bits of LockVar are int
597 syscall(SYS_futex, &LockVar, FUTEX_WAIT_PRIVATE, *(int*)&LF_LOCK_FUTEX_WAIT, 0, 0, 0);
598 }
599 } else {
600 sched_yield();
601 }
602#else
603 sched_yield();
604#endif
605 }
606
607 void Unlock()
608 {

Callers 1

TryLockMethod · 0.80

Calls 1

DoCasFunction · 0.70

Tested by

no test coverage detected