334817 {
334819 ssize_t oldCount;
334820 int spin = 10000;
334821 while (--spin >= 0)
334822 {
334823 oldCount = m_count.load(std::memory_order_relaxed);
334824 if (oldCount > 0)
334825 {
334826 ssize_t newCount = oldCount >
max ? oldCount -
max : 0;
334827 if (m_count.compare_exchange_strong(oldCount, newCount, std::memory_order_acquire, std::memory_order_relaxed))
334828 return oldCount - newCount;
334829 }
334830 std::atomic_signal_fence(std::memory_order_acquire);
334831 }
334832 oldCount = m_count.fetch_sub(1, std::memory_order_acquire);
334833 if (oldCount <= 0)
334834 {
334835 if (timeout_usecs < 0)
334836 {
334837 if (!m_sema.wait())
334838 return 0;
334839 }
334840 else if (!m_sema.timed_wait((std::uint64_t)timeout_usecs))
334841 {
334842 while (true)
334843 {
334844 oldCount = m_count.load(std::memory_order_acquire);
334845 if (oldCount >= 0 && m_sema.try_wait())
334846 break;
334847 if (oldCount < 0 && m_count.compare_exchange_strong(oldCount, oldCount + 1, std::memory_order_relaxed, std::memory_order_relaxed))
334848 return 0;
334849 }
334850 }
334851 }
334853 return 1 + tryWaitMany(
max - 1);
334854 return 1;
334855 }