Debian Codegraph @

libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp

raw
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 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03
11
12 // <mutex>
13
14 // template <class Mutex> class unique_lock;
15
16 // unique_lock(mutex_type& m, defer_lock_t);
17
18 #include <mutex>
19 #include <cassert>
20 #include "nasty_containers.h"
21
22 #include "test_macros.h"
23
24 int main(int, char**)
25 {
26 {
27 typedef std::mutex M;
28 M m;
29 std::unique_lock<M> lk(m, std::defer_lock);
30 assert(lk.mutex() == std::addressof(m));
31 assert(lk.owns_lock() == false);
32 }
33 {
34 typedef nasty_mutex M;
35 M m;
36 std::unique_lock<M> lk(m, std::defer_lock);
37 assert(lk.mutex() == std::addressof(m));
38 assert(lk.owns_lock() == false);
39 }
40
41 return 0;
42 }