[libcxx-commits] [PATCH] D154354: [libc++] Fix thread annotations on shared_mutex and shared_timed_mutex
Nikolas Klauser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jul 3 15:44:57 PDT 2023
philnik requested changes to this revision.
philnik added a comment.
This revision now requires changes to proceed.
In D154354#4469777 <https://reviews.llvm.org/D154354#4469777>, @aaronpuchert wrote:
> Thanks for picking this up!
>
> In D154354#4468666 <https://reviews.llvm.org/D154354#4468666>, @philnik wrote:
>
>> Could we add some sort of tests for this?
>
> There are several existing tests, see libcxx/test/libcxx/thread/thread.mutex/thread_safety_* <https://github.com/llvm/llvm-project/tree/main/libcxx/test/libcxx/thread/thread.mutex>. What should work:
>
> std::shared_mutex m;
> int data __attribute__((guarded_by(m)));
> void read(int);
>
> ++foo; // warning, but probably no need to test this: libc++ has
> // nothing to do with it, it's due to the attribute above.
> m.lock();
> ++foo; // ok.
> m.unlock();
>
> if (m.try_lock())
> ++foo; // ok.
> m.unlock();
>
> m.lock_shared();
> read(foo); // ok.
> ++foo; // warning.
> m.unlock_shared();
Then I definitely want some tests for this.
================
Comment at: libcxx/include/shared_mutex:199
// Exclusive ownership
- _LIBCPP_INLINE_VISIBILITY void lock() { return __base_.lock(); }
- _LIBCPP_INLINE_VISIBILITY bool try_lock() { return __base_.try_lock(); }
- _LIBCPP_INLINE_VISIBILITY void unlock() { return __base_.unlock(); }
+ _LIBCPP_INLINE_VISIBILITY void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability()) {
+ return __base_.lock();
----------------
As a fly-by we might as well _Uglify the attributes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154354/new/
https://reviews.llvm.org/D154354
More information about the libcxx-commits
mailing list