96#if defined(FUTEX_OP) && QT_POINTER_SIZE > 4
113 return int(
unsigned(
v));
115 return int(
v & 0x7fffffffU);
124 return unsigned(
quint64(
v) >> 32) >
unsigned(
v);
131#if Q_BYTE_ORDER == Q_BIG_ENDIAN && QT_POINTER_SIZE > 4
141#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN && QT_POINTER_SIZE > 4
147template <
bool IsTimed>
bool
151 using namespace std::chrono;
152 int n = int(
unsigned(nn));
164 curValue =
quint64(curValue) >> 32;
186 if (IsTimed &&
timer.hasExpired())
194template <
typename T>
bool
197 constexpr bool IsTimed = std::is_same_v<QDeadlineTimer, T>;
211 if constexpr (IsTimed) {
225 if (waiterCount == 0x7fffffffU) {
226 qCritical() <<
"Waiter count overflow in QSemaphore";
232 curValue += oneWaiter;
238 if (futexSemaphoreTryAcquire_loop<IsTimed>(u, curValue, nn,
timeout))
286 Q_ASSERT_X(
n >= 0,
"QSemaphore",
"parameter 'n' must be non-negative");
318#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
319# warning "Move the Q_ASSERT to inline code, make QSemaphore have wide contract, " \
320 "and mark noexcept where futexes are in use."
322 Q_ASSERT_X(
n >= 0,
"QSemaphore::acquire",
"parameter 'n' must be non-negative");
330 const auto sufficientResourcesAvailable = [
this,
n] {
return d->avail >=
n; };
332 auto locker = qt_unique_lock(
d->mutex);
333 d->cond.wait(locker, sufficientResourcesAvailable);
352 Q_ASSERT_X(
n >= 0,
"QSemaphore::release",
"parameter 'n' must be non-negative");
361 newValue = prevValue + nn;
403 const auto locker = qt_scoped_lock(
d->mutex);
405 d->cond.notify_all();
419 const auto locker = qt_scoped_lock(
d->mutex);
436 Q_ASSERT_X(
n >= 0,
"QSemaphore::tryAcquire",
"parameter 'n' must be non-negative");
441 const auto locker = qt_scoped_lock(
d->mutex);
482 if (
timer.isForever()) {
487 if (
timer.hasExpired())
490 Q_ASSERT_X(
n >= 0,
"QSemaphore::tryAcquire",
"parameter 'n' must be non-negative");
495 using namespace std::chrono;
496 const auto sufficientResourcesAvailable = [
this,
n] {
return d->avail >=
n; };
498 auto locker = qt_unique_lock(
d->mutex);
499 if (!
d->cond.wait_until(locker,
timer.deadline<steady_clock>(), sufficientResourcesAvailable))
T fetchAndOrRelaxed(T valueToAdd) noexcept
bool testAndSetOrdered(T expectedValue, T newValue) noexcept
void storeRelaxed(T newValue) noexcept
T loadAcquire() const noexcept
T fetchAndSubRelaxed(T valueToAdd) noexcept
T fetchAndAddRelaxed(T valueToAdd) noexcept
bool testAndSetRelease(T expectedValue, T newValue) noexcept
T loadRelaxed() const noexcept
ForeverConstant
\value Forever Used when creating a QDeadlineTimer to indicate the deadline should not expire
static constexpr ForeverConstant Forever
QSemaphorePrivate(qsizetype n)
~QSemaphore()
Destroys the semaphore.
void acquire(int n=1)
Tries to acquire n resources guarded by the semaphore.
QBasicAtomicInteger< quintptr > u
bool tryAcquire(int n=1)
Tries to acquire n resources guarded by the semaphore and returns true on success.
void release(int n=1)
Releases n resources guarded by the semaphore.
QSemaphore(int n=0)
Creates a new semaphore and initializes the number of resources it guards to n (by default,...
int available() const
Returns the number of resources currently available to the semaphore.
Combined button and popup list for selecting options.
void futexWakeAll(Atomic &futex)
void futexWait(Atomic &futex, typename Atomic::Type expectedValue)
constexpr bool futexAvailable()
static constexpr quintptr IdealMutexAlignment
std::conditional_t< sizeof(Layout1)<=sizeof(Layout2), Layout1, Layout2 > Members
static ControlElement< T > * ptr(QWidget *widget)
GLsizei const GLfloat * v
[13]
GLbitfield GLuint64 timeout
[4]
#define Q_ASSERT_X(cond, x, msg)
static QBasicAtomicInteger< quint32 > * futexHigh32(QBasicAtomicInteger< quintptr > *ptr)
static QBasicAtomicInteger< quint32 > * futexLow32(QBasicAtomicInteger< quintptr > *ptr)
static constexpr bool futexHasWaiterCount
bool futexSemaphoreTryAcquire_loop(QBasicAtomicInteger< quintptr > &u, quintptr curValue, quintptr nn, QDeadlineTimer timer)
static bool futexNeedsWake(quintptr v)
static constexpr quintptr futexNeedsWakeAllBit
static int futexAvailCounter(quintptr v)
static constexpr QDeadlineTimer::ForeverConstant Expired
bool futexSemaphoreTryAcquire(QBasicAtomicInteger< quintptr > &u, int n, T timeout)
unsigned long long quint64
std::condition_variable cond
std::condition_variable cond