CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
102 lines
2.5 KiB
ReStructuredText
102 lines
2.5 KiB
ReStructuredText
.. title:: clang-tidy - modernize-use-scoped-lock
|
|
|
|
modernize-use-scoped-lock
|
|
=========================
|
|
|
|
Finds uses of ``std::lock_guard`` and suggests replacing them with C++17's
|
|
alternative ``std::scoped_lock``.
|
|
|
|
Fix-its are provided for single declarations of ``std::lock_guard`` and warning
|
|
is emitted for multiple declarations of ``std::lock_guard`` that can be
|
|
replaced with a single declaration of ``std::scoped_lock``.
|
|
|
|
Examples
|
|
--------
|
|
|
|
Single ``std::lock_guard`` declaration:
|
|
|
|
.. code-block:: c++
|
|
|
|
std::mutex M;
|
|
std::lock_guard<std::mutex> L(M);
|
|
|
|
|
|
Transforms to:
|
|
|
|
.. code-block:: c++
|
|
|
|
std::mutex M;
|
|
std::scoped_lock L(M);
|
|
|
|
Single ``std::lock_guard`` declaration with ``std::adopt_lock``:
|
|
|
|
.. code-block:: c++
|
|
|
|
std::mutex M;
|
|
std::lock(M);
|
|
std::lock_guard<std::mutex> L(M, std::adopt_lock);
|
|
|
|
|
|
Transforms to:
|
|
|
|
.. code-block:: c++
|
|
|
|
std::mutex M;
|
|
std::lock(M);
|
|
std::scoped_lock L(std::adopt_lock, M);
|
|
|
|
Multiple ``std::lock_guard`` declarations only emit warnings:
|
|
|
|
.. code-block:: c++
|
|
|
|
std::mutex M1, M2;
|
|
std::lock(M1, M2);
|
|
std::lock_guard Lock1(M1, std::adopt_lock); // warning: use single 'std::scoped_lock' instead of multiple 'std::lock_guard'
|
|
std::lock_guard Lock2(M2, std::adopt_lock); // note: additional 'std::lock_guard' declared here
|
|
|
|
|
|
Limitations
|
|
-----------
|
|
|
|
The check will not emit warnings if ``std::lock_guard`` is used implicitly via
|
|
``template`` parameter:
|
|
|
|
.. code-block:: c++
|
|
|
|
template <template <typename> typename Lock>
|
|
void TemplatedLock() {
|
|
std::mutex M;
|
|
Lock<std::mutex> L(M); // no warning
|
|
}
|
|
|
|
void instantiate() {
|
|
TemplatedLock<std::lock_guard>();
|
|
}
|
|
|
|
|
|
Options
|
|
-------
|
|
|
|
.. option:: WarnOnSingleLocks
|
|
|
|
When `true`, the check will warn on single ``std::lock_guard`` declarations.
|
|
Set this option to `false` if you want to get warnings only on multiple
|
|
``std::lock_guard`` declarations that can be replaced with a single
|
|
``std::scoped_lock``. Default is `true`.
|
|
|
|
.. option:: WarnOnUsingAndTypedef
|
|
|
|
When `true`, the check will emit warnings if ``std::lock_guard`` is used
|
|
in ``using`` or ``typedef`` context. Default is `true`.
|
|
|
|
.. code-block:: c++
|
|
|
|
template <typename T>
|
|
using Lock = std::lock_guard<T>; // warning: use 'std::scoped_lock' instead of 'std::lock_guard'
|
|
|
|
using LockMutex = std::lock_guard<std::mutex>; // warning: use 'std::scoped_lock' instead of 'std::lock_guard'
|
|
|
|
typedef std::lock_guard<std::mutex> LockDef; // warning: use 'std::scoped_lock' instead of 'std::lock_guard'
|
|
|
|
using std::lock_guard; // warning: use 'std::scoped_lock' instead of 'std::lock_guard'
|