mutex_defer_lock.pass.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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: libcpp-has-no-threads
  10. // UNSUPPORTED: c++98, c++03, c++11
  11. // XFAIL: dylib-has-no-shared_mutex
  12. // <shared_mutex>
  13. // template <class Mutex> class shared_lock;
  14. // shared_lock(mutex_type& m, defer_lock_t);
  15. #include <shared_mutex>
  16. #include <cassert>
  17. #include "nasty_containers.hpp"
  18. int main(int, char**)
  19. {
  20. {
  21. typedef std::shared_timed_mutex M;
  22. M m;
  23. std::unique_lock<M> lk(m, std::defer_lock);
  24. assert(lk.mutex() == std::addressof(m));
  25. assert(lk.owns_lock() == false);
  26. }
  27. {
  28. typedef nasty_mutex M;
  29. M m;
  30. std::unique_lock<M> lk(m, std::defer_lock);
  31. assert(lk.mutex() == std::addressof(m));
  32. assert(lk.owns_lock() == false);
  33. }
  34. return 0;
  35. }