Home | History | Annotate | Download | only in thread.mutex
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // On Windows Clang bugs out when both __declspec and __attribute__ are present,
     11 // the processing goes awry preventing the definition of the types.
     12 // XFAIL: LIBCXX-WINDOWS-FIXME
     13 
     14 // UNSUPPORTED: libcpp-has-no-threads
     15 // REQUIRES: thread-safety
     16 
     17 // <mutex>
     18 
     19 // MODULES_DEFINES: _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS
     20 #define _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS
     21 
     22 #include <mutex>
     23 
     24 #include "test_macros.h"
     25 
     26 std::mutex m;
     27 int foo __attribute__((guarded_by(m)));
     28 
     29 static void scoped() {
     30 #if TEST_STD_VER >= 17
     31   std::scoped_lock<std::mutex> lock(m);
     32   foo++;
     33 #endif
     34 }
     35 
     36 int main() {
     37   scoped();
     38   std::lock_guard<std::mutex> lock(m);
     39   foo++;
     40 }
     41