Annotate scoped_lock as with scoped_lockable attribute
authorAaron Puchert <aaronpuchert@alice-dsl.net>
Tue, 9 Oct 2018 23:42:29 +0000 (23:42 +0000)
committerAaron Puchert <aaronpuchert@alice-dsl.net>
Tue, 9 Oct 2018 23:42:29 +0000 (23:42 +0000)
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

llvm-svn: 344096

libcxx/include/mutex
libcxx/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp

index 9c55c7c..6d2de2b 100644 (file)
@@ -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:
index 6024d99..bd015fe 100644 (file)
 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++;
 }