Home | History | Annotate | Download | only in thread.lock.shared.mod
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // UNSUPPORTED: libcpp-has-no-threads
     11 // UNSUPPORTED: c++98, c++03, c++11
     12 
     13 // <shared_mutex>
     14 
     15 // template <class Mutex> class shared_lock;
     16 
     17 // template <class Mutex>
     18 //   void swap(shared_lock<Mutex>& x, shared_lock<Mutex>& y) noexcept;
     19 
     20 #include <shared_mutex>
     21 #include <cassert>
     22 
     23 struct mutex
     24 {
     25     void lock_shared() {}
     26     void unlock_shared() {}
     27 };
     28 
     29 mutex m;
     30 
     31 int main()
     32 {
     33     std::shared_lock<mutex> lk1(m);
     34     std::shared_lock<mutex> lk2;
     35     swap(lk1, lk2);
     36     assert(lk1.mutex() == nullptr);
     37     assert(lk1.owns_lock() == false);
     38     assert(lk2.mutex() == &m);
     39     assert(lk2.owns_lock() == true);
     40     static_assert(noexcept(swap(lk1, lk2)), "non-member swap must be noexcept");
     41 }
     42