condition_variable (condition_variable_any:: __wait_until_impl): Add.
2010-01-29 Paolo Carlini <paolo.carlini@oracle.com> * include/std/condition_variable (condition_variable_any:: __wait_until_impl): Add. (condition_variable_any::wait_until): Provide definitions. * testsuite/30_threads/condition_variable_any/members/2.cc: New. * testsuite/30_threads/condition_variable_any/cons/assign_neg.cc: Adjust dg-error line number. * testsuite/30_threads/condition_variable_any/cons/copy_neg.cc: Likewise. * testsuite/30_threads/condition_variable/members/1.cc: Minor stylistic changes. * testsuite/30_threads/condition_variable/members/1.cc: Likewise. From-SVN: r156367
This commit is contained in:
parent
55eb4dab27
commit
023cee968b
7 changed files with 136 additions and 13 deletions
|
@ -1,3 +1,18 @@
|
|||
2010-01-29 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
* include/std/condition_variable (condition_variable_any::
|
||||
__wait_until_impl): Add.
|
||||
(condition_variable_any::wait_until): Provide definitions.
|
||||
* testsuite/30_threads/condition_variable_any/members/2.cc: New.
|
||||
* testsuite/30_threads/condition_variable_any/cons/assign_neg.cc:
|
||||
Adjust dg-error line number.
|
||||
* testsuite/30_threads/condition_variable_any/cons/copy_neg.cc:
|
||||
Likewise.
|
||||
|
||||
* testsuite/30_threads/condition_variable/members/1.cc: Minor
|
||||
stylistic changes.
|
||||
* testsuite/30_threads/condition_variable/members/1.cc: Likewise.
|
||||
|
||||
2010-01-29 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
* include/std/condition_variable (enum class cv_status): Add and
|
||||
|
|
|
@ -98,10 +98,10 @@ namespace std
|
|||
const chrono::time_point<_Clock, _Duration>& __atime)
|
||||
{
|
||||
// DR 887 - Sync unknown clock to known clock.
|
||||
typename _Clock::time_point __c_entry = _Clock::now();
|
||||
__clock_t::time_point __s_entry = __clock_t::now();
|
||||
chrono::nanoseconds __delta = __atime - __c_entry;
|
||||
__clock_t::time_point __s_atime = __s_entry + __delta;
|
||||
const typename _Clock::time_point __c_entry = _Clock::now();
|
||||
const __clock_t::time_point __s_entry = __clock_t::now();
|
||||
const chrono::nanoseconds __delta = __atime - __c_entry;
|
||||
const __clock_t::time_point __s_atime = __s_entry + __delta;
|
||||
|
||||
return __wait_until_impl(__lock, __s_atime);
|
||||
}
|
||||
|
@ -165,6 +165,7 @@ namespace std
|
|||
// Like above, only mutex may not have try_lock.
|
||||
class condition_variable_any
|
||||
{
|
||||
typedef chrono::system_clock __clock_t;
|
||||
typedef __gthread_cond_t __native_type;
|
||||
__native_type _M_cond;
|
||||
|
||||
|
@ -201,10 +202,25 @@ namespace std
|
|||
wait(__lock);
|
||||
}
|
||||
|
||||
template<typename _Lock, typename _Duration>
|
||||
cv_status
|
||||
wait_until(_Lock& __lock,
|
||||
const chrono::time_point<__clock_t, _Duration>& __atime)
|
||||
{ return __wait_until_impl(__lock, __atime); }
|
||||
|
||||
template<typename _Lock, typename _Clock, typename _Duration>
|
||||
cv_status
|
||||
wait_until(_Lock& __lock,
|
||||
const chrono::time_point<_Clock, _Duration>& __atime);
|
||||
const chrono::time_point<_Clock, _Duration>& __atime)
|
||||
{
|
||||
// DR 887 - Sync unknown clock to known clock.
|
||||
const typename _Clock::time_point __c_entry = _Clock::now();
|
||||
const __clock_t::time_point __s_entry = __clock_t::now();
|
||||
const chrono::nanoseconds __delta = __atime - __c_entry;
|
||||
const __clock_t::time_point __s_atime = __s_entry + __delta;
|
||||
|
||||
return __wait_until_impl(__lock, __s_atime);
|
||||
}
|
||||
|
||||
template<typename _Lock, typename _Clock,
|
||||
typename _Duration, typename _Predicate>
|
||||
|
@ -232,6 +248,31 @@ namespace std
|
|||
native_handle_type
|
||||
native_handle()
|
||||
{ return &_M_cond; }
|
||||
|
||||
private:
|
||||
template<typename _Lock, typename _Clock, typename _Duration>
|
||||
cv_status
|
||||
__wait_until_impl(_Lock& __lock,
|
||||
const chrono::time_point<_Clock, _Duration>& __atime)
|
||||
{
|
||||
chrono::time_point<__clock_t, chrono::seconds> __s =
|
||||
chrono::time_point_cast<chrono::seconds>(__atime);
|
||||
|
||||
chrono::nanoseconds __ns =
|
||||
chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
|
||||
|
||||
__gthread_time_t __ts =
|
||||
{
|
||||
static_cast<std::time_t>(__s.time_since_epoch().count()),
|
||||
static_cast<long>(__ns.count())
|
||||
};
|
||||
|
||||
__gthread_cond_timedwait(&_M_cond, __lock.mutex()->native_handle(),
|
||||
&__ts);
|
||||
|
||||
return (_Clock::now() < __atime
|
||||
? cv_status::no_timeout : cv_status::timeout);
|
||||
}
|
||||
};
|
||||
|
||||
// @} group condition_variables
|
||||
|
|
|
@ -5,7 +5,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
|
||||
|
@ -22,13 +22,12 @@
|
|||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <system_error>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
int main()
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
|
@ -53,6 +52,10 @@ int main()
|
|||
{
|
||||
VERIFY( false );
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,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
|
||||
|
@ -22,13 +22,12 @@
|
|||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <system_error>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
int main()
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
|
@ -53,6 +52,10 @@ int main()
|
|||
{
|
||||
VERIFY( false );
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -32,4 +32,4 @@ void test01()
|
|||
}
|
||||
|
||||
// { dg-error "used here" "" { target *-*-* } 31 }
|
||||
// { dg-error "deleted function" "" { target *-*-* } 178 }
|
||||
// { dg-error "deleted function" "" { target *-*-* } 179 }
|
||||
|
|
|
@ -31,4 +31,4 @@ void test01()
|
|||
}
|
||||
|
||||
// { dg-error "used here" "" { target *-*-* } 30 }
|
||||
// { dg-error "deleted function" "" { target *-*-* } 177 }
|
||||
// { dg-error "deleted function" "" { target *-*-* } 178 }
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
// { 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 "" }
|
||||
|
||||
// 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
|
||||
// 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 <chrono>
|
||||
#include <condition_variable>
|
||||
#include <system_error>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
try
|
||||
{
|
||||
std::chrono::microseconds ms(500);
|
||||
std::condition_variable_any c1;
|
||||
std::mutex m;
|
||||
std::unique_lock<std::mutex> l(m);
|
||||
|
||||
auto then = std::chrono::monotonic_clock::now();
|
||||
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() );
|
||||
}
|
||||
catch (const std::system_error& e)
|
||||
{
|
||||
VERIFY( false );
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
VERIFY( false );
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue