summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qsemaphore.cpp
diff options
context:
space:
mode:
authorArtem Dyomin <artem.dyomin@qt.io>2023-09-12 14:46:30 +0200
committerArtem Dyomin <artem.dyomin@qt.io>2023-09-13 13:45:04 +0200
commit60113056bc4c328f62808d1c0fa2a1abec481f78 (patch)
treed809700995d26e3f5d906f394edf73aeff5357fd /src/corelib/thread/qsemaphore.cpp
parent4e9944e6c8a456353d243ab268cb0f01ff006faa (diff)
Optimize cond var notification
Notification of a conditional variable shouldn't be under the locked mutex, as it may affect extra mutex contentions. Pick-to: 6.5 6.6 Change-Id: Ie8429eca3f36e9a6e8e5ad2e0337bbf508f5b326 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread/qsemaphore.cpp')
-rw-r--r--src/corelib/thread/qsemaphore.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp
index c472e62698..2437c96595 100644
--- a/src/corelib/thread/qsemaphore.cpp
+++ b/src/corelib/thread/qsemaphore.cpp
@@ -400,8 +400,10 @@ void QSemaphore::release(int n)
return;
}
- const auto locker = qt_scoped_lock(d->mutex);
- d->avail += n;
+ {
+ const auto locker = qt_scoped_lock(d->mutex);
+ d->avail += n;
+ }
d->cond.notify_all();
}