[libcxx] r344096 - Annotate scoped_lock as with scoped_lockable attribute
Aaron Puchert
aaronpuchert at alice-dsl.net
Tue Oct 9 16:42:29 PDT 2018
Author: aaronpuchert
Date: Tue Oct 9 16:42:29 2018
New Revision: 344096
URL: http://llvm.org/viewvc/llvm-project?rev=344096&view=rev
Log:
Annotate scoped_lock as with scoped_lockable attribute
Summary:
Scoped capabilities need to be annotated as such, otherwise the thread
safety analysis won't work as intended.
Fixes PR39234.
Reviewers: ldionne
Reviewed By: ldionne
Subscribers: christof, libcxx-commits
Differential Revision: https://reviews.llvm.org/D53049
Modified:
libcxx/trunk/include/mutex
libcxx/trunk/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp
Modified: libcxx/trunk/include/mutex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/mutex?rev=344096&r1=344095&r2=344096&view=diff
==============================================================================
--- libcxx/trunk/include/mutex (original)
+++ libcxx/trunk/include/mutex Tue Oct 9 16:42:29 2018
@@ -489,7 +489,7 @@ public:
};
template <class _Mutex>
-class _LIBCPP_TEMPLATE_VIS scoped_lock<_Mutex> {
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) scoped_lock<_Mutex> {
public:
typedef _Mutex mutex_type;
private:
Modified: libcxx/trunk/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp?rev=344096&r1=344095&r2=344096&view=diff
==============================================================================
--- libcxx/trunk/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp (original)
+++ libcxx/trunk/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp Tue Oct 9 16:42:29 2018
@@ -24,7 +24,13 @@
std::mutex m;
int foo __attribute__((guarded_by(m)));
+static void scoped() {
+ std::scoped_lock<std::mutex> lock(m);
+ foo++;
+}
+
int main() {
+ scoped();
std::lock_guard<std::mutex> lock(m);
foo++;
}
More information about the libcxx-commits
mailing list