Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jonathan Roelofs | 8d86b2e | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 9 | // |
| 10 | // UNSUPPORTED: libcpp-has-no-threads |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 11 | |
| 12 | // <mutex> |
| 13 | |
| 14 | // template <class Mutex> class unique_lock; |
| 15 | |
| 16 | // void unlock(); |
| 17 | |
| 18 | #include <mutex> |
| 19 | #include <cassert> |
| 20 | |
| 21 | bool unlock_called = false; |
| 22 | |
| 23 | struct mutex |
| 24 | { |
| 25 | void lock() {} |
| 26 | void unlock() {unlock_called = true;} |
| 27 | }; |
| 28 | |
| 29 | mutex m; |
| 30 | |
| 31 | int main() |
| 32 | { |
| 33 | std::unique_lock<mutex> lk(m); |
| 34 | lk.unlock(); |
| 35 | assert(unlock_called == true); |
| 36 | assert(lk.owns_lock() == false); |
| 37 | try |
| 38 | { |
| 39 | lk.unlock(); |
| 40 | assert(false); |
| 41 | } |
| 42 | catch (std::system_error& e) |
| 43 | { |
| 44 | assert(e.code().value() == EPERM); |
| 45 | } |
| 46 | lk.release(); |
| 47 | try |
| 48 | { |
| 49 | lk.unlock(); |
| 50 | assert(false); |
| 51 | } |
| 52 | catch (std::system_error& e) |
| 53 | { |
| 54 | assert(e.code().value() == EPERM); |
| 55 | } |
| 56 | } |