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
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // <mutex>
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // template <class Mutex> class lock_guard;
145a83710eSEric Fiselier 
155a83710eSEric Fiselier // explicit lock_guard(mutex_type& m);
165a83710eSEric Fiselier 
176015dd11SMarshall Clow // template<class _Mutex> lock_guard(lock_guard<_Mutex>)
186015dd11SMarshall Clow //     -> lock_guard<_Mutex>;  // C++17
196015dd11SMarshall Clow 
205a83710eSEric Fiselier #include <mutex>
215a83710eSEric Fiselier #include <cstdlib>
225a83710eSEric Fiselier #include <cassert>
235a83710eSEric Fiselier 
2478036360SIgor Kudrin #include "make_test_thread.h"
256015dd11SMarshall Clow #include "test_macros.h"
266015dd11SMarshall Clow 
275a83710eSEric Fiselier std::mutex m;
285a83710eSEric Fiselier 
do_try_lock()2978036360SIgor Kudrin void do_try_lock() {
3078036360SIgor Kudrin   assert(m.try_lock() == false);
3178036360SIgor Kudrin }
3278036360SIgor Kudrin 
main(int,char **)33504bc07dSLouis Dionne int main(int, char**) {
345a83710eSEric Fiselier   {
355a83710eSEric Fiselier     std::lock_guard<std::mutex> lg(m);
3678036360SIgor Kudrin     std::thread t = support::make_test_thread(do_try_lock);
3778036360SIgor Kudrin     t.join();
385a83710eSEric Fiselier   }
395a83710eSEric Fiselier 
405a83710eSEric Fiselier   m.lock();
415a83710eSEric Fiselier   m.unlock();
426015dd11SMarshall Clow 
4301666904SLouis Dionne #if TEST_STD_VER >= 17
446015dd11SMarshall Clow   std::lock_guard lg(m);
456015dd11SMarshall Clow   static_assert((std::is_same<decltype(lg), std::lock_guard<decltype(m)>>::value), "" );
466015dd11SMarshall Clow #endif
472df59c50SJF Bastien 
482df59c50SJF Bastien   return 0;
495a83710eSEric Fiselier }
50