[PATCH] D53049: Annotate scoped_lock as with scoped_lockable attribute

Aaron Puchert via Phabricator reviews at reviews.llvm.org
Tue Oct 9 15:36:07 PDT 2018


aaronpuchert created this revision.
aaronpuchert added a reviewer: ldionne.
Herald added subscribers: libcxx-commits, christof.

Scoped capabilities need to be annotated as such, otherwise the thread
safety analysis won't work as intended.

Fixes PR39234.


Repository:
  rCXX libc++

https://reviews.llvm.org/D53049

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


Index: test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp
===================================================================
--- test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp
+++ 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++;
 }
Index: include/mutex
===================================================================
--- include/mutex
+++ include/mutex
@@ -489,7 +489,7 @@
 };
 
 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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53049.168890.patch
Type: text/x-patch
Size: 896 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20181009/dd89c958/attachment.bin>


More information about the libcxx-commits mailing list