summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwin10helpers.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-10-17 13:00:04 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-11-22 11:32:35 +0000
commitd6c8fab8805f5085568065cdc8bfbfddfcfd8f2e (patch)
tree6e3364402c50dc52496a6ca0df003b4722175aa9 /src/plugins/platforms/windows/qwin10helpers.h
parent34c2a1dcf05661562cd00fe6dbdf884d8917933d (diff)
QMutex: make sure we try_lock_for no shorter than the duration passed
By templating on the <chrono> types and unconditionally using duration_cast to coerce the duration into a milliseconds, we allowed code such as mutex.try_lock_for(10us) to compile, which is misleading, since it's actually a zero- timeout try_lock(). Feedback from the std-discussions mailing list is that the wait_for functions should wait for _at least_ the duration given, because that is the natural direction of variance (tasks becoming ready to run might not get a CPU immediately, causing delays), while an interface that documents to wait _no more_ than the given duration is promising something it cannot fulfill. Fix by converting the given duration to the smallest number of milliseconds not less than the original duration. If that is not representable in an int, use INT_MAX, emulating the effect of a spurious wakeup, which are allowed to happen if the function returns false in that case. In the above example, the try_lock_for call is now equivalent to mutex.tryLock(1); The tryLock() docs state that the actual waiting time does not exceed the given milliseconds, but fixing that is a separate issue. Change-Id: Id4cbbea0ecc6fd2f94bb5aef28a1658be3728e52 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/plugins/platforms/windows/qwin10helpers.h')
0 files changed, 0 insertions, 0 deletions