]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/libcxx/thread/thread.mutex/thread_safety_requires_capability.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / libcxx / thread / thread.mutex / thread_safety_requires_capability.pass.cpp
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 // UNSUPPORTED: libcpp-has-no-threads
11 // REQUIRES: thread-safety
12
13 // <mutex>
14
15 // MODULES_DEFINES: _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS
16 #define _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS
17
18 #include <mutex>
19
20 std::mutex m;
21 int foo __attribute__((guarded_by(m)));
22
23 void increment() __attribute__((requires_capability(m))) {
24   foo++;
25 }
26
27 int main() {
28   m.lock();
29   increment();
30   m.unlock();
31 }