| 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 |
|
| 11 |
// <mutex> |
| 12 |
|
| 13 |
// template <class Mutex> class unique_lock; |
| 14 |
|
| 15 |
// void unlock(); |
| 16 |
|
| 17 |
#include <cassert> |
| 18 |
#include <mutex> |
| 19 |
#include <system_error> |
| 20 |
|
| 21 |
#include "test_macros.h" |
| 22 |
|
| 23 |
bool unlock_called = false; |
| 24 |
|
| 25 |
struct mutex |
| 26 |
{ |
| 27 |
void lock() {} |
| 28 |
void unlock() {unlock_called = true;} |
| 29 |
}; |
| 30 |
|
| 31 |
mutex m; |
| 32 |
|
| 33 |
int main(int, char**) |
| 34 |
{ |
| 35 |
std::unique_lock<mutex> lk(m); |
| 36 |
lk.unlock(); |
| 37 |
assert(unlock_called == true); |
| 38 |
assert(lk.owns_lock() == false); |
| 39 |
#ifndef TEST_HAS_NO_EXCEPTIONS |
| 40 |
try |
| 41 |
{ |
| 42 |
lk.unlock(); |
| 43 |
assert(false); |
| 44 |
} |
| 45 |
catch (std::system_error& e) |
| 46 |
{ |
| 47 |
assert(e.code().value() == EPERM); |
| 48 |
} |
| 49 |
#endif |
| 50 |
lk.release(); |
| 51 |
#ifndef TEST_HAS_NO_EXCEPTIONS |
| 52 |
try |
| 53 |
{ |
| 54 |
lk.unlock(); |
| 55 |
assert(false); |
| 56 |
} |
| 57 |
catch (std::system_error& e) |
| 58 |
{ |
| 59 |
assert(e.code().value() == EPERM); |
| 60 |
} |
| 61 |
#endif |
| 62 |
|
| 63 |
return 0; |
| 64 |
} |