brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 4f31a75 Raw
67 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// UNSUPPORTED: no-threads10// UNSUPPORTED: c++03, c++1111 12// <shared_mutex>13 14// template <class Mutex> class shared_lock;15 16// void unlock();17 18#include <cassert>19#include <cerrno>20#include <shared_mutex>21#include <system_error>22 23#include "test_macros.h"24 25bool unlock_called = false;26 27struct mutex28{29    void lock_shared() {}30    void unlock_shared() {unlock_called = true;}31};32 33mutex m;34 35int main(int, char**)36{37    std::shared_lock<mutex> lk(m);38    lk.unlock();39    assert(unlock_called == true);40    assert(lk.owns_lock() == false);41#ifndef TEST_HAS_NO_EXCEPTIONS42    try43    {44        lk.unlock();45        assert(false);46    }47    catch (std::system_error& e)48    {49        assert(e.code().value() == EPERM);50    }51#endif52    lk.release();53#ifndef TEST_HAS_NO_EXCEPTIONS54    try55    {56        lk.unlock();57        assert(false);58    }59    catch (std::system_error& e)60    {61        assert(e.code().value() == EPERM);62    }63#endif64 65  return 0;66}67