mirror of git://gcc.gnu.org/git/gcc.git
future (launch): Update enumerators and define operators required for bitmask type.
2011-05-28 Jonathan Wakely <jwakely.gcc@gmail.com> * include/std/future (launch): Update enumerators and define operators required for bitmask type. Remove trailing whitespace. * src/future.cc: Remove trailing whitespace. * testsuite/30_threads/async/any.cc: Adjust. * testsuite/30_threads/async/sync.cc: Adjust. * testsuite/30_threads/async/launch.cc: New. From-SVN: r174374
This commit is contained in:
parent
6ffe882a61
commit
faa0051112
|
|
@ -1,3 +1,12 @@
|
|||
2011-05-28 Jonathan Wakely <jwakely.gcc@gmail.com>
|
||||
|
||||
* include/std/future (launch): Update enumerators and define
|
||||
operators required for bitmask type. Remove trailing whitespace.
|
||||
* src/future.cc: Remove trailing whitespace.
|
||||
* testsuite/30_threads/async/any.cc: Adjust.
|
||||
* testsuite/30_threads/async/sync.cc: Adjust.
|
||||
* testsuite/30_threads/async/launch.cc: New.
|
||||
|
||||
2011-05-28 Jonathan Wakely <jwakely.gcc@gmail.com>
|
||||
|
||||
* include/std/future: Use noexcept.
|
||||
|
|
|
|||
|
|
@ -125,11 +125,40 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
/// Launch code for futures
|
||||
enum class launch
|
||||
{
|
||||
any,
|
||||
async,
|
||||
sync
|
||||
async = 1,
|
||||
deferred = 2
|
||||
};
|
||||
|
||||
inline constexpr launch operator&(launch __x, launch __y)
|
||||
{
|
||||
return static_cast<launch>(
|
||||
static_cast<int>(__x) & static_cast<int>(__y));
|
||||
}
|
||||
|
||||
inline constexpr launch operator|(launch __x, launch __y)
|
||||
{
|
||||
return static_cast<launch>(
|
||||
static_cast<int>(__x) | static_cast<int>(__y));
|
||||
}
|
||||
|
||||
inline constexpr launch operator^(launch __x, launch __y)
|
||||
{
|
||||
return static_cast<launch>(
|
||||
static_cast<int>(__x) ^ static_cast<int>(__y));
|
||||
}
|
||||
|
||||
inline constexpr launch operator~(launch __x)
|
||||
{ return static_cast<launch>(~static_cast<int>(__x)); }
|
||||
|
||||
inline launch& operator&=(launch& __x, launch __y)
|
||||
{ return __x = __x & __y; }
|
||||
|
||||
inline launch& operator|=(launch& __x, launch __y)
|
||||
{ return __x = __x | __y; }
|
||||
|
||||
inline launch& operator^=(launch& __x, launch __y)
|
||||
{ return __x = __x ^ __y; }
|
||||
|
||||
/// Status code for futures
|
||||
enum class future_status
|
||||
{
|
||||
|
|
@ -1363,7 +1392,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
{
|
||||
typedef typename result_of<_Fn(_Args...)>::type result_type;
|
||||
std::shared_ptr<__future_base::_State_base> __state;
|
||||
if (__policy == launch::async)
|
||||
if ((__policy & (launch::async|launch::deferred)) == launch::async)
|
||||
{
|
||||
typedef typename __future_base::_Async_state<result_type> _State;
|
||||
__state = std::make_shared<_State>(std::bind<result_type>(
|
||||
|
|
@ -1384,7 +1413,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
__async_sfinae_helper<typename decay<_Fn>::type, _Fn, _Args...>::type
|
||||
async(_Fn&& __fn, _Args&&... __args)
|
||||
{
|
||||
return async(launch::any, std::forward<_Fn>(__fn),
|
||||
return async(launch::async|launch::deferred, std::forward<_Fn>(__fn),
|
||||
std::forward<_Args>(__args)...);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
// { dg-require-gthreads "" }
|
||||
// { dg-require-atomic-builtins "" }
|
||||
|
||||
// Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
// Copyright (C) 2010, 2011 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
|
|
@ -41,7 +41,7 @@ void test01()
|
|||
int a = 1;
|
||||
int b = 10;
|
||||
int c = 100;
|
||||
future<int> f1 = async(launch::any, sum(), a, ref(b), cref(c));
|
||||
future<int> f1 = async(launch::async|launch::deferred, sum(), a, ref(b), cref(c));
|
||||
future<int> f2 = async(sum(), a, ref(b), cref(c));
|
||||
|
||||
VERIFY( f1.valid() );
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
|
||||
// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
|
||||
// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
|
||||
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
|
||||
// { dg-require-cstdint "" }
|
||||
// { dg-require-gthreads "" }
|
||||
// { dg-require-atomic-builtins "" }
|
||||
|
||||
// Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include <future>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
using std::launch;
|
||||
|
||||
const launch none{};
|
||||
const launch both = launch::async|launch::deferred;
|
||||
const launch all = ~none;
|
||||
|
||||
VERIFY( (none & both) == none );
|
||||
VERIFY( (none | both) == both );
|
||||
VERIFY( (none ^ both) == both );
|
||||
|
||||
VERIFY( (none & all) == none );
|
||||
VERIFY( (none | all) == all );
|
||||
VERIFY( (none ^ all) == all );
|
||||
|
||||
VERIFY( (both & all) == both );
|
||||
VERIFY( (both | all) == all );
|
||||
VERIFY( (both ^ all) == ~both );
|
||||
|
||||
VERIFY( (none & launch::async) == none );
|
||||
VERIFY( (none & launch::deferred) == none );
|
||||
|
||||
VERIFY( (none | launch::async) == launch::async );
|
||||
VERIFY( (none | launch::deferred) == launch::deferred );
|
||||
|
||||
VERIFY( (none ^ launch::async) == launch::async );
|
||||
VERIFY( (none ^ launch::deferred) == launch::deferred );
|
||||
|
||||
VERIFY( (none & none) == none );
|
||||
VERIFY( (none | none) == none );
|
||||
VERIFY( (none ^ none) == none );
|
||||
|
||||
VERIFY( (both & both) == both );
|
||||
VERIFY( (both | both) == both );
|
||||
VERIFY( (both ^ both) == none );
|
||||
|
||||
VERIFY( (all & all) == all );
|
||||
VERIFY( (all | all) == all );
|
||||
VERIFY( (all ^ all) == none );
|
||||
|
||||
launch l = none;
|
||||
|
||||
l &= none;
|
||||
VERIFY( l == none );
|
||||
l |= none;
|
||||
VERIFY( l == none );
|
||||
l ^= none;
|
||||
VERIFY( l == none );
|
||||
|
||||
l &= both;
|
||||
VERIFY( l == none );
|
||||
l |= both;
|
||||
VERIFY( l == both );
|
||||
l ^= both;
|
||||
VERIFY( l == none );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
// { dg-require-gthreads "" }
|
||||
// { dg-require-atomic-builtins "" }
|
||||
|
||||
// Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
// Copyright (C) 2010, 2011 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
|
|
@ -41,7 +41,7 @@ void test01()
|
|||
int a = 1;
|
||||
int b = 10;
|
||||
int c = 100;
|
||||
future<int> f1 = async(launch::sync, sum(), a, ref(b), cref(c));
|
||||
future<int> f1 = async(launch::deferred, sum(), a, ref(b), cref(c));
|
||||
|
||||
VERIFY( f1.valid() );
|
||||
VERIFY( f1.get() == 111 );
|
||||
|
|
|
|||
Loading…
Reference in New Issue