Commit b7200e3f by Jonathan Wakely Committed by Jonathan Wakely

condition_variable (condition_variable_any): Provide definitions for all members.

2010-02-03  Jonathan Wakely  <jwakely.gcc@gmail.com>

	* include/std/condition_variable (condition_variable_any): Provide
	definitions for all members.
	* src/condition_variable.cc (condition_variable_any): Adjust
	definitions.
	* config/abi/pre/gnu.ver: Adjust exports for condition_variable_any.
	* 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_any/members/1.cc: New.
	* testsuite/30_threads/condition_variable_any/members/2.cc: New.
	* testsuite/30_threads/condition_variable_any/requirements/
	standard_layout.cc: Remove.
	* testsuite/30_threads/condition_variable_any/native_handle/
	typesizes.cc: Remove.

From-SVN: r156479
parent a7f3e500
2010-02-03 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/std/condition_variable (condition_variable_any): Provide
definitions for all members.
* src/condition_variable.cc (condition_variable_any): Adjust
definitions.
* config/abi/pre/gnu.ver: Adjust exports for condition_variable_any.
* 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_any/members/1.cc: New.
* testsuite/30_threads/condition_variable_any/members/2.cc: New.
* testsuite/30_threads/condition_variable_any/requirements/
standard_layout.cc: Remove.
* testsuite/30_threads/condition_variable_any/native_handle/
typesizes.cc: Remove.
2010-02-02 Paolo Carlini <paolo.carlini@oracle.com> 2010-02-02 Paolo Carlini <paolo.carlini@oracle.com>
* include/ext/vstring.h (__versa_string::shrink_to_fit): Fix * include/ext/vstring.h (__versa_string::shrink_to_fit): Fix
......
...@@ -1113,10 +1113,6 @@ GLIBCXX_3.4.14 { ...@@ -1113,10 +1113,6 @@ GLIBCXX_3.4.14 {
# std::time_get::_M_extract_wday_or_month # std::time_get::_M_extract_wday_or_month
_ZNKSt8time_getI[cw]St19istreambuf_iteratorI[cw]St11char_traitsI[cw]EEE24_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; } GLIBCXX_3.4.13;
# Symbols in the support library (libsupc++) have their own tag. # Symbols in the support library (libsupc++) have their own tag.
......
...@@ -162,14 +162,15 @@ namespace std ...@@ -162,14 +162,15 @@ namespace std
}; };
/// condition_variable_any /// condition_variable_any
// Like above, only mutex may not have try_lock. // Like above, but mutex is not required to have try_lock.
class condition_variable_any class condition_variable_any
{ {
typedef __gthread_cond_t __native_type; typedef chrono::system_clock __clock_t;
__native_type _M_cond; condition_variable _M_cond;
mutex _M_mutex;
public: public:
typedef __native_type* native_handle_type; typedef condition_variable::native_handle_type native_handle_type;
condition_variable_any() throw (); condition_variable_any() throw ();
~condition_variable_any() throw (); ~condition_variable_any() throw ();
...@@ -178,14 +179,29 @@ namespace std ...@@ -178,14 +179,29 @@ namespace std
condition_variable_any& operator=(const condition_variable_any&) = delete; condition_variable_any& operator=(const condition_variable_any&) = delete;
void void
notify_one(); notify_one()
{
lock_guard<mutex> __lock(_M_mutex);
_M_cond.notify_one();
}
void void
notify_all(); notify_all()
{
lock_guard<mutex> __lock(_M_mutex);
_M_cond.notify_all();
}
template<typename _Lock> template<typename _Lock>
void void
wait(_Lock& __lock); wait(_Lock& __lock)
{
unique_lock<mutex> __my_lock(_M_mutex);
__lock.unlock();
_M_cond.wait(__my_lock);
__lock.lock();
}
template<typename _Lock, typename _Predicate> template<typename _Lock, typename _Predicate>
void void
...@@ -198,7 +214,14 @@ namespace std ...@@ -198,7 +214,14 @@ namespace std
template<typename _Lock, typename _Clock, typename _Duration> template<typename _Lock, typename _Clock, typename _Duration>
cv_status cv_status
wait_until(_Lock& __lock, wait_until(_Lock& __lock,
const chrono::time_point<_Clock, _Duration>& __atime); const chrono::time_point<_Clock, _Duration>& __atime)
{
unique_lock<mutex> __my_lock(_M_mutex);
__lock.unlock();
cv_status __status = _M_cond.wait_until(__my_lock, __atime);
__lock.lock();
return __status;
}
template<typename _Lock, typename _Clock, template<typename _Lock, typename _Clock,
typename _Duration, typename _Predicate> typename _Duration, typename _Predicate>
...@@ -215,17 +238,19 @@ namespace std ...@@ -215,17 +238,19 @@ namespace std
template<typename _Lock, typename _Rep, typename _Period> template<typename _Lock, typename _Rep, typename _Period>
cv_status cv_status
wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __rtime); wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __rtime)
{ return wait_until(__lock, __clock_t::now() + __rtime); }
template<typename _Lock, typename _Rep, template<typename _Lock, typename _Rep,
typename _Period, typename _Predicate> typename _Period, typename _Predicate>
bool bool
wait_for(_Lock& __lock, wait_for(_Lock& __lock,
const chrono::duration<_Rep, _Period>& __rtime, _Predicate __p); const chrono::duration<_Rep, _Period>& __rtime, _Predicate __p)
{ return wait_until(__lock, __clock_t::now() + __rtime, std::move(__p)); }
native_handle_type native_handle_type
native_handle() native_handle()
{ return &_M_cond; } { return _M_cond.native_handle(); }
}; };
// @} group condition_variables // @} group condition_variables
......
...@@ -80,44 +80,10 @@ namespace std ...@@ -80,44 +80,10 @@ namespace std
} }
condition_variable_any::condition_variable_any() throw () condition_variable_any::condition_variable_any() throw ()
{ { }
#ifdef __GTHREAD_COND_INIT
__native_type __tmp = __GTHREAD_COND_INIT;
_M_cond = __tmp;
#else
int __e = __gthread_cond_init(&_M_cond, NULL);
if (__e)
__throw_system_error(__e);
#endif
}
condition_variable_any::~condition_variable_any() throw () condition_variable_any::~condition_variable_any() throw ()
{ { }
__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 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
...@@ -32,4 +32,4 @@ void test01() ...@@ -32,4 +32,4 @@ void test01()
} }
// { dg-error "used here" "" { target *-*-* } 31 } // { dg-error "used here" "" { target *-*-* } 31 }
// { dg-error "deleted function" "" { target *-*-* } 178 } // { dg-error "deleted function" "" { target *-*-* } 179 }
...@@ -31,4 +31,4 @@ void test01() ...@@ -31,4 +31,4 @@ void test01()
} }
// { dg-error "used here" "" { target *-*-* } 30 } // { dg-error "used here" "" { target *-*-* } 30 }
// { dg-error "deleted function" "" { target *-*-* } 177 } // { dg-error "deleted function" "" { target *-*-* } 178 }
// { 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) 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>
struct Mutex
{
Mutex() : locked(false) { }
void lock()
{
if (locked)
throw locked;
mtx.lock();
locked = true;
}
void unlock()
{
if (!locked)
throw locked;
mtx.unlock();
locked = false;
}
std::mutex mtx;
bool locked;
};
void test01()
{
bool test __attribute__((unused)) = true;
try
{
std::chrono::microseconds ms(500);
std::condition_variable_any c1;
Mutex m;
m.lock();
auto then = std::chrono::system_clock::now();
std::cv_status result = c1.wait_for(m, ms);
VERIFY( result == std::cv_status::timeout );
VERIFY( (std::chrono::system_clock::now() - then) >= ms );
VERIFY( m.locked );
}
catch (const std::system_error& e)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
}
int main()
{
test01();
return 0;
}
// { 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) 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>
struct Mutex
{
Mutex() : locked(false) { }
void lock()
{
if (locked)
throw locked;
mtx.lock();
locked = true;
}
void unlock()
{
if (!locked)
throw locked;
mtx.unlock();
locked = false;
}
std::mutex mtx;
bool locked;
};
void test01()
{
bool test __attribute__((unused)) = true;
try
{
std::chrono::microseconds ms(500);
std::condition_variable_any c1;
Mutex m;
m.lock();
auto then = std::chrono::monotonic_clock::now();
std::cv_status result = c1.wait_until(m, then + ms);
VERIFY( result == std::cv_status::timeout );
VERIFY( (std::chrono::monotonic_clock::now() - then) >= ms );
VERIFY( m.locked );
}
catch (const std::system_error& e)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
}
int main()
{
test01();
return 0;
}
// { 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) 2009 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 <thread/all.h>
int main()
{
typedef std::condition_variable_any test_type;
__gnu_test::compare_type_to_native_type<test_type>();
return 0;
}
// { 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>();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment