Skip to content

Commit

Permalink
Thread: Refactor futures by adding a basic_future common class + adde…
Browse files Browse the repository at this point in the history
…d some tests for shared_future

[SVN r81129]
  • Loading branch information
viboes committed Oct 31, 2012
1 parent 1c0a499 commit 45c87d3
Show file tree
Hide file tree
Showing 13 changed files with 853 additions and 162 deletions.
296 changes: 142 additions & 154 deletions include/boost/thread/future.hpp

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions test/Jamfile.v2
Expand Up @@ -280,6 +280,18 @@ rule thread-compile-fail ( sources : reqs * : name )
[ thread-run2 ./sync/futures/future/share_pass.cpp : future__share_p ]
;

#explicit ts_shared_future ;
test-suite ts_shared_future
:
[ thread-run2 ./sync/futures/shared_future/copy_assign_pass.cpp : shared_future__copy_assign_p ]
[ thread-run2 ./sync/futures/shared_future/copy_ctor_pass.cpp : shared_future__copy_ctor_p ]
[ thread-run2 ./sync/futures/shared_future/default_pass.cpp : shared_future__default_p ]
[ thread-run2 ./sync/futures/shared_future/dtor_pass.cpp : shared_future__dtor_p ]
[ thread-run2 ./sync/futures/shared_future/get_pass.cpp : shared_future__get_p ]
[ thread-run2 ./sync/futures/shared_future/move_ctor_pass.cpp : shared_future__move_ctor_p ]
[ thread-run2 ./sync/futures/shared_future/move_assign_pass.cpp : shared_future__move_asign_p ]
;

#explicit ts_packaged_task ;
test-suite ts_packaged_task
:
Expand Down
4 changes: 2 additions & 2 deletions test/sync/futures/future/dtor_pass.cpp
Expand Up @@ -14,9 +14,9 @@

// <boost/thread/future.hpp>

// class promise<R>
// class future<R>

// ~promise();
// ~future();

#define BOOST_THREAD_VERSION 3
#include <boost/exception/exception.hpp>
Expand Down
6 changes: 4 additions & 2 deletions test/sync/futures/future/get_pass.cpp
Expand Up @@ -14,9 +14,11 @@

// <boost/thread/future.hpp>

// class promise<R>
// class future<R>

// future<R> get_future();
// const R& future::get();
// R& future<R&>::get();
// void future<void>::get();

//#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
Expand Down
4 changes: 2 additions & 2 deletions test/sync/futures/future/move_assign_pass.cpp
Expand Up @@ -14,9 +14,9 @@

// <future>

// class promise<R>
// class future<R>

// promise& operator=(promise&& rhs);
// future& operator=(future&& rhs);

#define BOOST_THREAD_VERSION 3

Expand Down
4 changes: 2 additions & 2 deletions test/sync/futures/future/move_ctor_pass.cpp
Expand Up @@ -14,9 +14,9 @@

// <future>

// class promise<R>
// class future<R>

// promise(promise&& rhs);
// future(future&& rhs);

#define BOOST_THREAD_VERSION 3

Expand Down
85 changes: 85 additions & 0 deletions test/sync/futures/shared_future/copy_assign_pass.cpp
@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)

// <boost/thread/future.hpp>

// class shared_future<R>

// shared_future& operator=(const shared_future&);


#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>

int main()
{
{
typedef int T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f;
f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());

}
{
typedef int T;
boost::shared_future<T> f0;
boost::shared_future<T> f;
f = f0;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef int& T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f;
f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int& T;
boost::shared_future<T> f0;
boost::shared_future<T> f;
f = f0;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef void T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f;
f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());
}
{
typedef void T;
boost::shared_future<T> f0;
boost::shared_future<T> f;
f = f0;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}

return boost::report_errors();
}

//#include "../../../remove_error_code_unused_warning.hpp"

77 changes: 77 additions & 0 deletions test/sync/futures/shared_future/copy_ctor_pass.cpp
@@ -0,0 +1,77 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)

// <boost/thread/future.hpp>
// class shared_future<R>

// shared_future(const future&);


#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>

int main()
{
{
typedef int T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int T;
boost::shared_future < T > f0;
boost::shared_future<T> f = f0;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef int& T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());
}
{
typedef int& T;
boost::shared_future < T > f0;
boost::shared_future<T> f = boost::move(f0);
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}
{
typedef void T;
boost::promise<T> p;
boost::shared_future<T> f0((p.get_future()));
boost::shared_future<T> f = f0;
BOOST_TEST(f0.valid());
BOOST_TEST(f.valid());
}
{
typedef void T;
boost::shared_future < T > f0;
boost::shared_future<T> f = f0;
BOOST_TEST(!f0.valid());
BOOST_TEST(!f.valid());
}

return boost::report_errors();
}

//#include "../../../remove_error_code_unused_warning.hpp"

45 changes: 45 additions & 0 deletions test/sync/futures/shared_future/default_pass.cpp
@@ -0,0 +1,45 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)

// <boost/thread/future.hpp>

// class shared_future<R>

// shared_future();

#define BOOST_THREAD_VERSION 3

#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>

int main()
{

{
boost::shared_future<int> f;
BOOST_TEST(!f.valid());
}
{
boost::shared_future<int&> f;
BOOST_TEST(!f.valid());
}
{
boost::shared_future<void> f;
BOOST_TEST(!f.valid());
}


return boost::report_errors();
}

109 changes: 109 additions & 0 deletions test/sync/futures/shared_future/dtor_pass.cpp
@@ -0,0 +1,109 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// Copyright (C) 2011 Vicente J. Botet Escriba
//
// 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)

// <boost/thread/future.hpp>

// class shared_future<R>

// ~shared_future();

#define BOOST_THREAD_VERSION 3
#include <boost/exception/exception.hpp>

#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
#include "../test_allocator.hpp"
#endif

int main()
{
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
BOOST_TEST(test_alloc_base::count == 0);
{
typedef int T;
boost::shared_future<T> f;
{
boost::promise<T> p(boost::allocator_arg, test_allocator<T>());
BOOST_TEST(test_alloc_base::count == 1);
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 0);
{
typedef int& T;
boost::shared_future<T> f;
{
boost::promise<T> p(boost::allocator_arg, test_allocator<int>());
BOOST_TEST(test_alloc_base::count == 1);
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 0);
{
typedef void T;
boost::shared_future<T> f;
{
boost::promise<T> p(boost::allocator_arg, test_allocator<T>());
BOOST_TEST(test_alloc_base::count == 1);
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 1);
BOOST_TEST(f.valid());
}
BOOST_TEST(test_alloc_base::count == 0);
#endif
{
typedef int T;
boost::shared_future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
}
BOOST_TEST(f.valid());
}
{
typedef int& T;
boost::shared_future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
}
BOOST_TEST(f.valid());
}
{
typedef void T;
boost::shared_future<T> f;
{
boost::promise<T> p;
f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
BOOST_TEST(f.valid());
}
BOOST_TEST(f.valid());
}
return boost::report_errors();
}

0 comments on commit 45c87d3

Please sign in to comment.