void signal_all(Lock& lock) { ASIO_ASSERT(lock.locked()); (void)lock; state_ |= 1; ::pthread_cond_broadcast(&cond_); // Ignore EINVAL. }
bool wait_for_usec(Lock& lock, long usec) { ASIO_ASSERT(lock.locked()); if ((state_ & 1) == 0) { state_ += 2; timespec ts; #if (defined(__MACH__) && defined(__APPLE__)) \ || (defined(__ANDROID__) && (__ANDROID_API__ < 21)) ts.tv_sec = usec / 1000000; ts.tv_nsec = (usec % 1000000) * 1000; ::pthread_cond_timedwait_relative_np( &cond_, &lock.mutex().mutex_, &ts); // Ignore EINVAL. #else // (defined(__MACH__) && defined(__APPLE__)) // || (defined(__ANDROID__) && (__ANDROID_API__ < 21)) if (::clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { ts.tv_sec += usec / 1000000; ts.tv_nsec = (usec % 1000000) * 1000; ts.tv_sec += ts.tv_nsec / 1000000000; ts.tv_nsec = ts.tv_nsec % 1000000000; ::pthread_cond_timedwait(&cond_, &lock.mutex().mutex_, &ts); // Ignore EINVAL. } #endif // (defined(__MACH__) && defined(__APPLE__)) // || (defined(__ANDROID__) && (__ANDROID_API__ < 21)) state_ -= 2; } return (state_ & 1) != 0; }
void wait(Lock& lock) { ASIO_ASSERT(lock.locked()); lock.unlock(); ::WaitForSingleObject(event_, INFINITE); lock.lock(); }
void clear(Lock& lock) { ASIO_ASSERT(lock.locked()); (void)lock; ::ResetEvent(events_[0]); state_ &= ~std::size_t(1); }
void signal_all(Lock& lock) { ASIO_ASSERT(lock.locked()); (void)lock; state_ |= 1; ::SetEvent(events_[0]); }
void signal_all(Lock& lock) { ASIO_ASSERT(lock.locked()); (void)lock; state_ |= 1; cond_.notify_all(); }
// Erase an entry from the map. void erase(iterator it) { ASIO_ASSERT(it != values_.end()); ASIO_ASSERT(num_buckets_ != 0); size_t bucket = calculate_hash_value(it->first) % num_buckets_; bool is_first = (it == buckets_[bucket].first); bool is_last = (it == buckets_[bucket].last); if (is_first && is_last) buckets_[bucket].first = buckets_[bucket].last = values_.end(); else if (is_first) ++buckets_[bucket].first; else if (is_last) --buckets_[bucket].last; values_erase(it); --size_; }
void unlock_and_signal_one(Lock& lock) { ASIO_ASSERT(lock.locked()); state_ |= 1; bool have_waiters = (state_ > 1); lock.unlock(); if (have_waiters) ::SetEvent(events_[1]); }
void unlock_and_signal_one(Lock& lock) { ASIO_ASSERT(lock.locked()); state_ |= 1; bool have_waiters = (state_ > 1); lock.unlock(); if (have_waiters) cond_.notify_one(); }
void unlock_and_signal_one(Lock& lock) { ASIO_ASSERT(lock.locked()); state_ |= 1; bool have_waiters = (state_ > 1); lock.unlock(); if (have_waiters) ::pthread_cond_signal(&cond_); // Ignore EINVAL. }
void wait(Lock& lock) { ASIO_ASSERT(lock.locked()); unique_lock_adapter u_lock(lock); while ((state_ & 1) == 0) { waiter w(state_); cond_.wait(u_lock.unique_lock_); } }
void wait(Lock& lock) { ASIO_ASSERT(lock.locked()); while ((state_ & 1) == 0) { state_ += 2; ::pthread_cond_wait(&cond_, &lock.mutex().mutex_); // Ignore EINVAL. state_ -= 2; } }
bool wait_for_usec(Lock& lock, long usec) { ASIO_ASSERT(lock.locked()); unique_lock_adapter u_lock(lock); if ((state_ & 1) == 0) { waiter w(state_); cond_.wait_for(u_lock.unique_lock_, std::chrono::microseconds(usec)); } return (state_ & 1) != 0; }
bool maybe_unlock_and_signal_one(Lock& lock) { ASIO_ASSERT(lock.locked()); state_ |= 1; if (state_ > 1) { lock.unlock(); cond_.notify_one(); return true; } return false; }
bool maybe_unlock_and_signal_one(Lock& lock) { ASIO_ASSERT(lock.locked()); state_ |= 1; if (state_ > 1) { lock.unlock(); ::SetEvent(events_[1]); return true; } return false; }
bool maybe_unlock_and_signal_one(Lock& lock) { ASIO_ASSERT(lock.locked()); state_ |= 1; if (state_ > 1) { lock.unlock(); ::pthread_cond_signal(&cond_); // Ignore EINVAL. return true; } return false; }
void wait(Lock& lock) { ASIO_ASSERT(lock.locked()); while ((state_ & 1) == 0) { state_ += 2; lock.unlock(); #if defined(ASIO_WINDOWS_APP) ::WaitForMultipleObjectsEx(2, events_, false, INFINITE, false); #else // defined(ASIO_WINDOWS_APP) ::WaitForMultipleObjects(2, events_, false, INFINITE); #endif // defined(ASIO_WINDOWS_APP) lock.lock(); state_ -= 2; } }
bool wait_for_usec(Lock& lock, long usec) { ASIO_ASSERT(lock.locked()); if ((state_ & 1) == 0) { state_ += 2; lock.unlock(); DWORD msec = usec > 0 ? (usec < 1000 ? 1 : usec / 1000) : 0; #if defined(ASIO_WINDOWS_APP) ::WaitForMultipleObjectsEx(2, events_, false, msec, false); #else // defined(ASIO_WINDOWS_APP) ::WaitForMultipleObjects(2, events_, false, msec); #endif // defined(ASIO_WINDOWS_APP) lock.lock(); state_ -= 2; } return (state_ & 1) != 0; }
// Re-initialise the hash from the values already contained in the list. void rehash(std::size_t num_buckets) { if (num_buckets == num_buckets_) return; num_buckets_ = num_buckets; ASIO_ASSERT(num_buckets_ != 0); iterator end_iter = values_.end(); // Update number of buckets and initialise all buckets to empty. bucket_type* tmp = new bucket_type[num_buckets_]; delete[] buckets_; buckets_ = tmp; for (std::size_t i = 0; i < num_buckets_; ++i) buckets_[i].first = buckets_[i].last = end_iter; // Put all values back into the hash. iterator iter = values_.begin(); while (iter != end_iter) { std::size_t bucket = calculate_hash_value(iter->first) % num_buckets_; if (buckets_[bucket].last == end_iter) { buckets_[bucket].first = buckets_[bucket].last = iter++; } else if (++buckets_[bucket].last == iter) { ++iter; } else { values_.splice(buckets_[bucket].last, values_, iter++); --buckets_[bucket].last; } } }
void signal(Lock& lock) { ASIO_ASSERT(lock.locked()); (void)lock; ::SetEvent(event_); }
void clear(Lock& lock) { ASIO_ASSERT(lock.locked()); (void)lock; ::ResetEvent(event_); }
void signal_and_unlock(Lock& lock) { ASIO_ASSERT(lock.locked()); lock.unlock(); ::SetEvent(event_); }
void clear(Lock& lock) { ASIO_ASSERT(lock.locked()); (void)lock; state_ &= ~std::size_t(1); }