QtCore: Remove std::mutex and std::condition_variable fallbacks
They existed because INTEGRITY hadn't yet been updated to the C++11 Standard Library, with a minor for broken MinGW cross-compilation builds that forgot to enable gthreads support in libstdc++. The former appears to have been since fixed and the latter is a massive toolchain configuration mistake. Change-Id: I63b988479db546dabffcfffd1766b55132371f9b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
b908c5cf28
commit
1a619ccb24
@ -411,7 +411,7 @@ void QReadWriteLock::unlock()
|
||||
}
|
||||
}
|
||||
|
||||
bool QReadWriteLockPrivate::lockForRead(std::unique_lock<QtPrivate::mutex> &lock, QDeadlineTimer timeout)
|
||||
bool QReadWriteLockPrivate::lockForRead(std::unique_lock<std::mutex> &lock, QDeadlineTimer timeout)
|
||||
{
|
||||
Q_ASSERT(!mutex.try_lock()); // mutex must be locked when entering this function
|
||||
|
||||
@ -432,7 +432,7 @@ bool QReadWriteLockPrivate::lockForRead(std::unique_lock<QtPrivate::mutex> &lock
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QReadWriteLockPrivate::lockForWrite(std::unique_lock<QtPrivate::mutex> &lock, QDeadlineTimer timeout)
|
||||
bool QReadWriteLockPrivate::lockForWrite(std::unique_lock<std::mutex> &lock, QDeadlineTimer timeout)
|
||||
{
|
||||
Q_ASSERT(!mutex.try_lock()); // mutex must be locked when entering this function
|
||||
|
||||
|
@ -45,10 +45,10 @@ public:
|
||||
explicit QReadWriteLockPrivate(bool isRecursive = false)
|
||||
: recursive(isRecursive) {}
|
||||
|
||||
alignas(QtPrivate::IdealMutexAlignment) QtPrivate::condition_variable writerCond;
|
||||
QtPrivate::condition_variable readerCond;
|
||||
alignas(QtPrivate::IdealMutexAlignment) std::condition_variable writerCond;
|
||||
std::condition_variable readerCond;
|
||||
|
||||
alignas(QtPrivate::IdealMutexAlignment) QtPrivate::mutex mutex;
|
||||
alignas(QtPrivate::IdealMutexAlignment) std::mutex mutex;
|
||||
int readerCount = 0;
|
||||
int writerCount = 0;
|
||||
int waitingReaders = 0;
|
||||
@ -56,8 +56,8 @@ public:
|
||||
const bool recursive;
|
||||
|
||||
//Called with the mutex locked
|
||||
bool lockForWrite(std::unique_lock<QtPrivate::mutex> &lock, QDeadlineTimer timeout);
|
||||
bool lockForRead(std::unique_lock<QtPrivate::mutex> &lock, QDeadlineTimer timeout);
|
||||
bool lockForWrite(std::unique_lock<std::mutex> &lock, QDeadlineTimer timeout);
|
||||
bool lockForRead(std::unique_lock<std::mutex> &lock, QDeadlineTimer timeout);
|
||||
void unlock();
|
||||
|
||||
//memory management
|
||||
|
@ -255,15 +255,15 @@ namespace { namespace QtSemaphorePrivate {
|
||||
using namespace QtPrivate;
|
||||
struct Layout1
|
||||
{
|
||||
alignas(IdealMutexAlignment) QtPrivate::mutex mutex;
|
||||
alignas(IdealMutexAlignment) std::mutex mutex;
|
||||
qsizetype avail = 0;
|
||||
alignas(IdealMutexAlignment) QtPrivate::condition_variable cond;
|
||||
alignas(IdealMutexAlignment) std::condition_variable cond;
|
||||
};
|
||||
|
||||
struct Layout2
|
||||
{
|
||||
alignas(IdealMutexAlignment) QtPrivate::mutex mutex;
|
||||
alignas(IdealMutexAlignment) QtPrivate::condition_variable cond;
|
||||
alignas(IdealMutexAlignment) std::mutex mutex;
|
||||
alignas(IdealMutexAlignment) std::condition_variable cond;
|
||||
qsizetype avail = 0;
|
||||
};
|
||||
|
||||
|
@ -19,116 +19,18 @@
|
||||
#include <QtCore/QDeadlineTimer>
|
||||
#include <QtCore/private/qglobal_p.h>
|
||||
|
||||
// This header always defines a class called "mutex" and one called
|
||||
// "condition_variable", so those mustn't be used to mark ELF symbol
|
||||
// visibility. Don't add more classes to this header!
|
||||
// ELFVERSION:stop
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
// There's no feature macro for C++11 std::mutex, so we use the C++14 one
|
||||
// for shared_mutex to detect it.
|
||||
// Needed for: MinGW without gthreads, Integrity
|
||||
#if __has_include(<shared_mutex>)
|
||||
# include <shared_mutex>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace QtPrivate {
|
||||
|
||||
#if !defined(__cpp_lib_shared_timed_mutex)
|
||||
|
||||
enum class cv_status { no_timeout, timeout };
|
||||
class condition_variable;
|
||||
|
||||
class mutex : private QMutex
|
||||
{
|
||||
friend class QtPrivate::condition_variable;
|
||||
|
||||
public:
|
||||
// all special member functions are ok!
|
||||
// do not expose the (QMutex::Recursive) ctor
|
||||
// don't use 'using QMutex::lock;' etc as those have the wrong noexcept
|
||||
|
||||
void lock() { return QMutex::lock(); }
|
||||
void unlock() { return QMutex::unlock(); }
|
||||
bool try_lock() { return QMutex::tryLock(); }
|
||||
};
|
||||
|
||||
class condition_variable : private QWaitCondition
|
||||
{
|
||||
public:
|
||||
// all special member functions are ok!
|
||||
|
||||
void notify_one() { QWaitCondition::wakeOne(); }
|
||||
void notify_all() { QWaitCondition::wakeAll(); }
|
||||
|
||||
void wait(std::unique_lock<QtPrivate::mutex> &lock) { QWaitCondition::wait(lock.mutex()); }
|
||||
template <class Predicate>
|
||||
void wait(std::unique_lock<QtPrivate::mutex> &lock, Predicate p)
|
||||
{
|
||||
while (!p())
|
||||
wait(lock);
|
||||
}
|
||||
|
||||
template <typename Rep, typename Period>
|
||||
cv_status wait_for(std::unique_lock<QtPrivate::mutex> &lock,
|
||||
const std::chrono::duration<Rep, Period> &d)
|
||||
{
|
||||
return QWaitCondition::wait(lock.mutex(), QDeadlineTimer{d})
|
||||
? cv_status::no_timeout
|
||||
: cv_status::timeout;
|
||||
}
|
||||
template <typename Rep, typename Period, typename Predicate>
|
||||
bool wait_for(std::unique_lock<QtPrivate::mutex> &lock,
|
||||
const std::chrono::duration<Rep, Period> &d, Predicate p)
|
||||
{
|
||||
const auto timer = QDeadlineTimer{d};
|
||||
while (!p()) {
|
||||
if (!QWaitCondition::wait(lock.mutex(), timer))
|
||||
return p();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Clock, typename Duration>
|
||||
cv_status wait_until(std::unique_lock<QtPrivate::mutex> &lock,
|
||||
const std::chrono::time_point<Clock, Duration> &t)
|
||||
{
|
||||
return QWaitCondition::wait(lock.mutex(), QDeadlineTimer{t})
|
||||
? cv_status::no_timeout
|
||||
: cv_status::timeout;
|
||||
}
|
||||
|
||||
template <typename Clock, typename Duration, typename Predicate>
|
||||
bool wait_until(std::unique_lock<QtPrivate::mutex> &lock,
|
||||
const std::chrono::time_point<Clock, Duration> &t, Predicate p)
|
||||
{
|
||||
const auto timer = QDeadlineTimer{t};
|
||||
while (!p()) {
|
||||
if (!QWaitCondition::wait(lock.mutex(), timer))
|
||||
return p();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#else // C++11 threads
|
||||
|
||||
using mutex = std::mutex;
|
||||
using condition_variable = std::condition_variable;
|
||||
|
||||
#endif // C++11 threads
|
||||
|
||||
// Ideal alignment for mutex and condition_variable: it's the hardware
|
||||
// interference size (size of a cache line) if the types are likely to contain
|
||||
// the actual data structures, otherwise just that of a pointer.
|
||||
static constexpr quintptr IdealMutexAlignment =
|
||||
sizeof(QtPrivate::mutex) > sizeof(void *) &&
|
||||
sizeof(QtPrivate::condition_variable) > sizeof(void *) ?
|
||||
sizeof(std::mutex) > sizeof(void *) &&
|
||||
sizeof(std::condition_variable) > sizeof(void *) ?
|
||||
64 : alignof(void*);
|
||||
|
||||
} // namespace QtPrivate
|
||||
|
@ -1231,7 +1231,7 @@ class WatchDog : public QThread
|
||||
static constexpr Expectation combine(Expectation e, size_t gen) noexcept
|
||||
{ return Expectation{e | (gen << GenerationShift)}; }
|
||||
|
||||
bool waitFor(std::unique_lock<QtPrivate::mutex> &m, Expectation e)
|
||||
bool waitFor(std::unique_lock<std::mutex> &m, Expectation e)
|
||||
{
|
||||
auto expectationChanged = [this, e] { return expecting.load(std::memory_order_relaxed) != e; };
|
||||
switch (state(e)) {
|
||||
@ -1310,8 +1310,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
QtPrivate::mutex mutex;
|
||||
QtPrivate::condition_variable waitCondition;
|
||||
std::mutex mutex;
|
||||
std::condition_variable waitCondition;
|
||||
std::atomic<Expectation> expecting;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user