Move test into test/std subdirectory.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2014-12-20 01:40:03 +00:00
parent 669a8a5a19
commit a90c6dd460
4817 changed files with 13 additions and 0 deletions

View File

@@ -0,0 +1,507 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class L1, class L2, class... L3>
// void lock(L1&, L2&, L3&...);
#include <mutex>
#include <cassert>
class L0
{
bool locked_;
public:
L0() : locked_(false) {}
void lock()
{
locked_ = true;
}
bool try_lock()
{
locked_ = true;
return locked_;
}
void unlock() {locked_ = false;}
bool locked() const {return locked_;}
};
class L1
{
bool locked_;
public:
L1() : locked_(false) {}
void lock()
{
locked_ = true;
}
bool try_lock()
{
locked_ = false;
return locked_;
}
void unlock() {locked_ = false;}
bool locked() const {return locked_;}
};
class L2
{
bool locked_;
public:
L2() : locked_(false) {}
void lock()
{
throw 1;
}
bool try_lock()
{
throw 1;
return locked_;
}
void unlock() {locked_ = false;}
bool locked() const {return locked_;}
};
int main()
{
{
L0 l0;
L0 l1;
std::lock(l0, l1);
assert(l0.locked());
assert(l1.locked());
}
{
L0 l0;
L1 l1;
std::lock(l0, l1);
assert(l0.locked());
assert(l1.locked());
}
{
L1 l0;
L0 l1;
std::lock(l0, l1);
assert(l0.locked());
assert(l1.locked());
}
{
L0 l0;
L2 l1;
try
{
std::lock(l0, l1);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
}
}
{
L2 l0;
L0 l1;
try
{
std::lock(l0, l1);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
}
}
{
L1 l0;
L2 l1;
try
{
std::lock(l0, l1);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
}
}
{
L2 l0;
L1 l1;
try
{
std::lock(l0, l1);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
}
}
{
L2 l0;
L2 l1;
try
{
std::lock(l0, l1);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
}
}
#ifndef _LIBCPP_HAS_NO_VARIADICS
{
L0 l0;
L0 l1;
L0 l2;
std::lock(l0, l1, l2);
assert(l0.locked());
assert(l1.locked());
assert(l2.locked());
}
{
L2 l0;
L2 l1;
L2 l2;
try
{
std::lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L0 l0;
L0 l1;
L1 l2;
std::lock(l0, l1, l2);
assert(l0.locked());
assert(l1.locked());
assert(l2.locked());
}
{
L0 l0;
L1 l1;
L0 l2;
std::lock(l0, l1, l2);
assert(l0.locked());
assert(l1.locked());
assert(l2.locked());
}
{
L1 l0;
L0 l1;
L0 l2;
std::lock(l0, l1, l2);
assert(l0.locked());
assert(l1.locked());
assert(l2.locked());
}
{
L0 l0;
L0 l1;
L2 l2;
try
{
std::lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L0 l0;
L2 l1;
L0 l2;
try
{
std::lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L2 l0;
L0 l1;
L0 l2;
try
{
std::lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L2 l0;
L2 l1;
L0 l2;
try
{
std::lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L2 l0;
L0 l1;
L2 l2;
try
{
std::lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L0 l0;
L2 l1;
L2 l2;
try
{
std::lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L2 l0;
L2 l1;
L1 l2;
try
{
std::lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L2 l0;
L1 l1;
L2 l2;
try
{
std::lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L1 l0;
L2 l1;
L2 l2;
try
{
std::lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L0 l0;
L0 l1;
L0 l2;
L0 l3;
std::lock(l0, l1, l2, l3);
assert(l0.locked());
assert(l1.locked());
assert(l2.locked());
assert(l3.locked());
}
{
L0 l0;
L0 l1;
L0 l2;
L1 l3;
std::lock(l0, l1, l2, l3);
assert(l0.locked());
assert(l1.locked());
assert(l2.locked());
assert(l3.locked());
}
{
L0 l0;
L0 l1;
L1 l2;
L0 l3;
std::lock(l0, l1, l2, l3);
assert(l0.locked());
assert(l1.locked());
assert(l2.locked());
assert(l3.locked());
}
{
L0 l0;
L1 l1;
L0 l2;
L0 l3;
std::lock(l0, l1, l2, l3);
assert(l0.locked());
assert(l1.locked());
assert(l2.locked());
assert(l3.locked());
}
{
L1 l0;
L0 l1;
L0 l2;
L0 l3;
std::lock(l0, l1, l2, l3);
assert(l0.locked());
assert(l1.locked());
assert(l2.locked());
assert(l3.locked());
}
{
L0 l0;
L0 l1;
L0 l2;
L2 l3;
try
{
std::lock(l0, l1, l2, l3);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
assert(!l3.locked());
}
}
{
L0 l0;
L0 l1;
L2 l2;
L0 l3;
try
{
std::lock(l0, l1, l2, l3);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
assert(!l3.locked());
}
}
{
L0 l0;
L2 l1;
L0 l2;
L0 l3;
try
{
std::lock(l0, l1, l2, l3);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
assert(!l3.locked());
}
}
{
L2 l0;
L0 l1;
L0 l2;
L0 l3;
try
{
std::lock(l0, l1, l2, l3);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
assert(!l3.locked());
}
}
#endif // _LIBCPP_HAS_NO_VARIADICS
}

View File

@@ -0,0 +1,516 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class L1, class L2, class... L3>
// int try_lock(L1&, L2&, L3&...);
#include <mutex>
#include <cassert>
class L0
{
bool locked_;
public:
L0() : locked_(false) {}
bool try_lock()
{
locked_ = true;
return locked_;
}
void unlock() {locked_ = false;}
bool locked() const {return locked_;}
};
class L1
{
bool locked_;
public:
L1() : locked_(false) {}
bool try_lock()
{
locked_ = false;
return locked_;
}
void unlock() {locked_ = false;}
bool locked() const {return locked_;}
};
class L2
{
bool locked_;
public:
L2() : locked_(false) {}
bool try_lock()
{
throw 1;
return locked_;
}
void unlock() {locked_ = false;}
bool locked() const {return locked_;}
};
int main()
{
{
L0 l0;
L0 l1;
assert(std::try_lock(l0, l1) == -1);
assert(l0.locked());
assert(l1.locked());
}
{
L0 l0;
L1 l1;
assert(std::try_lock(l0, l1) == 1);
assert(!l0.locked());
assert(!l1.locked());
}
{
L1 l0;
L0 l1;
assert(std::try_lock(l0, l1) == 0);
assert(!l0.locked());
assert(!l1.locked());
}
{
L0 l0;
L2 l1;
try
{
std::try_lock(l0, l1);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
}
}
{
L2 l0;
L0 l1;
try
{
std::try_lock(l0, l1);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
}
}
#ifndef _LIBCPP_HAS_NO_VARIADICS
{
L0 l0;
L0 l1;
L0 l2;
assert(std::try_lock(l0, l1, l2) == -1);
assert(l0.locked());
assert(l1.locked());
assert(l2.locked());
}
{
L1 l0;
L1 l1;
L1 l2;
assert(std::try_lock(l0, l1, l2) == 0);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L2 l0;
L2 l1;
L2 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L0 l0;
L1 l1;
L2 l2;
assert(std::try_lock(l0, l1, l2) == 1);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L0 l0;
L0 l1;
L1 l2;
assert(std::try_lock(l0, l1, l2) == 2);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L0 l0;
L1 l1;
L0 l2;
assert(std::try_lock(l0, l1, l2) == 1);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L1 l0;
L0 l1;
L0 l2;
assert(std::try_lock(l0, l1, l2) == 0);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L0 l0;
L0 l1;
L2 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L0 l0;
L2 l1;
L0 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L2 l0;
L0 l1;
L0 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L1 l0;
L1 l1;
L0 l2;
assert(std::try_lock(l0, l1, l2) == 0);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L1 l0;
L0 l1;
L1 l2;
assert(std::try_lock(l0, l1, l2) == 0);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L0 l0;
L1 l1;
L1 l2;
assert(std::try_lock(l0, l1, l2) == 1);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L1 l0;
L1 l1;
L2 l2;
assert(std::try_lock(l0, l1, l2) == 0);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L1 l0;
L2 l1;
L1 l2;
assert(std::try_lock(l0, l1, l2) == 0);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L2 l0;
L1 l1;
L1 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L2 l0;
L2 l1;
L0 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L2 l0;
L0 l1;
L2 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L0 l0;
L2 l1;
L2 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L2 l0;
L2 l1;
L1 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L2 l0;
L1 l1;
L2 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L1 l0;
L2 l1;
L2 l2;
assert(std::try_lock(l0, l1, l2) == 0);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L0 l0;
L2 l1;
L1 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L1 l0;
L0 l1;
L2 l2;
assert(std::try_lock(l0, l1, l2) == 0);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L1 l0;
L2 l1;
L0 l2;
assert(std::try_lock(l0, l1, l2) == 0);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
{
L2 l0;
L0 l1;
L1 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L2 l0;
L1 l1;
L0 l2;
try
{
std::try_lock(l0, l1, l2);
assert(false);
}
catch (int)
{
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
}
}
{
L0 l0;
L0 l1;
L0 l2;
L0 l3;
assert(std::try_lock(l0, l1, l2, l3) == -1);
assert(l0.locked());
assert(l1.locked());
assert(l2.locked());
assert(l3.locked());
}
{
L1 l0;
L0 l1;
L0 l2;
L0 l3;
assert(std::try_lock(l0, l1, l2, l3) == 0);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
assert(!l3.locked());
}
{
L0 l0;
L1 l1;
L0 l2;
L0 l3;
assert(std::try_lock(l0, l1, l2, l3) == 1);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
assert(!l3.locked());
}
{
L0 l0;
L0 l1;
L1 l2;
L0 l3;
assert(std::try_lock(l0, l1, l2, l3) == 2);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
assert(!l3.locked());
}
{
L0 l0;
L0 l1;
L0 l2;
L1 l3;
assert(std::try_lock(l0, l1, l2, l3) == 3);
assert(!l0.locked());
assert(!l1.locked());
assert(!l2.locked());
assert(!l3.locked());
}
#endif // _LIBCPP_HAS_NO_VARIADICS
}

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class lock_guard;
// lock_guard(mutex_type& m, adopt_lock_t);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
time_point t1;
{
m.lock();
std::lock_guard<std::mutex> lg(m, std::adopt_lock);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// template <class Mutex> class lock_guard;
// lock_guard& operator=(lock_guard const&) = delete;
#include <mutex>
int main()
{
std::mutex m0;
std::mutex m1;
std::lock_guard<std::mutex> lg0(m0);
std::lock_guard<std::mutex> lg(m1);
lg = lg0;
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// template <class Mutex> class lock_guard;
// lock_guard(lock_guard const&) = delete;
#include <mutex>
int main()
{
std::mutex m;
std::lock_guard<std::mutex> lg0(m);
std::lock_guard<std::mutex> lg(lg0);
}

View File

@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// template <class Mutex> class lock_guard;
// explicit lock_guard(mutex_type& m);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
time_point t1;
{
std::lock_guard<std::mutex> lg = m;
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
assert(d < ns(2500000)); // within 2.5ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class lock_guard;
// explicit lock_guard(mutex_type& m);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
time_point t1;
{
std::lock_guard<std::mutex> lg(m);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
assert(d < ms(200)); // within 200ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex>
// class lock_guard
// {
// public:
// typedef Mutex mutex_type;
// ...
// };
#include <mutex>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::lock_guard<std::mutex>::mutex_type,
std::mutex>::value), "");
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <shared_mutex>
// template <class Mutex> class shared_lock;
// shared_lock& operator=(shared_lock const&) = delete;
#include <shared_mutex>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m0;
std::shared_timed_mutex m1;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<std::shared_timed_mutex> lk0(m0);
std::shared_lock<std::shared_timed_mutex> lk1(m1);
lk1 = lk0;
#else
# error
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <shared_mutex>
// template <class Mutex> class shared_lock;
// shared_lock(shared_lock const&) = delete;
#include <shared_mutex>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<std::shared_timed_mutex> lk0(m);
std::shared_lock<std::shared_timed_mutex> lk = lk0;
#else
# error
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// shared_lock();
#include <shared_mutex>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<std::shared_timed_mutex> ul;
assert(!ul.owns_lock());
assert(ul.mutex() == nullptr);
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// shared_lock& operator=(shared_lock&& u);
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m0;
std::shared_timed_mutex m1;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<std::shared_timed_mutex> lk0(m0);
std::shared_lock<std::shared_timed_mutex> lk1(m1);
lk1 = std::move(lk0);
assert(lk1.mutex() == &m0);
assert(lk1.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// shared_lock(shared_lock&& u);
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<std::shared_timed_mutex> lk0(m);
std::shared_lock<std::shared_timed_mutex> lk = std::move(lk0);
assert(lk.mutex() == &m);
assert(lk.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// explicit shared_lock(mutex_type& m);
#include <shared_mutex>
#include <thread>
#include <vector>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
time_point t1;
{
std::shared_lock<std::shared_timed_mutex> ul(m);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
void g()
{
time_point t0 = Clock::now();
time_point t1;
{
std::shared_lock<std::shared_timed_mutex> ul(m);
t1 = Clock::now();
}
ns d = t1 - t0;
assert(d < ms(50)); // within 50ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f));
std::this_thread::sleep_for(ms(250));
m.unlock();
for (auto& t : v)
t.join();
m.lock_shared();
for (auto& t : v)
t = std::thread(g);
std::thread q(f);
std::this_thread::sleep_for(ms(250));
m.unlock_shared();
for (auto& t : v)
t.join();
q.join();
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// shared_lock(mutex_type& m, adopt_lock_t);
#include <shared_mutex>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
m.lock();
std::shared_lock<std::shared_timed_mutex> lk(m, std::adopt_lock);
assert(lk.mutex() == &m);
assert(lk.owns_lock() == true);
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// shared_lock(mutex_type& m, defer_lock_t);
#include <shared_mutex>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
std::shared_lock<std::shared_timed_mutex> lk(m, std::defer_lock);
assert(lk.mutex() == &m);
assert(lk.owns_lock() == false);
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// class timed_mutex;
// template <class Rep, class Period>
// shared_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
#include <shared_mutex>
#include <thread>
#include <vector>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
std::shared_lock<std::shared_timed_mutex> lk(m, ms(300));
assert(lk.owns_lock() == true);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
std::shared_lock<std::shared_timed_mutex> lk(m, ms(250));
assert(lk.owns_lock() == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
{
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f1));
std::this_thread::sleep_for(ms(250));
m.unlock();
for (auto& t : v)
t.join();
}
{
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f2));
std::this_thread::sleep_for(ms(300));
m.unlock();
for (auto& t : v)
t.join();
}
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// class shared_timed_mutex;
// template <class Clock, class Duration>
// shared_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
#include <shared_mutex>
#include <thread>
#include <vector>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
std::shared_lock<std::shared_timed_mutex> lk(m, Clock::now() + ms(300));
assert(lk.owns_lock() == true);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ns(50000000)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
std::shared_lock<std::shared_timed_mutex> lk(m, Clock::now() + ms(250));
assert(lk.owns_lock() == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
{
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f1));
std::this_thread::sleep_for(ms(250));
m.unlock();
for (auto& t : v)
t.join();
}
{
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f2));
std::this_thread::sleep_for(ms(300));
m.unlock();
for (auto& t : v)
t.join();
}
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// shared_lock(mutex_type& m, try_to_lock_t);
#include <shared_mutex>
#include <thread>
#include <vector>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
{
std::shared_lock<std::shared_timed_mutex> lk(m, std::try_to_lock);
assert(lk.owns_lock() == false);
}
{
std::shared_lock<std::shared_timed_mutex> lk(m, std::try_to_lock);
assert(lk.owns_lock() == false);
}
{
std::shared_lock<std::shared_timed_mutex> lk(m, std::try_to_lock);
assert(lk.owns_lock() == false);
}
while (true)
{
std::shared_lock<std::shared_timed_mutex> lk(m, std::try_to_lock);
if (lk.owns_lock())
break;
}
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(200)); // within 200ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f));
std::this_thread::sleep_for(ms(250));
m.unlock();
for (auto& t : v)
t.join();
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// void lock();
#include <shared_mutex>
#include <thread>
#include <vector>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
std::shared_lock<std::shared_timed_mutex> lk(m, std::defer_lock);
time_point t0 = Clock::now();
lk.lock();
time_point t1 = Clock::now();
assert(lk.owns_lock() == true);
ns d = t1 - t0 - ms(250);
assert(d < ms(25)); // within 25ms
try
{
lk.lock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EDEADLK);
}
lk.unlock();
lk.release();
try
{
lk.lock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f));
std::this_thread::sleep_for(ms(250));
m.unlock();
for (auto& t : v)
t.join();
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// bool try_lock();
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
bool try_lock_called = false;
struct mutex
{
bool try_lock_shared()
{
try_lock_called = !try_lock_called;
return try_lock_called;
}
void unlock_shared() {}
};
mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<mutex> lk(m, std::defer_lock);
assert(lk.try_lock() == true);
assert(try_lock_called == true);
assert(lk.owns_lock() == true);
try
{
lk.try_lock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EDEADLK);
}
lk.unlock();
assert(lk.try_lock() == false);
assert(try_lock_called == false);
assert(lk.owns_lock() == false);
lk.release();
try
{
lk.try_lock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,75 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// template <class Rep, class Period>
// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
bool try_lock_for_called = false;
typedef std::chrono::milliseconds ms;
struct mutex
{
template <class Rep, class Period>
bool try_lock_shared_for(const std::chrono::duration<Rep, Period>& rel_time)
{
assert(rel_time == ms(5));
try_lock_for_called = !try_lock_for_called;
return try_lock_for_called;
}
void unlock_shared() {}
};
mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<mutex> lk(m, std::defer_lock);
assert(lk.try_lock_for(ms(5)) == true);
assert(try_lock_for_called == true);
assert(lk.owns_lock() == true);
try
{
lk.try_lock_for(ms(5));
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EDEADLK);
}
lk.unlock();
assert(lk.try_lock_for(ms(5)) == false);
assert(try_lock_for_called == false);
assert(lk.owns_lock() == false);
lk.release();
try
{
lk.try_lock_for(ms(5));
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,75 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// template <class Clock, class Duration>
// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
bool try_lock_until_called = false;
struct mutex
{
template <class Clock, class Duration>
bool try_lock_shared_until(const std::chrono::time_point<Clock, Duration>& abs_time)
{
typedef std::chrono::milliseconds ms;
assert(Clock::now() - abs_time < ms(5));
try_lock_until_called = !try_lock_until_called;
return try_lock_until_called;
}
void unlock_shared() {}
};
mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
typedef std::chrono::steady_clock Clock;
std::shared_lock<mutex> lk(m, std::defer_lock);
assert(lk.try_lock_until(Clock::now()) == true);
assert(try_lock_until_called == true);
assert(lk.owns_lock() == true);
try
{
lk.try_lock_until(Clock::now());
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EDEADLK);
}
lk.unlock();
assert(lk.try_lock_until(Clock::now()) == false);
assert(try_lock_until_called == false);
assert(lk.owns_lock() == false);
lk.release();
try
{
lk.try_lock_until(Clock::now());
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,62 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// void unlock();
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
bool unlock_called = false;
struct mutex
{
void lock_shared() {}
void unlock_shared() {unlock_called = true;}
};
mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<mutex> lk(m);
lk.unlock();
assert(unlock_called == true);
assert(lk.owns_lock() == false);
try
{
lk.unlock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
lk.release();
try
{
lk.unlock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,45 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// void swap(shared_lock& u) noexcept;
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
struct mutex
{
void lock_shared() {}
void unlock_shared() {}
};
mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<mutex> lk1(m);
std::shared_lock<mutex> lk2;
lk1.swap(lk2);
assert(lk1.mutex() == nullptr);
assert(lk1.owns_lock() == false);
assert(lk2.mutex() == &m);
assert(lk2.owns_lock() == true);
static_assert(noexcept(lk1.swap(lk2)), "member swap must be noexcept");
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// template <class Mutex>
// void swap(shared_lock<Mutex>& x, shared_lock<Mutex>& y) noexcept;
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
struct mutex
{
void lock_shared() {}
void unlock_shared() {}
};
mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<mutex> lk1(m);
std::shared_lock<mutex> lk2;
swap(lk1, lk2);
assert(lk1.mutex() == nullptr);
assert(lk1.owns_lock() == false);
assert(lk2.mutex() == &m);
assert(lk2.owns_lock() == true);
static_assert(noexcept(swap(lk1, lk2)), "non-member swap must be noexcept");
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// mutex_type* release() noexcept;
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
struct mutex
{
static int lock_count;
static int unlock_count;
void lock_shared() {++lock_count;}
void unlock_shared() {++unlock_count;}
};
int mutex::lock_count = 0;
int mutex::unlock_count = 0;
mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<mutex> lk(m);
assert(lk.mutex() == &m);
assert(lk.owns_lock() == true);
assert(mutex::lock_count == 1);
assert(mutex::unlock_count == 0);
assert(lk.release() == &m);
assert(lk.mutex() == nullptr);
assert(lk.owns_lock() == false);
assert(mutex::lock_count == 1);
assert(mutex::unlock_count == 0);
static_assert(noexcept(lk.release()), "release must be noexcept");
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// mutex_type *mutex() const noexcept;
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<std::shared_timed_mutex> lk0;
assert(lk0.mutex() == nullptr);
std::shared_lock<std::shared_timed_mutex> lk1(m);
assert(lk1.mutex() == &m);
lk1.unlock();
assert(lk1.mutex() == &m);
static_assert(noexcept(lk0.mutex()), "mutex() must be noexcept");
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// explicit operator bool() const noexcept;
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<std::shared_timed_mutex> lk0;
assert(static_cast<bool>(lk0) == false);
std::shared_lock<std::shared_timed_mutex> lk1(m);
assert(static_cast<bool>(lk1) == true);
lk1.unlock();
assert(static_cast<bool>(lk1) == false);
static_assert(noexcept(static_cast<bool>(lk0)), "explicit operator bool() must be noexcept");
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex> class shared_lock;
// bool owns_lock() const noexcept;
#include <shared_mutex>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_lock<std::shared_timed_mutex> lk0;
assert(lk0.owns_lock() == false);
std::shared_lock<std::shared_timed_mutex> lk1(m);
assert(lk1.owns_lock() == true);
lk1.unlock();
assert(lk1.owns_lock() == false);
static_assert(noexcept(lk0.owns_lock()), "owns_lock must be noexcept");
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// template <class Mutex>
// class shared_lock
// {
// public:
// typedef Mutex mutex_type;
// ...
// };
#include <shared_mutex>
#include <type_traits>
int main()
{
#if _LIBCPP_STD_VER > 11
static_assert((std::is_same<std::shared_lock<std::mutex>::mutex_type,
std::mutex>::value), "");
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// template <class Mutex> class unique_lock;
// unique_lock& operator=(unique_lock const&) = delete;
#include <mutex>
#include <cassert>
std::mutex m0;
std::mutex m1;
int main()
{
std::unique_lock<std::mutex> lk0(m0);
std::unique_lock<std::mutex> lk1(m1);
lk1 = lk0;
assert(lk1.mutex() == &m0);
assert(lk1.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// template <class Mutex> class unique_lock;
// unique_lock(unique_lock const&) = delete;
#include <mutex>
#include <cassert>
std::mutex m;
int main()
{
std::unique_lock<std::mutex> lk0(m);
std::unique_lock<std::mutex> lk = lk0;
assert(lk.mutex() == &m);
assert(lk.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
}

View File

@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// unique_lock();
#include <mutex>
#include <cassert>
int main()
{
std::unique_lock<std::mutex> ul;
assert(!ul.owns_lock());
assert(ul.mutex() == nullptr);
}

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// unique_lock& operator=(unique_lock&& u);
#include <mutex>
#include <cassert>
std::mutex m0;
std::mutex m1;
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
std::unique_lock<std::mutex> lk0(m0);
std::unique_lock<std::mutex> lk1(m1);
lk1 = std::move(lk0);
assert(lk1.mutex() == &m0);
assert(lk1.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// unique_lock(unique_lock&& u);
#include <mutex>
#include <cassert>
std::mutex m;
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
std::unique_lock<std::mutex> lk0(m);
std::unique_lock<std::mutex> lk = std::move(lk0);
assert(lk.mutex() == &m);
assert(lk.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// explicit unique_lock(mutex_type& m);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
time_point t1;
{
std::unique_lock<std::mutex> ul(m);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// unique_lock(mutex_type& m, adopt_lock_t);
#include <mutex>
#include <cassert>
int main()
{
std::mutex m;
m.lock();
std::unique_lock<std::mutex> lk(m, std::adopt_lock);
assert(lk.mutex() == &m);
assert(lk.owns_lock() == true);
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// unique_lock(mutex_type& m, defer_lock_t);
#include <mutex>
#include <cassert>
int main()
{
std::mutex m;
std::unique_lock<std::mutex> lk(m, std::defer_lock);
assert(lk.mutex() == &m);
assert(lk.owns_lock() == false);
}

View File

@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class timed_mutex;
// template <class Rep, class Period>
// unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
std::unique_lock<std::timed_mutex> lk(m, ms(300));
assert(lk.owns_lock() == true);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
std::unique_lock<std::timed_mutex> lk(m, ms(250));
assert(lk.owns_lock() == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
int main()
{
{
m.lock();
std::thread t(f1);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}
{
m.lock();
std::thread t(f2);
std::this_thread::sleep_for(ms(300));
m.unlock();
t.join();
}
}

View File

@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class timed_mutex;
// template <class Clock, class Duration>
// unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
std::unique_lock<std::timed_mutex> lk(m, Clock::now() + ms(300));
assert(lk.owns_lock() == true);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ns(50000000)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
std::unique_lock<std::timed_mutex> lk(m, Clock::now() + ms(250));
assert(lk.owns_lock() == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
int main()
{
{
m.lock();
std::thread t(f1);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}
{
m.lock();
std::thread t(f2);
std::this_thread::sleep_for(ms(300));
m.unlock();
t.join();
}
}

View File

@@ -0,0 +1,64 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// unique_lock(mutex_type& m, try_to_lock_t);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
{
std::unique_lock<std::mutex> lk(m, std::try_to_lock);
assert(lk.owns_lock() == false);
}
{
std::unique_lock<std::mutex> lk(m, std::try_to_lock);
assert(lk.owns_lock() == false);
}
{
std::unique_lock<std::mutex> lk(m, std::try_to_lock);
assert(lk.owns_lock() == false);
}
while (true)
{
std::unique_lock<std::mutex> lk(m, std::try_to_lock);
if (lk.owns_lock())
break;
}
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(200)); // within 200ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// void lock();
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
std::unique_lock<std::mutex> lk(m, std::defer_lock);
time_point t0 = Clock::now();
lk.lock();
time_point t1 = Clock::now();
assert(lk.owns_lock() == true);
ns d = t1 - t0 - ms(250);
assert(d < ms(25)); // within 25ms
try
{
lk.lock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EDEADLK);
}
lk.unlock();
lk.release();
try
{
lk.lock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,64 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// bool try_lock();
#include <mutex>
#include <cassert>
bool try_lock_called = false;
struct mutex
{
bool try_lock()
{
try_lock_called = !try_lock_called;
return try_lock_called;
}
void unlock() {}
};
mutex m;
int main()
{
std::unique_lock<mutex> lk(m, std::defer_lock);
assert(lk.try_lock() == true);
assert(try_lock_called == true);
assert(lk.owns_lock() == true);
try
{
lk.try_lock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EDEADLK);
}
lk.unlock();
assert(lk.try_lock() == false);
assert(try_lock_called == false);
assert(lk.owns_lock() == false);
lk.release();
try
{
lk.try_lock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// template <class Rep, class Period>
// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
#include <mutex>
#include <cassert>
bool try_lock_for_called = false;
typedef std::chrono::milliseconds ms;
struct mutex
{
template <class Rep, class Period>
bool try_lock_for(const std::chrono::duration<Rep, Period>& rel_time)
{
assert(rel_time == ms(5));
try_lock_for_called = !try_lock_for_called;
return try_lock_for_called;
}
void unlock() {}
};
mutex m;
int main()
{
std::unique_lock<mutex> lk(m, std::defer_lock);
assert(lk.try_lock_for(ms(5)) == true);
assert(try_lock_for_called == true);
assert(lk.owns_lock() == true);
try
{
lk.try_lock_for(ms(5));
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EDEADLK);
}
lk.unlock();
assert(lk.try_lock_for(ms(5)) == false);
assert(try_lock_for_called == false);
assert(lk.owns_lock() == false);
lk.release();
try
{
lk.try_lock_for(ms(5));
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// template <class Clock, class Duration>
// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
#include <mutex>
#include <cassert>
bool try_lock_until_called = false;
struct mutex
{
template <class Clock, class Duration>
bool try_lock_until(const std::chrono::time_point<Clock, Duration>& abs_time)
{
typedef std::chrono::milliseconds ms;
assert(Clock::now() - abs_time < ms(5));
try_lock_until_called = !try_lock_until_called;
return try_lock_until_called;
}
void unlock() {}
};
mutex m;
int main()
{
typedef std::chrono::steady_clock Clock;
std::unique_lock<mutex> lk(m, std::defer_lock);
assert(lk.try_lock_until(Clock::now()) == true);
assert(try_lock_until_called == true);
assert(lk.owns_lock() == true);
try
{
lk.try_lock_until(Clock::now());
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EDEADLK);
}
lk.unlock();
assert(lk.try_lock_until(Clock::now()) == false);
assert(try_lock_until_called == false);
assert(lk.owns_lock() == false);
lk.release();
try
{
lk.try_lock_until(Clock::now());
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
}

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// void unlock();
#include <mutex>
#include <cassert>
bool unlock_called = false;
struct mutex
{
void lock() {}
void unlock() {unlock_called = true;}
};
mutex m;
int main()
{
std::unique_lock<mutex> lk(m);
lk.unlock();
assert(unlock_called == true);
assert(lk.owns_lock() == false);
try
{
lk.unlock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
lk.release();
try
{
lk.unlock();
assert(false);
}
catch (std::system_error& e)
{
assert(e.code().value() == EPERM);
}
}

View File

@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// void swap(unique_lock& u);
#include <mutex>
#include <cassert>
struct mutex
{
void lock() {}
void unlock() {}
};
mutex m;
int main()
{
std::unique_lock<mutex> lk1(m);
std::unique_lock<mutex> lk2;
lk1.swap(lk2);
assert(lk1.mutex() == nullptr);
assert(lk1.owns_lock() == false);
assert(lk2.mutex() == &m);
assert(lk2.owns_lock() == true);
}

View File

@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// template <class Mutex>
// void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y);
#include <mutex>
#include <cassert>
struct mutex
{
void lock() {}
void unlock() {}
};
mutex m;
int main()
{
std::unique_lock<mutex> lk1(m);
std::unique_lock<mutex> lk2;
swap(lk1, lk2);
assert(lk1.mutex() == nullptr);
assert(lk1.owns_lock() == false);
assert(lk2.mutex() == &m);
assert(lk2.owns_lock() == true);
}

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// mutex_type* release() noexcept;
#include <mutex>
#include <cassert>
struct mutex
{
static int lock_count;
static int unlock_count;
void lock() {++lock_count;}
void unlock() {++unlock_count;}
};
int mutex::lock_count = 0;
int mutex::unlock_count = 0;
mutex m;
int main()
{
std::unique_lock<mutex> lk(m);
assert(lk.mutex() == &m);
assert(lk.owns_lock() == true);
assert(mutex::lock_count == 1);
assert(mutex::unlock_count == 0);
assert(lk.release() == &m);
assert(lk.mutex() == nullptr);
assert(lk.owns_lock() == false);
assert(mutex::lock_count == 1);
assert(mutex::unlock_count == 0);
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// mutex_type *mutex() const;
#include <mutex>
#include <cassert>
std::mutex m;
int main()
{
std::unique_lock<std::mutex> lk0;
assert(lk0.mutex() == nullptr);
std::unique_lock<std::mutex> lk1(m);
assert(lk1.mutex() == &m);
lk1.unlock();
assert(lk1.mutex() == &m);
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// explicit operator bool() const;
#include <mutex>
#include <cassert>
std::mutex m;
int main()
{
std::unique_lock<std::mutex> lk0;
assert(static_cast<bool>(lk0) == false);
std::unique_lock<std::mutex> lk1(m);
assert(static_cast<bool>(lk1) == true);
lk1.unlock();
assert(static_cast<bool>(lk1) == false);
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex> class unique_lock;
// bool owns_lock() const;
#include <mutex>
#include <cassert>
std::mutex m;
int main()
{
std::unique_lock<std::mutex> lk0;
assert(lk0.owns_lock() == false);
std::unique_lock<std::mutex> lk1(m);
assert(lk1.owns_lock() == true);
lk1.unlock();
assert(lk1.owns_lock() == false);
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// template <class Mutex>
// class unique_lock
// {
// public:
// typedef Mutex mutex_type;
// ...
// };
#include <mutex>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::unique_lock<std::mutex>::mutex_type,
std::mutex>::value), "");
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// struct defer_lock_t {};
// struct try_to_lock_t {};
// struct adopt_lock_t {};
//
// constexpr defer_lock_t defer_lock{};
// constexpr try_to_lock_t try_to_lock{};
// constexpr adopt_lock_t adopt_lock{};
#include <mutex>
#include <type_traits>
int main()
{
typedef std::defer_lock_t T1;
typedef std::try_to_lock_t T2;
typedef std::adopt_lock_t T3;
T1 t1 = std::defer_lock;
T2 t2 = std::try_to_lock;
T3 t3 = std::adopt_lock;
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// class mutex;
// mutex& operator=(const mutex&) = delete;
#include <mutex>
int main()
{
std::mutex m0;
std::mutex m1;
m1 = m0;
}

View File

@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// class mutex;
// mutex(const mutex&) = delete;
#include <mutex>
int main()
{
std::mutex m0;
std::mutex m1(m0);
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class mutex;
// mutex();
#include <mutex>
int main()
{
std::mutex m;
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class mutex;
// void lock();
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
#include <iostream>
std::mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
m.lock();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class mutex;
// typedef pthread_mutex_t* native_handle_type;
// native_handle_type native_handle();
#include <mutex>
#include <cassert>
int main()
{
std::mutex m;
pthread_mutex_t* h = m.native_handle();
assert(h);
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class mutex;
// bool try_lock();
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
assert(!m.try_lock());
assert(!m.try_lock());
assert(!m.try_lock());
while(!m.try_lock())
;
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(200)); // within 200ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// class recursive_mutex;
// recursive_mutex& operator=(const recursive_mutex&) = delete;
#include <mutex>
int main()
{
std::recursive_mutex m0;
std::recursive_mutex m1;
m1 = m0;
}

View File

@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// class recursive_mutex;
// recursive_mutex(const recursive_mutex&) = delete;
#include <mutex>
int main()
{
std::recursive_mutex m0;
std::recursive_mutex m1(m0);
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class recursive_mutex;
// recursive_mutex();
#include <mutex>
int main()
{
std::recursive_mutex m;
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class recursive_mutex;
// void lock();
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
#include <iostream>
std::recursive_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
m.lock();
time_point t1 = Clock::now();
m.lock();
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(200)); // within 200ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class recursive_mutex;
// typedef pthread_mutex_t* native_handle_type;
// native_handle_type native_handle();
#include <mutex>
#include <cassert>
int main()
{
std::recursive_mutex m;
pthread_mutex_t* h = m.native_handle();
assert(h);
}

View File

@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class recursive_mutex;
// bool try_lock();
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::recursive_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
assert(!m.try_lock());
assert(!m.try_lock());
assert(!m.try_lock());
while(!m.try_lock())
;
time_point t1 = Clock::now();
assert(m.try_lock());
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(200)); // within 200ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <shared_mutex>
// class shared_timed_mutex;
// shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
#include <shared_mutex>
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m0;
std::shared_timed_mutex m1;
m1 = m0;
#else
# error
#endif
}

View File

@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <shared_mutex>
// class shared_timed_mutex;
// shared_timed_mutex(const shared_timed_mutex&) = delete;
#include <shared_mutex>
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m0;
std::shared_timed_mutex m1(m0);
#else
# error
#endif
}

View File

@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// class shared_timed_mutex;
// shared_timed_mutex();
#include <shared_mutex>
int main()
{
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
#endif
}

View File

@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// class shared_timed_mutex;
// void lock();
#include <shared_mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
m.lock();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,77 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// class shared_timed_mutex;
// void lock_shared();
#include <shared_mutex>
#include <thread>
#include <vector>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
m.lock_shared();
time_point t1 = Clock::now();
m.unlock_shared();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
void g()
{
time_point t0 = Clock::now();
m.lock_shared();
time_point t1 = Clock::now();
m.unlock_shared();
ns d = t1 - t0;
assert(d < ms(50)); // within 50ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f));
std::this_thread::sleep_for(ms(250));
m.unlock();
for (auto& t : v)
t.join();
m.lock_shared();
for (auto& t : v)
t = std::thread(g);
std::thread q(f);
std::this_thread::sleep_for(ms(250));
m.unlock_shared();
for (auto& t : v)
t.join();
q.join();
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// class shared_timed_mutex;
// bool try_lock();
#include <shared_mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
assert(!m.try_lock());
assert(!m.try_lock());
assert(!m.try_lock());
while(!m.try_lock())
;
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(200)); // within 200ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// class shared_timed_mutex;
// template <class Rep, class Period>
// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
#include <shared_mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
assert(m.try_lock_for(ms(300)) == true);
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
assert(m.try_lock_for(ms(250)) == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
{
m.lock();
std::thread t(f1);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}
{
m.lock();
std::thread t(f2);
std::this_thread::sleep_for(ms(300));
m.unlock();
t.join();
}
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,62 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// class shared_timed_mutex;
// bool try_lock_shared();
#include <shared_mutex>
#include <thread>
#include <vector>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
assert(!m.try_lock_shared());
assert(!m.try_lock_shared());
assert(!m.try_lock_shared());
while(!m.try_lock_shared())
;
time_point t1 = Clock::now();
m.unlock_shared();
ns d = t1 - t0 - ms(250);
assert(d < ms(200)); // within 200ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f));
std::this_thread::sleep_for(ms(250));
m.unlock();
for (auto& t : v)
t.join();
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// class shared_timed_mutex;
// template <class Rep, class Period>
// bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
#include <shared_mutex>
#include <thread>
#include <vector>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
assert(m.try_lock_shared_for(ms(300)) == true);
time_point t1 = Clock::now();
m.unlock_shared();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
assert(m.try_lock_shared_for(ms(250)) == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
{
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f1));
std::this_thread::sleep_for(ms(250));
m.unlock();
for (auto& t : v)
t.join();
}
{
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f2));
std::this_thread::sleep_for(ms(300));
m.unlock();
for (auto& t : v)
t.join();
}
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// class shared_timed_mutex;
// template <class Clock, class Duration>
// bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
#include <shared_mutex>
#include <thread>
#include <vector>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
assert(m.try_lock_shared_until(Clock::now() + ms(300)) == true);
time_point t1 = Clock::now();
m.unlock_shared();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
assert(m.try_lock_shared_until(Clock::now() + ms(250)) == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
{
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f1));
std::this_thread::sleep_for(ms(250));
m.unlock();
for (auto& t : v)
t.join();
}
{
m.lock();
std::vector<std::thread> v;
for (int i = 0; i < 5; ++i)
v.push_back(std::thread(f2));
std::this_thread::sleep_for(ms(300));
m.unlock();
for (auto& t : v)
t.join();
}
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <shared_mutex>
// class shared_timed_mutex;
// template <class Clock, class Duration>
// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
#include <shared_mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
assert(m.try_lock_until(Clock::now() + ms(300)) == true);
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
assert(m.try_lock_until(Clock::now() + ms(250)) == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
#endif // _LIBCPP_STD_VER > 11
int main()
{
#if _LIBCPP_STD_VER > 11
{
m.lock();
std::thread t(f1);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}
{
m.lock();
std::thread t(f2);
std::this_thread::sleep_for(ms(300));
m.unlock();
t.join();
}
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// class timed_mutex;
// timed_mutex& operator=(const timed_mutex&) = delete;
#include <mutex>
int main()
{
std::timed_mutex m0;
std::timed_mutex m1;
m1 = m0;
}

View File

@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// class timed_mutex;
// timed_mutex(const timed_mutex&) = delete;
#include <mutex>
int main()
{
std::timed_mutex m0;
std::timed_mutex m1(m0);
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class timed_mutex;
// timed_mutex();
#include <mutex>
int main()
{
std::timed_mutex m;
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class timed_mutex;
// void lock();
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
#include <iostream>
std::timed_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
m.lock();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class timed_mutex;
// bool try_lock();
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::timed_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
assert(!m.try_lock());
assert(!m.try_lock());
assert(!m.try_lock());
while(!m.try_lock())
;
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(200)); // within 200ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class timed_mutex;
// template <class Rep, class Period>
// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
assert(m.try_lock_for(ms(300)) == true);
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
assert(m.try_lock_for(ms(250)) == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
int main()
{
{
m.lock();
std::thread t(f1);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}
{
m.lock();
std::thread t(f2);
std::this_thread::sleep_for(ms(300));
m.unlock();
t.join();
}
}

View File

@@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class timed_mutex;
// template <class Clock, class Duration>
// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
assert(m.try_lock_until(Clock::now() + ms(300)) == true);
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
assert(m.try_lock_until(Clock::now() + ms(250)) == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
int main()
{
{
m.lock();
std::thread t(f1);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}
{
m.lock();
std::thread t(f2);
std::this_thread::sleep_for(ms(300));
m.unlock();
t.join();
}
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// class recursive_timed_mutex;
// recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
#include <mutex>
int main()
{
std::recursive_timed_mutex m0;
std::recursive_timed_mutex m1;
m1 = m0;
}

View File

@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// class recursive_timed_mutex;
// recursive_timed_mutex(const recursive_timed_mutex&) = delete;
#include <mutex>
int main()
{
std::recursive_timed_mutex m0;
std::recursive_timed_mutex m1(m0);
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class recursive_timed_mutex;
// recursive_timed_mutex();
#include <mutex>
int main()
{
std::recursive_timed_mutex m;
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class recursive_timed_mutex;
// void lock();
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
#include <iostream>
std::recursive_timed_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
m.lock();
time_point t1 = Clock::now();
m.lock();
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class recursive_timed_mutex;
// bool try_lock();
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::recursive_timed_mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
{
time_point t0 = Clock::now();
assert(!m.try_lock());
assert(!m.try_lock());
assert(!m.try_lock());
while(!m.try_lock())
;
time_point t1 = Clock::now();
assert(m.try_lock());
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(200)); // within 200ms
}
int main()
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class recursive_timed_mutex;
// template <class Rep, class Period>
// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::recursive_timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
assert(m.try_lock_for(ms(300)) == true);
time_point t1 = Clock::now();
assert(m.try_lock());
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ns(50000000)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
assert(m.try_lock_for(ms(250)) == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ns(50000000)); // within 50ms
}
int main()
{
{
m.lock();
std::thread t(f1);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}
{
m.lock();
std::thread t(f2);
std::this_thread::sleep_for(ms(300));
m.unlock();
t.join();
}
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// class recursive_timed_mutex;
// template <class Clock, class Duration>
// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
std::recursive_timed_mutex m;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f1()
{
time_point t0 = Clock::now();
assert(m.try_lock_until(Clock::now() + ms(300)) == true);
time_point t1 = Clock::now();
assert(m.try_lock());
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
void f2()
{
time_point t0 = Clock::now();
assert(m.try_lock_until(Clock::now() + ms(250)) == false);
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
int main()
{
{
m.lock();
std::thread t(f1);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
}
{
m.lock();
std::thread t(f2);
std::this_thread::sleep_for(ms(300));
m.unlock();
t.join();
}
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,208 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
// struct once_flag;
// template<class Callable, class ...Args>
// void call_once(once_flag& flag, Callable func, Args&&... args);
#include <mutex>
#include <thread>
#include <cassert>
typedef std::chrono::milliseconds ms;
std::once_flag flg0;
int init0_called = 0;
void init0()
{
std::this_thread::sleep_for(ms(250));
++init0_called;
}
void f0()
{
std::call_once(flg0, init0);
}
std::once_flag flg3;
int init3_called = 0;
int init3_completed = 0;
void init3()
{
++init3_called;
std::this_thread::sleep_for(ms(250));
if (init3_called == 1)
throw 1;
++init3_completed;
}
void f3()
{
try
{
std::call_once(flg3, init3);
}
catch (...)
{
}
}
#ifndef _LIBCPP_HAS_NO_VARIADICS
struct init1
{
static int called;
void operator()(int i) {called += i;}
};
int init1::called = 0;
std::once_flag flg1;
void f1()
{
std::call_once(flg1, init1(), 1);
}
struct init2
{
static int called;
void operator()(int i, int j) const {called += i + j;}
};
int init2::called = 0;
std::once_flag flg2;
void f2()
{
std::call_once(flg2, init2(), 2, 3);
std::call_once(flg2, init2(), 4, 5);
}
#endif // _LIBCPP_HAS_NO_VARIADICS
std::once_flag flg41;
std::once_flag flg42;
int init41_called = 0;
int init42_called = 0;
void init42();
void init41()
{
std::this_thread::sleep_for(ms(250));
++init41_called;
}
void init42()
{
std::this_thread::sleep_for(ms(250));
++init42_called;
}
void f41()
{
std::call_once(flg41, init41);
std::call_once(flg42, init42);
}
void f42()
{
std::call_once(flg42, init42);
std::call_once(flg41, init41);
}
#ifndef _LIBCPP_HAS_NO_VARIADICS
class MoveOnly
{
#if !defined(__clang__)
// GCC 4.8 complains about the following being private
public:
MoveOnly(const MoveOnly&)
{
}
#else
MoveOnly(const MoveOnly&);
#endif
public:
MoveOnly() {}
MoveOnly(MoveOnly&&) {}
void operator()(MoveOnly&&)
{
}
};
#endif
int main()
{
// check basic functionality
{
std::thread t0(f0);
std::thread t1(f0);
t0.join();
t1.join();
assert(init0_called == 1);
}
// check basic exception safety
{
std::thread t0(f3);
std::thread t1(f3);
t0.join();
t1.join();
assert(init3_called == 2);
assert(init3_completed == 1);
}
// check deadlock avoidance
{
std::thread t0(f41);
std::thread t1(f42);
t0.join();
t1.join();
assert(init41_called == 1);
assert(init42_called == 1);
}
#ifndef _LIBCPP_HAS_NO_VARIADICS
// check functors with 1 arg
{
std::thread t0(f1);
std::thread t1(f1);
t0.join();
t1.join();
assert(init1::called == 1);
}
// check functors with 2 args
{
std::thread t0(f2);
std::thread t1(f2);
t0.join();
t1.join();
assert(init2::called == 5);
}
{
std::once_flag f;
std::call_once(f, MoveOnly(), MoveOnly());
}
#endif // _LIBCPP_HAS_NO_VARIADICS
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <mutex>
// struct once_flag;
// once_flag& operator=(const once_flag&) = delete;
#include <mutex>
int main()
{
std::once_flag f;
std::once_flag f2;
f2 = f;
}

Some files were not shown because too many files have changed in this diff Show More