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

source code of libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp