Преглед на файлове

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@344096 91177308-0d34-0410-b5e6-96231b3b80d8
Aaron Puchert преди 6 години
родител
ревизия
f7d5bd26cd
променени са 2 файла, в които са добавени 7 реда и са изтрити 1 реда
  1. 1 1
      include/mutex
  2. 6 0
      test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp

+ 1 - 1
include/mutex

@@ -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:

+ 6 - 0
test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp

@@ -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++;
 }