MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / fastlock_sleep

Function fastlock_sleep

src/fastlock.cpp:305–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303}
304
305extern "C" void fastlock_sleep(fastlock *lock, pid_t pid, unsigned wake, unsigned myticket)
306{
307 UNUSED(lock);
308 UNUSED(pid);
309 UNUSED(wake);
310 UNUSED(myticket);
311#ifdef __linux__
312 g_dlock.registerwait(lock, pid);
313 unsigned mask = (1U << (myticket % 32));
314 __atomic_fetch_or(&lock->futex, mask, __ATOMIC_ACQUIRE);
315
316 // double check the lock wasn't release between the last check and us setting the futex mask
317 uint32_t u;
318 __atomic_load(&lock->m_ticket.u, &u, __ATOMIC_ACQUIRE);
319 if ((u & 0xffff) != myticket)
320 {
321 futex(&lock->m_ticket.u, FUTEX_WAIT_BITSET_PRIVATE, wake, nullptr, mask);
322 }
323
324 __atomic_fetch_and(&lock->futex, ~mask, __ATOMIC_RELEASE);
325 g_dlock.clearwait(lock, pid);
326#endif
327 __atomic_fetch_add(&g_longwaits, 1, __ATOMIC_RELAXED);
328}
329
330extern "C" void fastlock_init(struct fastlock *lock, const char *name)
331{

Callers 1

fastlock_lockFunction · 0.85

Calls 3

futexFunction · 0.85
registerwaitMethod · 0.80
clearwaitMethod · 0.80

Tested by

no test coverage detected