15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier //
9*a7f9895cSLouis Dionne // UNSUPPORTED: no-threads
1031cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11
115a83710eSEric Fiselier 
125a83710eSEric Fiselier // <shared_mutex>
135a83710eSEric Fiselier 
145a83710eSEric Fiselier // template <class Mutex> class shared_lock;
155a83710eSEric Fiselier 
165a83710eSEric Fiselier // void unlock();
175a83710eSEric Fiselier 
185a83710eSEric Fiselier #include <shared_mutex>
195a83710eSEric Fiselier #include <cassert>
206cb05ca3SChristopher Di Bella #include <system_error>
215a83710eSEric Fiselier 
2260d6ef63SRoger Ferrer Ibanez #include "test_macros.h"
2360d6ef63SRoger Ferrer Ibanez 
245a83710eSEric Fiselier bool unlock_called = false;
255a83710eSEric Fiselier 
265a83710eSEric Fiselier struct mutex
275a83710eSEric Fiselier {
lock_sharedmutex285a83710eSEric Fiselier     void lock_shared() {}
unlock_sharedmutex295a83710eSEric Fiselier     void unlock_shared() {unlock_called = true;}
305a83710eSEric Fiselier };
315a83710eSEric Fiselier 
325a83710eSEric Fiselier mutex m;
335a83710eSEric Fiselier 
main(int,char **)342df59c50SJF Bastien int main(int, char**)
355a83710eSEric Fiselier {
365a83710eSEric Fiselier     std::shared_lock<mutex> lk(m);
375a83710eSEric Fiselier     lk.unlock();
385a83710eSEric Fiselier     assert(unlock_called == true);
395a83710eSEric Fiselier     assert(lk.owns_lock() == false);
4060d6ef63SRoger Ferrer Ibanez #ifndef TEST_HAS_NO_EXCEPTIONS
415a83710eSEric Fiselier     try
425a83710eSEric Fiselier     {
435a83710eSEric Fiselier         lk.unlock();
445a83710eSEric Fiselier         assert(false);
455a83710eSEric Fiselier     }
465a83710eSEric Fiselier     catch (std::system_error& e)
475a83710eSEric Fiselier     {
485a83710eSEric Fiselier         assert(e.code().value() == EPERM);
495a83710eSEric Fiselier     }
5060d6ef63SRoger Ferrer Ibanez #endif
515a83710eSEric Fiselier     lk.release();
5260d6ef63SRoger Ferrer Ibanez #ifndef TEST_HAS_NO_EXCEPTIONS
535a83710eSEric Fiselier     try
545a83710eSEric Fiselier     {
555a83710eSEric Fiselier         lk.unlock();
565a83710eSEric Fiselier         assert(false);
575a83710eSEric Fiselier     }
585a83710eSEric Fiselier     catch (std::system_error& e)
595a83710eSEric Fiselier     {
605a83710eSEric Fiselier         assert(e.code().value() == EPERM);
615a83710eSEric Fiselier     }
6260d6ef63SRoger Ferrer Ibanez #endif
632df59c50SJF Bastien 
642df59c50SJF Bastien   return 0;
655a83710eSEric Fiselier }
66