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// <mutex>
10
11// template <class Mutex> class unique_lock;
12
13// bool owns_lock() const;
14
15#include <cassert>
16#include <mutex>
17
18#include "checking_mutex.h"
19#include "test_macros.h"
20
21#if TEST_STD_VER >= 11
22static_assert(noexcept(std::declval<std::unique_lock<checking_mutex>&>().owns_lock()), "");
23#endif
24
25int main(int, char**) {
26 {
27 checking_mutex mux;
28 const std::unique_lock<checking_mutex> lock0; // Make sure `owns_lock()` is `const`
29 assert(!lock0.owns_lock());
30 std::unique_lock<checking_mutex> lock1(mux);
31 assert(lock1.owns_lock());
32 lock1.unlock();
33 assert(!lock1.owns_lock());
34 }
35
36 return 0;
37}
38

source code of libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.obs/owns_lock.pass.cpp