xref: /llvm-project/libcxx/test/libcxx/thread/thread.mutex/thread_safety_requires_capability.pass.cpp (revision a7f9895cc18995549c7facb96e72718da282a864)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // On Windows Clang bugs out when both __declspec and __attribute__ are present,
10 // the processing goes awry preventing the definition of the types.
11 // XFAIL: msvc
12 
13 // UNSUPPORTED: no-threads
14 // REQUIRES: thread-safety
15 
16 // <mutex>
17 
18 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS
19 
20 #include <mutex>
21 
22 #include "test_macros.h"
23 
24 std::mutex m;
25 int foo __attribute__((guarded_by(m)));
26 
increment()27 void increment() __attribute__((requires_capability(m))) {
28   foo++;
29 }
30 
main(int,char **)31 int main(int, char**) {
32   m.lock();
33   increment();
34   m.unlock();
35 
36   return 0;
37 }
38