Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65547 - in sandbox/sync/libs/sync/test: condition condition/condvar condition/condvarany lock lock/condition lock/guard lock/reverse lock/strict lock/unique/cons lock/unique/locking lock/unique/mod lock/unique/obs lockable/lockable_req/thread_mutex lockable/lockable_req/thread_recursive_mutex lockable/poly lockable/timed_lockable_req/thread_timed_mutex lockable/timed_lockable_req/thread_timed_recursive_mutex lockables/algorithm lockables/array_lock
From: vicente.botet_at_[hidden]
Date: 2010-09-23 11:09:54


Author: viboes
Date: 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
New Revision: 65547
URL: http://svn.boost.org/trac/boost/changeset/65547

Log:
Sync Added more directories for tests and test from libc++ (to be adapted)
Added:
   sandbox/sync/libs/sync/test/condition/
   sandbox/sync/libs/sync/test/condition/condvar/
   sandbox/sync/libs/sync/test/condition/condvar/assign.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/copy.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/default.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/destructor.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/native_handle.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/notify_all.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/notify_one.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/wait.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/wait_for.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/wait_for_pred.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/wait_pred.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/wait_until.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvar/wait_until_pred.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/
   sandbox/sync/libs/sync/test/condition/condvarany/assign.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/copy.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/default.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/destructor.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/notify_all.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/notify_one.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/wait.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/wait_for.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/wait_for_pred.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/wait_pred.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/wait_until.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/condvarany/wait_until_pred.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/cv_status.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/condition/notify_all_at_thread_exit.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/condition/
   sandbox/sync/libs/sync/test/lock/guard/adopt_lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/guard/assign.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/guard/copy.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/guard/mutex.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/guard/mutex.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/guard/types.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/reverse/
   sandbox/sync/libs/sync/test/lock/reverse/nested_reverse_locker_test.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/reverse/reverse_lock_test.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/strict/
   sandbox/sync/libs/sync/test/lock/types.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/cons/copy_assign.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/cons/copy_ctor.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/cons/default.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/cons/move_assign.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/cons/move_ctor.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/cons/mutex.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/cons/mutex_adopt_lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/cons/mutex_defer_lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/cons/mutex_duration.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/cons/mutex_time_point.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/cons/mutex_try_to_lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/locking/lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/locking/try_lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/locking/try_lock_for.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/locking/try_lock_until.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/locking/unlock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/mod/member_swap.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/mod/nonmember_swap.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/mod/release.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/obs/mutex.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/obs/op_bool.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lock/unique/obs/owns_lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/assign.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/copy.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/default.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/native_handle.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/try_lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/assign.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/copy.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/default.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/native_handle.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/try_lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/poly/
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/assign.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/copy.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/default.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/try_lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/try_lock_for.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/try_lock_until.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/assign.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/copy.fail.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/default.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/try_lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/try_lock_for.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/try_lock_until.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockables/algorithm/lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockables/algorithm/try_lock.pass.cpp (contents, props changed)
   sandbox/sync/libs/sync/test/lockables/array_lock/

Added: sandbox/sync/libs/sync/test/condition/condvar/assign.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/assign.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// condition_variable& operator=(const condition_variable&) = delete;
+
+#include <condition_variable>
+#include <cassert>
+
+int main()
+{
+ std::condition_variable cv0;
+ std::condition_variable cv1;
+ cv1 = cv0;
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/copy.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/copy.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// condition_variable(const condition_variable&) = delete;
+
+#include <condition_variable>
+#include <cassert>
+
+int main()
+{
+ std::condition_variable cv0;
+ std::condition_variable cv1(cv0);
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/default.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/default.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// condition_variable();
+
+#include <condition_variable>
+#include <cassert>
+
+int main()
+{
+ std::condition_variable cv;
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/destructor.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/destructor.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// ~condition_variable();
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <cassert>
+
+std::condition_variable* cv;
+std::mutex m;
+typedef std::unique_lock<std::mutex> Lock;
+
+bool f_ready = false;
+bool g_ready = false;
+
+void f()
+{
+ Lock lk(m);
+ f_ready = true;
+ cv->notify_one();
+ delete cv;
+}
+
+void g()
+{
+ Lock lk(m);
+ g_ready = true;
+ cv->notify_one();
+ while (!f_ready)
+ cv->wait(lk);
+}
+
+int main()
+{
+ cv = new std::condition_variable;
+ std::thread th2(g);
+ Lock lk(m);
+ while (!g_ready)
+ cv->wait(lk);
+ lk.unlock();
+ std::thread th1(f);
+ th1.join();
+ th2.join();
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/native_handle.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/native_handle.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// typedef pthread_cond_t* native_handle_type;
+// native_handle_type native_handle();
+
+#include <condition_variable>
+#include <cassert>
+
+int main()
+{
+ static_assert((std::is_same<std::condition_variable::native_handle_type,
+ pthread_cond_t*>::value), "");
+ std::condition_variable cv;
+ std::condition_variable::native_handle_type h = cv.native_handle();
+ assert(h != nullptr);
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/notify_all.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/notify_all.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// void notify_all();
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <cassert>
+
+std::condition_variable cv;
+std::mutex mut;
+
+int test0 = 0;
+int test1 = 0;
+int test2 = 0;
+
+void f1()
+{
+ std::unique_lock<std::mutex> lk(mut);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 == 1);
+ test1 = 2;
+}
+
+void f2()
+{
+ std::unique_lock<std::mutex> lk(mut);
+ assert(test2 == 0);
+ while (test2 == 0)
+ cv.wait(lk);
+ assert(test2 == 1);
+ test2 = 2;
+}
+
+int main()
+{
+ std::thread t1(f1);
+ std::thread t2(f2);
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ {
+ std::unique_lock<std::mutex>lk(mut);
+ test1 = 1;
+ test2 = 1;
+ }
+ cv.notify_all();
+ {
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ std::unique_lock<std::mutex>lk(mut);
+ }
+ t1.join();
+ t2.join();
+ assert(test1 == 2);
+ assert(test2 == 2);
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/notify_one.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/notify_one.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,92 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// void notify_one();
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <cassert>
+
+std::condition_variable cv;
+std::mutex mut;
+
+int test0 = 0;
+int test1 = 0;
+int test2 = 0;
+
+void f1()
+{
+ std::unique_lock<std::mutex> lk(mut);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 == 1);
+ test1 = 2;
+}
+
+void f2()
+{
+ std::unique_lock<std::mutex> lk(mut);
+ assert(test2 == 0);
+ while (test2 == 0)
+ cv.wait(lk);
+ assert(test2 == 1);
+ test2 = 2;
+}
+
+int main()
+{
+ std::thread t1(f1);
+ std::thread t2(f2);
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ {
+ std::unique_lock<std::mutex>lk(mut);
+ test1 = 1;
+ test2 = 1;
+ }
+ cv.notify_one();
+ {
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ std::unique_lock<std::mutex>lk(mut);
+ }
+ if (test1 == 2)
+ {
+ t1.join();
+ test1 = 0;
+ }
+ else if (test2 == 2)
+ {
+ t2.join();
+ test2 = 0;
+ }
+ else
+ assert(false);
+ cv.notify_one();
+ {
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ std::unique_lock<std::mutex>lk(mut);
+ }
+ if (test1 == 2)
+ {
+ t1.join();
+ test1 = 0;
+ }
+ else if (test2 == 2)
+ {
+ t2.join();
+ test2 = 0;
+ }
+ else
+ assert(false);
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/wait.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/wait.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// void wait(unique_lock<mutex>& lock);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <cassert>
+
+std::condition_variable cv;
+std::mutex mut;
+
+int test1 = 0;
+int test2 = 0;
+
+void f()
+{
+ std::unique_lock<std::mutex> lk(mut);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ while (test2 == 0)
+ cv.wait(lk);
+ assert(test2 != 0);
+}
+
+int main()
+{
+ std::unique_lock<std::mutex>lk(mut);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/wait_for.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/wait_for.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,85 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// template <class Rep, class Period>
+// cv_status
+// wait_for(unique_lock<mutex>& lock,
+// const chrono::duration<Rep, Period>& rel_time);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <chrono>
+#include <cassert>
+
+std::condition_variable cv;
+std::mutex mut;
+
+int test1 = 0;
+int test2 = 0;
+
+int runs = 0;
+
+void f()
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::milliseconds milliseconds;
+ std::unique_lock<std::mutex> lk(mut);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ Clock::time_point t0 = Clock::now();
+ while (test2 == 0 &&
+ cv.wait_for(lk, milliseconds(250)) == std::cv_status::no_timeout)
+ ;
+ Clock::time_point t1 = Clock::now();
+ if (runs == 0)
+ {
+ assert(t1 - t0 < milliseconds(250));
+ assert(test2 != 0);
+ }
+ else
+ {
+ assert(t1 - t0 - milliseconds(250) < milliseconds(5));
+ assert(test2 == 0);
+ }
+ ++runs;
+}
+
+int main()
+{
+ {
+ std::unique_lock<std::mutex>lk(mut);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+ }
+ test1 = 0;
+ test2 = 0;
+ {
+ std::unique_lock<std::mutex>lk(mut);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ lk.unlock();
+ t.join();
+ }
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/wait_for_pred.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/wait_for_pred.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,93 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// template <class Rep, class Period, class Predicate>
+// bool
+// wait_for(unique_lock<mutex>& lock,
+// const chrono::duration<Rep, Period>& rel_time,
+// Predicate pred);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <chrono>
+#include <cassert>
+
+class Pred
+{
+ int& i_;
+public:
+ explicit Pred(int& i) : i_(i) {}
+
+ bool operator()() {return i_ != 0;}
+};
+
+std::condition_variable cv;
+std::mutex mut;
+
+int test1 = 0;
+int test2 = 0;
+
+int runs = 0;
+
+void f()
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::milliseconds milliseconds;
+ std::unique_lock<std::mutex> lk(mut);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ Clock::time_point t0 = Clock::now();
+ bool r = cv.wait_for(lk, milliseconds(250), Pred(test2));
+ Clock::time_point t1 = Clock::now();
+ if (runs == 0)
+ {
+ assert(t1 - t0 < milliseconds(250));
+ assert(test2 != 0);
+ }
+ else
+ {
+ assert(t1 - t0 - milliseconds(250) < milliseconds(2));
+ assert(test2 == 0);
+ }
+ ++runs;
+}
+
+int main()
+{
+ {
+ std::unique_lock<std::mutex>lk(mut);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+ }
+ test1 = 0;
+ test2 = 0;
+ {
+ std::unique_lock<std::mutex>lk(mut);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ lk.unlock();
+ t.join();
+ }
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/wait_pred.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/wait_pred.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// template <class Predicate>
+// void wait(unique_lock<mutex>& lock, Predicate pred);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <functional>
+#include <cassert>
+
+std::condition_variable cv;
+std::mutex mut;
+
+int test1 = 0;
+int test2 = 0;
+
+class Pred
+{
+ int& i_;
+public:
+ explicit Pred(int& i) : i_(i) {}
+
+ bool operator()() {return i_ != 0;}
+};
+
+void f()
+{
+ std::unique_lock<std::mutex> lk(mut);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ cv.wait(lk, Pred(test2));
+ assert(test2 != 0);
+}
+
+int main()
+{
+ std::unique_lock<std::mutex>lk(mut);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/wait_until.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/wait_until.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,100 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// template <class Clock, class Duration>
+// cv_status
+// wait_until(unique_lock<mutex>& lock,
+// const chrono::time_point<Clock, Duration>& abs_time);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <chrono>
+#include <cassert>
+
+struct Clock
+{
+ typedef std::chrono::milliseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef std::chrono::time_point<Clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now()
+ {
+ using namespace std::chrono;
+ return time_point(duration_cast<duration>(
+ monotonic_clock::now().time_since_epoch()
+ ));
+ }
+};
+
+std::condition_variable cv;
+std::mutex mut;
+
+int test1 = 0;
+int test2 = 0;
+
+int runs = 0;
+
+void f()
+{
+ std::unique_lock<std::mutex> lk(mut);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ Clock::time_point t0 = Clock::now();
+ Clock::time_point t = t0 + Clock::duration(250);
+ while (test2 == 0 && cv.wait_until(lk, t) == std::cv_status::no_timeout)
+ ;
+ Clock::time_point t1 = Clock::now();
+ if (runs == 0)
+ {
+ assert(t1 - t0 < Clock::duration(250));
+ assert(test2 != 0);
+ }
+ else
+ {
+ assert(t1 - t0 - Clock::duration(250) < Clock::duration(5));
+ assert(test2 == 0);
+ }
+ ++runs;
+}
+
+int main()
+{
+ {
+ std::unique_lock<std::mutex>lk(mut);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+ }
+ test1 = 0;
+ test2 = 0;
+ {
+ std::unique_lock<std::mutex>lk(mut);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ lk.unlock();
+ t.join();
+ }
+}

Added: sandbox/sync/libs/sync/test/condition/condvar/wait_until_pred.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvar/wait_until_pred.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,111 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable;
+
+// template <class Clock, class Duration, class Predicate>
+// bool
+// wait_until(unique_lock<mutex>& lock,
+// const chrono::time_point<Clock, Duration>& abs_time,
+// Predicate pred);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <chrono>
+#include <cassert>
+
+struct Clock
+{
+ typedef std::chrono::milliseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef std::chrono::time_point<Clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now()
+ {
+ using namespace std::chrono;
+ return time_point(duration_cast<duration>(
+ monotonic_clock::now().time_since_epoch()
+ ));
+ }
+};
+
+class Pred
+{
+ int& i_;
+public:
+ explicit Pred(int& i) : i_(i) {}
+
+ bool operator()() {return i_ != 0;}
+};
+
+std::condition_variable cv;
+std::mutex mut;
+
+int test1 = 0;
+int test2 = 0;
+
+int runs = 0;
+
+void f()
+{
+ std::unique_lock<std::mutex> lk(mut);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ Clock::time_point t0 = Clock::now();
+ Clock::time_point t = t0 + Clock::duration(250);
+ bool r = cv.wait_until(lk, t, Pred(test2));
+ Clock::time_point t1 = Clock::now();
+ if (runs == 0)
+ {
+ assert(t1 - t0 < Clock::duration(250));
+ assert(test2 != 0);
+ assert(r);
+ }
+ else
+ {
+ assert(t1 - t0 - Clock::duration(250) < Clock::duration(2));
+ assert(test2 == 0);
+ assert(!r);
+ }
+ ++runs;
+}
+
+int main()
+{
+ {
+ std::unique_lock<std::mutex>lk(mut);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+ }
+ test1 = 0;
+ test2 = 0;
+ {
+ std::unique_lock<std::mutex>lk(mut);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ lk.unlock();
+ t.join();
+ }
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/assign.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/assign.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// condition_variable_any& operator=(const condition_variable_any&) = delete;
+
+#include <condition_variable>
+#include <cassert>
+
+int main()
+{
+ std::condition_variable_any cv0;
+ std::condition_variable_any cv1;
+ cv1 = cv0;
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/copy.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/copy.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// condition_variable_any(const condition_variable_any&) = delete;
+
+#include <condition_variable>
+#include <cassert>
+
+int main()
+{
+ std::condition_variable_any cv0;
+ std::condition_variable_any cv1(cv0);
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/default.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/default.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// condition_variable_any();
+
+#include <condition_variable>
+#include <cassert>
+
+int main()
+{
+ std::condition_variable_any cv;
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/destructor.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/destructor.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// ~condition_variable_any();
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <cassert>
+
+std::condition_variable_any* cv;
+std::mutex m;
+
+bool f_ready = false;
+bool g_ready = false;
+
+void f()
+{
+ m.lock();
+ f_ready = true;
+ cv->notify_one();
+ delete cv;
+ m.unlock();
+}
+
+void g()
+{
+ m.lock();
+ g_ready = true;
+ cv->notify_one();
+ while (!f_ready)
+ cv->wait(m);
+ m.unlock();
+}
+
+int main()
+{
+ cv = new std::condition_variable_any;
+ std::thread th2(g);
+ m.lock();
+ while (!g_ready)
+ cv->wait(m);
+ m.unlock();
+ std::thread th1(f);
+ th1.join();
+ th2.join();
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/notify_all.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/notify_all.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// void notify_all();
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <cassert>
+
+std::condition_variable_any cv;
+
+typedef std::timed_mutex L0;
+typedef std::unique_lock<L0> L1;
+
+L0 m0;
+
+int test0 = 0;
+int test1 = 0;
+int test2 = 0;
+
+void f1()
+{
+ L1 lk(m0);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 == 1);
+ test1 = 2;
+}
+
+void f2()
+{
+ L1 lk(m0);
+ assert(test2 == 0);
+ while (test2 == 0)
+ cv.wait(lk);
+ assert(test2 == 1);
+ test2 = 2;
+}
+
+int main()
+{
+ std::thread t1(f1);
+ std::thread t2(f2);
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ {
+ L1 lk(m0);
+ test1 = 1;
+ test2 = 1;
+ }
+ cv.notify_all();
+ {
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ L1 lk(m0);
+ }
+ t1.join();
+ t2.join();
+ assert(test1 == 2);
+ assert(test2 == 2);
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/notify_one.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/notify_one.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,96 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// void notify_one();
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <cassert>
+
+std::condition_variable_any cv;
+
+typedef std::timed_mutex L0;
+typedef std::unique_lock<L0> L1;
+
+L0 m0;
+
+int test0 = 0;
+int test1 = 0;
+int test2 = 0;
+
+void f1()
+{
+ L1 lk(m0);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 == 1);
+ test1 = 2;
+}
+
+void f2()
+{
+ L1 lk(m0);
+ assert(test2 == 0);
+ while (test2 == 0)
+ cv.wait(lk);
+ assert(test2 == 1);
+ test2 = 2;
+}
+
+int main()
+{
+ std::thread t1(f1);
+ std::thread t2(f2);
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ {
+ L1 lk(m0);
+ test1 = 1;
+ test2 = 1;
+ }
+ cv.notify_one();
+ {
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ L1 lk(m0);
+ }
+ if (test1 == 2)
+ {
+ t1.join();
+ test1 = 0;
+ }
+ else if (test2 == 2)
+ {
+ t2.join();
+ test2 = 0;
+ }
+ else
+ assert(false);
+ cv.notify_one();
+ {
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ L1 lk(m0);
+ }
+ if (test1 == 2)
+ {
+ t1.join();
+ test1 = 0;
+ }
+ else if (test2 == 2)
+ {
+ t2.join();
+ test2 = 0;
+ }
+ else
+ assert(false);
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/wait.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/wait.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// template <class Lock>
+// void wait(Lock& lock);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <cassert>
+
+std::condition_variable_any cv;
+
+typedef std::timed_mutex L0;
+typedef std::unique_lock<L0> L1;
+
+L0 m0;
+
+int test1 = 0;
+int test2 = 0;
+
+void f()
+{
+ L1 lk(m0);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ while (test2 == 0)
+ cv.wait(lk);
+ assert(test2 != 0);
+}
+
+int main()
+{
+ L1 lk(m0);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/wait_for.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/wait_for.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,88 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// template <class Lock, class Rep, class Period>
+// cv_status
+// wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <chrono>
+#include <cassert>
+
+std::condition_variable_any cv;
+
+typedef std::timed_mutex L0;
+typedef std::unique_lock<L0> L1;
+
+L0 m0;
+
+int test1 = 0;
+int test2 = 0;
+
+int runs = 0;
+
+void f()
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::milliseconds milliseconds;
+ L1 lk(m0);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ Clock::time_point t0 = Clock::now();
+ while (test2 == 0 &&
+ cv.wait_for(lk, milliseconds(250)) == std::cv_status::no_timeout)
+ ;
+ Clock::time_point t1 = Clock::now();
+ if (runs == 0)
+ {
+ assert(t1 - t0 < milliseconds(250));
+ assert(test2 != 0);
+ }
+ else
+ {
+ assert(t1 - t0 - milliseconds(250) < milliseconds(5));
+ assert(test2 == 0);
+ }
+ ++runs;
+}
+
+int main()
+{
+ {
+ L1 lk(m0);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+ }
+ test1 = 0;
+ test2 = 0;
+ {
+ L1 lk(m0);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ lk.unlock();
+ t.join();
+ }
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/wait_for_pred.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/wait_for_pred.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,96 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// template <class Lock, class Rep, class Period, class Predicate>
+// bool
+// wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time,
+// Predicate pred);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <chrono>
+#include <cassert>
+
+class Pred
+{
+ int& i_;
+public:
+ explicit Pred(int& i) : i_(i) {}
+
+ bool operator()() {return i_ != 0;}
+};
+
+std::condition_variable_any cv;
+
+typedef std::timed_mutex L0;
+typedef std::unique_lock<L0> L1;
+
+L0 m0;
+
+int test1 = 0;
+int test2 = 0;
+
+int runs = 0;
+
+void f()
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::milliseconds milliseconds;
+ L1 lk(m0);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ Clock::time_point t0 = Clock::now();
+ bool r = cv.wait_for(lk, milliseconds(250), Pred(test2));
+ Clock::time_point t1 = Clock::now();
+ if (runs == 0)
+ {
+ assert(t1 - t0 < milliseconds(250));
+ assert(test2 != 0);
+ }
+ else
+ {
+ assert(t1 - t0 - milliseconds(250) < milliseconds(5));
+ assert(test2 == 0);
+ }
+ ++runs;
+}
+
+int main()
+{
+ {
+ L1 lk(m0);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+ }
+ test1 = 0;
+ test2 = 0;
+ {
+ L1 lk(m0);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ lk.unlock();
+ t.join();
+ }
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/wait_pred.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/wait_pred.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// template <class Lock, class Predicate>
+// void wait(Lock& lock, Predicate pred);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <functional>
+#include <cassert>
+
+std::condition_variable_any cv;
+
+typedef std::timed_mutex L0;
+typedef std::unique_lock<L0> L1;
+
+L0 m0;
+
+int test1 = 0;
+int test2 = 0;
+
+class Pred
+{
+ int& i_;
+public:
+ explicit Pred(int& i) : i_(i) {}
+
+ bool operator()() {return i_ != 0;}
+};
+
+void f()
+{
+ L1 lk(m0);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ cv.wait(lk, Pred(test2));
+ assert(test2 != 0);
+}
+
+int main()
+{
+ L1 lk(m0);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/wait_until.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/wait_until.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,103 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// template <class Lock, class Clock, class Duration>
+// cv_status
+// wait_until(Lock& lock, const chrono::time_point<Clock, Duration>& abs_time);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <chrono>
+#include <cassert>
+
+struct Clock
+{
+ typedef std::chrono::milliseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef std::chrono::time_point<Clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now()
+ {
+ using namespace std::chrono;
+ return time_point(duration_cast<duration>(
+ monotonic_clock::now().time_since_epoch()
+ ));
+ }
+};
+
+std::condition_variable_any cv;
+
+typedef std::timed_mutex L0;
+typedef std::unique_lock<L0> L1;
+
+L0 m0;
+
+int test1 = 0;
+int test2 = 0;
+
+int runs = 0;
+
+void f()
+{
+ L1 lk(m0);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ Clock::time_point t0 = Clock::now();
+ Clock::time_point t = t0 + Clock::duration(250);
+ while (test2 == 0 && cv.wait_until(lk, t) == std::cv_status::no_timeout)
+ ;
+ Clock::time_point t1 = Clock::now();
+ if (runs == 0)
+ {
+ assert(t1 - t0 < Clock::duration(250));
+ assert(test2 != 0);
+ }
+ else
+ {
+ assert(t1 - t0 - Clock::duration(250) < Clock::duration(5));
+ assert(test2 == 0);
+ }
+ ++runs;
+}
+
+int main()
+{
+ {
+ L1 lk(m0);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+ }
+ test1 = 0;
+ test2 = 0;
+ {
+ L1 lk(m0);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ lk.unlock();
+ t.join();
+ }
+}

Added: sandbox/sync/libs/sync/test/condition/condvarany/wait_until_pred.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/condvarany/wait_until_pred.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,115 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// class condition_variable_any;
+
+// template <class Lock, class Duration, class Predicate>
+// bool
+// wait_until(Lock& lock,
+// const chrono::time_point<Clock, Duration>& abs_time,
+// Predicate pred);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <chrono>
+#include <cassert>
+
+struct Clock
+{
+ typedef std::chrono::milliseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef std::chrono::time_point<Clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now()
+ {
+ using namespace std::chrono;
+ return time_point(duration_cast<duration>(
+ monotonic_clock::now().time_since_epoch()
+ ));
+ }
+};
+
+class Pred
+{
+ int& i_;
+public:
+ explicit Pred(int& i) : i_(i) {}
+
+ bool operator()() {return i_ != 0;}
+};
+
+std::condition_variable_any cv;
+
+typedef std::timed_mutex L0;
+typedef std::unique_lock<L0> L1;
+
+L0 m0;
+
+int test1 = 0;
+int test2 = 0;
+
+int runs = 0;
+
+void f()
+{
+ L1 lk(m0);
+ assert(test2 == 0);
+ test1 = 1;
+ cv.notify_one();
+ Clock::time_point t0 = Clock::now();
+ Clock::time_point t = t0 + Clock::duration(250);
+ bool r = cv.wait_until(lk, t, Pred(test2));
+ Clock::time_point t1 = Clock::now();
+ if (runs == 0)
+ {
+ assert(t1 - t0 < Clock::duration(250));
+ assert(test2 != 0);
+ assert(r);
+ }
+ else
+ {
+ assert(t1 - t0 - Clock::duration(250) < Clock::duration(2));
+ assert(test2 == 0);
+ assert(!r);
+ }
+ ++runs;
+}
+
+int main()
+{
+ {
+ L1 lk(m0);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ test2 = 1;
+ lk.unlock();
+ cv.notify_one();
+ t.join();
+ }
+ test1 = 0;
+ test2 = 0;
+ {
+ L1 lk(m0);
+ std::thread t(f);
+ assert(test1 == 0);
+ while (test1 == 0)
+ cv.wait(lk);
+ assert(test1 != 0);
+ lk.unlock();
+ t.join();
+ }
+}

Added: sandbox/sync/libs/sync/test/condition/cv_status.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/cv_status.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// enum class cv_status { no_timeout, timeout };
+
+#include <condition_variable>
+#include <cassert>
+
+int main()
+{
+ assert(std::cv_status::no_timeout == 0);
+ assert(std::cv_status::timeout == 1);
+}

Added: sandbox/sync/libs/sync/test/condition/notify_all_at_thread_exit.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/condition/notify_all_at_thread_exit.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <condition_variable>
+
+// void
+// notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
+
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+#include <chrono>
+#include <cassert>
+
+std::condition_variable cv;
+std::mutex mut;
+
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::high_resolution_clock Clock;
+
+void func()
+{
+ std::unique_lock<std::mutex> lk(mut);
+ std::notify_all_at_thread_exit(cv, std::move(lk));
+ std::this_thread::sleep_for(ms(300));
+}
+
+int main()
+{
+ std::unique_lock<std::mutex> lk(mut);
+ std::thread(func).detach();
+ Clock::time_point t0 = Clock::now();
+ cv.wait(lk);
+ Clock::time_point t1 = Clock::now();
+ assert(t1-t0 > ms(250));
+}

Added: sandbox/sync/libs/sync/test/lock/guard/adopt_lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/guard/adopt_lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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 < ns(2500000)); // within 2.5ms
+}
+
+int main()
+{
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/lock/guard/assign.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/guard/assign.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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;
+}

Added: sandbox/sync/libs/sync/test/lock/guard/copy.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/guard/copy.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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);
+}

Added: sandbox/sync/libs/sync/test/lock/guard/mutex.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/guard/mutex.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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();
+}

Added: sandbox/sync/libs/sync/test/lock/guard/mutex.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/guard/mutex.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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();
+}

Added: sandbox/sync/libs/sync/test/lock/guard/types.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/guard/types.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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), "");
+}

Added: sandbox/sync/libs/sync/test/lock/reverse/nested_reverse_locker_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/reverse/nested_reverse_locker_test.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,143 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/synchro/lockers/nested_reverse_locker.hpp>
+#include <boost/synchro/thread/mutex.hpp>
+#include <boost/synchro/thread/locks.hpp>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+using namespace boost::unit_test;
+using namespace boost::synchro;
+
+ #define BOOST_SYNCHRONIZED_VAR(VARS_DECLARATION) if (volatile bool stop_ = false) {} else \
+ for (VARS_DECLARATION; !stop_; stop_ = true)
+
+ #define BOOST_SYNCHRONIZED(MUTEX) BOOST_SYNCHRONIZED_VAR(guard __lock(MUTEX))
+
+ #define synchronized(MUTEX) BOOST_SYNCHRONIZED(MUTEX)
+
+ #define atomic BOOST_SYNCHRONIZED(atomic_globla_mutex)
+
+
+static boost::mutex atomic_globla_mutex;
+struct guard {
+ boost::mutex& m_;
+ bool locked_;
+ guard(boost::mutex& m): m_(m) {
+ locked_ = m_.try_lock();
+ std::cout << "guard:" << &m_ << std::endl;
+ };
+ ~guard() {
+ std::cout << "~guard:" << &m_ << std::endl;
+ m_.unlock();
+ };
+ operator bool(/*synchronized _=mtx*/) const
+ {
+ return locked_;
+ }
+};
+
+struct non_copyable_class
+ : boost::noncopyable
+{
+ int value;
+ boost::mutex mtx;
+ typedef const guard &synchronized;
+ typedef guard synchronizer;
+
+ non_copyable_class():
+ value(0)
+ {}
+
+ void inc()
+ {
+ synchronized (mtx) ++value;
+ atomic ++value;
+ }
+ void dec()
+ {
+ synchronized(mtx) --value;
+ }
+ int get()
+ {
+ synchronized(mtx) return value;
+ return 0; // not reachable
+ }
+};
+
+//boost::mutex non_copyable_class::mtx;
+void test_xxx() {
+
+ {
+ typedef const guard &try_locker;
+ boost::mutex mtx;
+ bool res=false;
+ if (try_locker locker = mtx) {
+ res=true;
+ std::cout << "try_locker:OK=" << int(locker) << std::endl;
+ }
+ BOOST_CHECK(res);
+ }
+ {
+ typedef const try_unique_locker<thread_mutex> &try_locker;
+ boost::mutex mtx;
+ bool res=false;
+ try_unique_locker<boost::mutex> locker(mtx);
+ if (locker) {
+ res=true;
+ std::cout << "try_unique_locker:OK=" << std::endl;
+ }
+ BOOST_CHECK(res);
+ }
+ non_copyable_class cnt;
+ BOOST_CHECK(cnt.get()==0);
+ cnt.inc();
+ BOOST_CHECK(cnt.get()==2);
+ std::cout << "non_copyable_class " << cnt.get() << std::endl;
+ cnt.dec();
+ BOOST_CHECK(cnt.get()==1);
+ std::cout << "non_copyable_class " << cnt.get() << std::endl;
+
+}
+void test_locked() {
+ thread_mutex mtx;
+ unique_lock_type<thread_mutex>::type lock(mtx);
+ BOOST_CHECK(lock);
+ {
+ boost::synchro::nested_reverse_locker<unique_lock_type<thread_mutex>::type > rlock(lock);
+ BOOST_CHECK(!lock);
+ }
+ BOOST_CHECK(lock);
+}
+
+void test_unlocked() {
+ thread_mutex mtx;
+ unique_lock_type<thread_mutex>::type lock(mtx);
+ BOOST_CHECK(lock);
+ lock.unlock();
+ BOOST_CHECK(!lock);
+ {
+ synchro::nested_reverse_locker<unique_lock_type<thread_mutex>::type > rlock(lock);
+ BOOST_CHECK(!lock);
+ }
+ BOOST_CHECK(!lock);
+}
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("nested_reverse_locker_tests");
+ test->add(BOOST_TEST_CASE(&test_xxx));
+ test->add(BOOST_TEST_CASE(&test_locked));
+ test->add(BOOST_TEST_CASE(&test_unlocked));
+ return test;
+}
+

Added: sandbox/sync/libs/sync/test/lock/reverse/reverse_lock_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/reverse/reverse_lock_test.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,52 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/synchro/lockers/reverse_lock.hpp>
+#include <boost/synchro/thread/mutex.hpp>
+#include <boost/synchro/thread/locks.hpp>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+using namespace boost::unit_test;
+using namespace boost::synchro;
+
+void test_locked() {
+ boost::mutex mtx;
+ boost::unique_lock<boost::mutex> lock(mtx);
+ BOOST_CHECK(lock);
+ {
+ boost::synchro::reverse_lock<unique_lock<boost::mutex> > rlock(lock);
+ BOOST_CHECK(!lock);
+ }
+ BOOST_CHECK(lock);
+}
+
+void test_unlocked() {
+ boost::mutex mtx;
+ boost::unique_lock<boost::mutex> lock(mtx);
+ BOOST_CHECK(lock);
+ lock.unlock();
+ BOOST_CHECK(!lock);
+ {
+ boost::synchro::reverse_lock<unique_lock<boost::mutex> > rlock(lock);
+ BOOST_CHECK(!lock);
+ }
+ BOOST_CHECK(!lock);
+}
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("reverse_lock_tests");
+ test->add(BOOST_TEST_CASE(&test_locked));
+ test->add(BOOST_TEST_CASE(&test_unlocked));
+ return test;
+}
+

Added: sandbox/sync/libs/sync/test/lock/types.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/types.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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;
+}

Added: sandbox/sync/libs/sync/test/lock/unique/cons/copy_assign.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/cons/copy_assign.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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);
+}

Added: sandbox/sync/libs/sync/test/lock/unique/cons/copy_ctor.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/cons/copy_ctor.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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);
+}

Added: sandbox/sync/libs/sync/test/lock/unique/cons/default.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/cons/default.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+}

Added: sandbox/sync/libs/sync/test/lock/unique/cons/move_assign.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/cons/move_assign.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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
+}

Added: sandbox/sync/libs/sync/test/lock/unique/cons/move_ctor.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/cons/move_ctor.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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
+}

Added: sandbox/sync/libs/sync/test/lock/unique/cons/mutex.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/cons/mutex.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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 < ns(2500000)); // within 2.5ms
+}
+
+int main()
+{
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/lock/unique/cons/mutex_adopt_lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/cons/mutex_adopt_lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+}

Added: sandbox/sync/libs/sync/test/lock/unique/cons/mutex_defer_lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/cons/mutex_defer_lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+}

Added: sandbox/sync/libs/sync/test/lock/unique/cons/mutex_duration.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/cons/mutex_duration.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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::monotonic_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 < ns(5000000)); // within 5ms
+}
+
+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 < ns(5000000)); // within 5ms
+}
+
+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();
+ }
+}

Added: sandbox/sync/libs/sync/test/lock/unique/cons/mutex_time_point.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/cons/mutex_time_point.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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::monotonic_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 < ns(5000000)); // within 5ms
+}
+
+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();
+ }
+}

Added: sandbox/sync/libs/sync/test/lock/unique/cons/mutex_try_to_lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/cons/mutex_try_to_lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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();
+ m.unlock();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ns(50000000)); // within 50ms
+}
+
+int main()
+{
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/lock/unique/locking/lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/locking/lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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 < ns(2500000)); // within 2.5ms
+ 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();
+}

Added: sandbox/sync/libs/sync/test/lock/unique/locking/try_lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/locking/try_lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+ }
+}

Added: sandbox/sync/libs/sync/test/lock/unique/locking/try_lock_for.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/locking/try_lock_for.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+ }
+}

Added: sandbox/sync/libs/sync/test/lock/unique/locking/try_lock_until.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/locking/try_lock_until.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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::monotonic_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);
+ }
+}

Added: sandbox/sync/libs/sync/test/lock/unique/locking/unlock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/locking/unlock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+ }
+}

Added: sandbox/sync/libs/sync/test/lock/unique/mod/member_swap.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/mod/member_swap.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+}

Added: sandbox/sync/libs/sync/test/lock/unique/mod/nonmember_swap.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/mod/nonmember_swap.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+}

Added: sandbox/sync/libs/sync/test/lock/unique/mod/release.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/mod/release.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <mutex>
+
+// template <class Mutex> class unique_lock;
+
+// void swap(unique_lock& u);
+
+#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);
+}

Added: sandbox/sync/libs/sync/test/lock/unique/obs/mutex.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/obs/mutex.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+}

Added: sandbox/sync/libs/sync/test/lock/unique/obs/op_bool.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/obs/op_bool.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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(lk0 == false);
+ std::unique_lock<std::mutex> lk1(m);
+ assert(lk1 == true);
+ lk1.unlock();
+ assert(lk1 == false);
+}

Added: sandbox/sync/libs/sync/test/lock/unique/obs/owns_lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lock/unique/obs/owns_lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/assign.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/assign.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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;
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/copy.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/copy.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <mutex>
+
+// class mutex;
+
+// mutex(const mutex&) = delete;
+
+#include <mutex>
+
+int main()
+{
+ std::mutex m0;
+ std::mutex m1(m0);
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/default.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/default.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <mutex>
+
+// class mutex;
+
+// mutex();
+
+#include <mutex>
+
+int main()
+{
+ std::mutex m;
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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 < ns(2500000)); // within 2.5ms
+}
+
+int main()
+{
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/native_handle.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/native_handle.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/try_lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_mutex/try_lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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 < ns(50000000)); // within 50ms
+}
+
+int main()
+{
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/assign.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/assign.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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;
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/copy.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/copy.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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);
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/default.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/default.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <mutex>
+
+// class recursive_mutex;
+
+// recursive_mutex();
+
+#include <mutex>
+
+int main()
+{
+ std::recursive_mutex m;
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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 < ns(2500000)); // within 2.5ms
+}
+
+int main()
+{
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/native_handle.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/native_handle.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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);
+}

Added: sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/try_lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/lockable_req/thread_recursive_mutex/try_lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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 < ns(50000000)); // within 50ms
+}
+
+int main()
+{
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/assign.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/assign.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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;
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/copy.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/copy.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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);
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/default.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/default.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <mutex>
+
+// class timed_mutex;
+
+// timed_mutex();
+
+#include <mutex>
+
+int main()
+{
+ std::timed_mutex m;
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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 < ns(2500000)); // within 2.5ms
+}
+
+int main()
+{
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/try_lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/try_lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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 < ns(50000000)); // within 50ms
+}
+
+int main()
+{
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/try_lock_for.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/try_lock_for.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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::monotonic_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 < ns(5000000)); // within 5ms
+}
+
+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(5000000)); // within 5ms
+}
+
+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();
+ }
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/try_lock_until.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_mutex/try_lock_until.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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::monotonic_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 < ns(5000000)); // within 5ms
+}
+
+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 < ns(5000000)); // within 5ms
+}
+
+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();
+ }
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/assign.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/assign.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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;
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/copy.fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/copy.fail.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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);
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/default.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/default.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <mutex>
+
+// class recursive_timed_mutex;
+
+// recursive_timed_mutex();
+
+#include <mutex>
+
+int main()
+{
+ std::recursive_timed_mutex m;
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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 < ns(2500000)); // within 2.5ms
+}
+
+int main()
+{
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/try_lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/try_lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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 < ns(50000000)); // within 50ms
+}
+
+int main()
+{
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/try_lock_for.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/try_lock_for.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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::monotonic_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(5000000)); // within 5ms
+}
+
+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(5000000)); // within 5ms
+}
+
+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();
+ }
+}

Added: sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/try_lock_until.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockable/timed_lockable_req/thread_timed_recursive_mutex/try_lock_until.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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::monotonic_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 < ns(5000000)); // within 5ms
+}
+
+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 < ns(5000000)); // within 5ms
+}
+
+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();
+ }
+}

Added: sandbox/sync/libs/sync/test/lockables/algorithm/lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockables/algorithm/lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,505 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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
+}

Added: sandbox/sync/libs/sync/test/lockables/algorithm/try_lock.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/sync/libs/sync/test/lockables/algorithm/try_lock.pass.cpp 2010-09-23 11:09:33 EDT (Thu, 23 Sep 2010)
@@ -0,0 +1,514 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <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
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk