condition_variable (enum class cv_status): Add and use it throughout, per N3000.

2010-01-29  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/std/condition_variable (enum class cv_status): Add and
	use it throughout, per N3000.
	(condition_variable_any::wait<>(_Lock&), wait<>(_Lock&, _Predicate),
	wait_until<>(_Lock&, const chrono::time_point<>&, _Predicate)):
	Provide definitions.
	* src/condition_variable.cc (condition_variable_any::notify_one,
	condition_variable_any::notify_all): Likewise.
	* config/abi/pre/gnu.ver: Export.
	* testsuite/30_threads/condition_variable_any/requirements/
	typedefs.cc: New.
	* testsuite/30_threads/condition_variable_any/requirements/
	standard_layout.cc: Likewise.
	* testsuite/30_threads/condition_variable/members/1.cc: Adjust.
	* testsuite/30_threads/condition_variable/members/2.cc: Likewise.
	* testsuite/30_threads/condition_variable/cons/assign_neg.cc: Adjust
	dg-error line numbers.
	* testsuite/30_threads/condition_variable/cons/copy_neg.cc: Likewise.
	* testsuite/30_threads/condition_variable_any/cons/assign_neg.cc:
	Likewise.
	* testsuite/30_threads/condition_variable_any/cons/copy_neg.cc:
	Likewise.

From-SVN: r156358
This commit is contained in:
Paolo Carlini 2010-01-29 16:59:55 +00:00 committed by Paolo Carlini
parent f9e06dbc62
commit cdf5f5a34d
12 changed files with 152 additions and 23 deletions

View file

@ -1,3 +1,27 @@
2010-01-29 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/condition_variable (enum class cv_status): Add and
use it throughout, per N3000.
(condition_variable_any::wait<>(_Lock&), wait<>(_Lock&, _Predicate),
wait_until<>(_Lock&, const chrono::time_point<>&, _Predicate)):
Provide definitions.
* src/condition_variable.cc (condition_variable_any::notify_one,
condition_variable_any::notify_all): Likewise.
* config/abi/pre/gnu.ver: Export.
* testsuite/30_threads/condition_variable_any/requirements/
typedefs.cc: New.
* testsuite/30_threads/condition_variable_any/requirements/
standard_layout.cc: Likewise.
* testsuite/30_threads/condition_variable/members/1.cc: Adjust.
* testsuite/30_threads/condition_variable/members/2.cc: Likewise.
* testsuite/30_threads/condition_variable/cons/assign_neg.cc: Adjust
dg-error line numbers.
* testsuite/30_threads/condition_variable/cons/copy_neg.cc: Likewise.
* testsuite/30_threads/condition_variable_any/cons/assign_neg.cc:
Likewise.
* testsuite/30_threads/condition_variable_any/cons/copy_neg.cc:
Likewise.
2010-01-28 François Dumont <francois.cppdevs@free.fr>
* include/bits/stl_algobase.h (struct __iter_base): Add.

View file

@ -1113,6 +1113,10 @@ GLIBCXX_3.4.14 {
# std::time_get::_M_extract_wday_or_month
_ZNKSt8time_getI[cw]St19istreambuf_iteratorI[cw]St11char_traitsI[cw]EEE24_M_extract_wday_or_month*;
# condition_variable_any::notify_*
_ZNSt22condition_variable_any10notify_allEv;
_ZNSt22condition_variable_any10notify_oneEv;
} GLIBCXX_3.4.13;
# Symbols in the support library (libsupc++) have their own tag.

View file

@ -1,6 +1,6 @@
// <condition_variable> -*- C++ -*-
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
// Copyright (C) 2008, 2009, 2010 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
@ -50,6 +50,9 @@ namespace std
* @{
*/
/// cv_status
enum class cv_status { no_timeout, timeout };
/// condition_variable
class condition_variable
{
@ -84,13 +87,13 @@ namespace std
}
template<typename _Duration>
bool
cv_status
wait_until(unique_lock<mutex>& __lock,
const chrono::time_point<__clock_t, _Duration>& __atime)
{ return __wait_until_impl(__lock, __atime); }
template<typename _Clock, typename _Duration>
bool
cv_status
wait_until(unique_lock<mutex>& __lock,
const chrono::time_point<_Clock, _Duration>& __atime)
{
@ -110,14 +113,13 @@ namespace std
_Predicate __p)
{
while (!__p())
if (!wait_until(__lock, __atime))
if (wait_until(__lock, __atime) == cv_status::timeout)
return __p();
return true;
}
template<typename _Rep, typename _Period>
bool
cv_status
wait_for(unique_lock<mutex>& __lock,
const chrono::duration<_Rep, _Period>& __rtime)
{ return wait_until(__lock, __clock_t::now() + __rtime); }
@ -135,7 +137,7 @@ namespace std
private:
template<typename _Clock, typename _Duration>
bool
cv_status
__wait_until_impl(unique_lock<mutex>& __lock,
const chrono::time_point<_Clock, _Duration>& __atime)
{
@ -154,7 +156,8 @@ namespace std
__gthread_cond_timedwait(&_M_cond, __lock.mutex()->native_handle(),
&__ts);
return _Clock::now() < __atime;
return (_Clock::now() < __atime
? cv_status::no_timeout : cv_status::timeout);
}
};
@ -182,14 +185,24 @@ namespace std
template<typename _Lock>
void
wait(_Lock& __lock);
wait(_Lock& __lock)
{
int __e = __gthread_cond_wait(&_M_cond,
__lock.mutex()->native_handle());
if (__e)
__throw_system_error(__e);
}
template<typename _Lock, typename _Predicate>
void
wait(_Lock& __lock, _Predicate __p);
wait(_Lock& __lock, _Predicate __p)
{
while (!__p())
wait(__lock);
}
template<typename _Lock, typename _Clock, typename _Duration>
bool
cv_status
wait_until(_Lock& __lock,
const chrono::time_point<_Clock, _Duration>& __atime);
@ -198,10 +211,16 @@ namespace std
bool
wait_until(_Lock& __lock,
const chrono::time_point<_Clock, _Duration>& __atime,
_Predicate __p);
_Predicate __p)
{
while (!__p())
if (wait_until(__lock, __atime) == cv_status::timeout)
return __p();
return true;
}
template<typename _Lock, typename _Rep, typename _Period>
bool
cv_status
wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __rtime);
template<typename _Lock, typename _Rep,

View file

@ -96,6 +96,28 @@ namespace std
{
__gthread_cond_destroy(&_M_cond);
}
void
condition_variable_any::notify_one()
{
int __e = __gthread_cond_signal(&_M_cond);
// XXX not in spec
// EINVAL
if (__e)
__throw_system_error(__e);
}
void
condition_variable_any::notify_all()
{
int __e = __gthread_cond_broadcast(&_M_cond);
// XXX not in spec
// EINVAL
if (__e)
__throw_system_error(__e);
}
}
#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1

View file

@ -32,4 +32,4 @@ void test01()
}
// { dg-error "used here" "" { target *-*-* } 31 }
// { dg-error "deleted function" "" { target *-*-* } 67 }
// { dg-error "deleted function" "" { target *-*-* } 70 }

View file

@ -31,4 +31,4 @@ void test01()
}
// { dg-error "used here" "" { target *-*-* } 30 }
// { dg-error "deleted function" "" { target *-*-* } 66 }
// { dg-error "deleted function" "" { target *-*-* } 69 }

View file

@ -40,8 +40,8 @@ int main()
std::unique_lock<std::mutex> l(m);
auto then = std::chrono::system_clock::now();
bool result = c1.wait_for(l, ms);
VERIFY( !result );
std::cv_status result = c1.wait_for(l, ms);
VERIFY( result == std::cv_status::timeout );
VERIFY( (std::chrono::system_clock::now() - then) >= ms );
VERIFY( l.owns_lock() );
}

View file

@ -40,8 +40,8 @@ int main()
std::unique_lock<std::mutex> l(m);
auto then = std::chrono::monotonic_clock::now();
bool result = c1.wait_until(l, then + ms);
VERIFY( !result );
std::cv_status result = c1.wait_until(l, then + ms);
VERIFY( result == std::cv_status::timeout );
VERIFY( (std::chrono::monotonic_clock::now() - then) >= ms );
VERIFY( l.owns_lock() );
}

View file

@ -3,7 +3,7 @@
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
// Copyright (C) 2008, 2009, 2010 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
@ -32,4 +32,4 @@ void test01()
}
// { dg-error "used here" "" { target *-*-* } 31 }
// { dg-error "deleted function" "" { target *-*-* } 175 }
// { dg-error "deleted function" "" { target *-*-* } 178 }

View file

@ -3,7 +3,7 @@
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
// Copyright (C) 2008, 2009, 2010 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
@ -31,4 +31,4 @@ void test01()
}
// { dg-error "used here" "" { target *-*-* } 30 }
// { dg-error "deleted function" "" { target *-*-* } 174 }
// { dg-error "deleted function" "" { target *-*-* } 177 }

View file

@ -0,0 +1,30 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2010 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 <condition_variable>
#include <testsuite_common_types.h>
void test01()
{
__gnu_test::standard_layout test;
test.operator()<std::condition_variable_any>();
}

View file

@ -0,0 +1,30 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// Copyright (C) 2010 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 <condition_variable>
void test01()
{
// Check for required typedefs
typedef std::condition_variable_any test_type;
typedef test_type::native_handle_type type;
}