MCPcopy Create free account
hub / github.com/bytedance/sonic-cpp / lock

Method lock

include/sonic/allocator.h:82–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80
81 public:
82 void lock() {
83 for (;;) {
84 if (!lock_.exchange(true, std::memory_order_acquire)) {
85 break;
86 }
87 while (lock_.load(std::memory_order_relaxed)) {
88 // use pause or yield instruction will slow down lock acquisition
89 // on contended locks.
90#ifndef SONIC_SPINLOCK_NO_PAUSE
91
92#if defined(__x86_64__) || defined(_M_AMD64)
93 __builtin_ia32_pause();
94#elif defined(__aarch64__) || defined(_M_ARM64)
95 asm volatile("yield");
96#endif
97
98#endif
99 }
100 }
101 }
102 void unlock() { lock_.store(false, std::memory_order_release); }
103};
104

Callers

nothing calls this directly

Calls 1

loadMethod · 0.45

Tested by

no test coverage detected