condition_variable: New.

2008-05-06  Benjamin Kosnik  <bkoz@redhat.com>

	* include/std/condition_variable: New.
	* include/std/mutex: New.
	* src/condition_variable.cc: New.
	* src/mutex.cc: New.
	* include/bits/functexcept.h: Add __throw_system_error varients.
	* src/functexcept.cc: Same.
	* config/abi/pre/gnu.ver: Add exports.

	* doc/xml/manual/using.xml: Add new includes.
	* doc/doxygen/user.cfg.in: Doxygen support.
	* doc/doxygen/doxygroups.cc: Same.

	* include/Makefile.am: Add mutex, condition_variable.
	* include/Makefile.in: Regenerated.
	* src/Makefile.am: Add mutex.cc, condition_variable.cc.
	* src/Makefile.in: Regenerated.

	* testsuite/30_threads: New.
	* testsuite/30_threads/lock_error: New.
	* testsuite/30_threads/mutex: New.
	* testsuite/30_threads/mutex/dest: New.
	* testsuite/30_threads/mutex/dest/destructor_locked.cc: New.
	* testsuite/30_threads/mutex/native_handle: New.
	* testsuite/30_threads/mutex/native_handle/1.cc: New.
	* testsuite/30_threads/mutex/cons: New.
	* testsuite/30_threads/mutex/cons/assign_neg.cc: New.
	* testsuite/30_threads/mutex/cons/1.cc: New.
	* testsuite/30_threads/mutex/cons/copy_neg.cc: New.
	* testsuite/30_threads/mutex/requirements: New.
	* testsuite/30_threads/mutex/requirements/typedefs.cc: New.
	* testsuite/30_threads/mutex/try_lock: New.
	* testsuite/30_threads/mutex/try_lock/1.cc: New.
	* testsuite/30_threads/mutex/try_lock/2.cc: New.
	* testsuite/30_threads/mutex/lock: New.
	* testsuite/30_threads/mutex/lock/1.cc: New.
	* testsuite/30_threads/mutex/unlock: New.
	* testsuite/30_threads/mutex/unlock/1.cc: New.
	* testsuite/30_threads/recursive_mutex: New.
	* testsuite/30_threads/recursive_mutex/dest: New.
	* testsuite/30_threads/recursive_mutex/dest/destructor_locked.cc: New.
	* testsuite/30_threads/recursive_mutex/native_handle: New.
	* testsuite/30_threads/recursive_mutex/native_handle/1.cc: New.
	* testsuite/30_threads/recursive_mutex/cons: New.
	* testsuite/30_threads/recursive_mutex/cons/assign_neg.cc: New.
	* testsuite/30_threads/recursive_mutex/cons/1.cc: New.
	* testsuite/30_threads/recursive_mutex/cons/copy_neg.cc: New.
	* testsuite/30_threads/recursive_mutex/requirements: New.
	* testsuite/30_threads/recursive_mutex/requirements/typedefs.cc: New.
	* testsuite/30_threads/lock_guard: New.
	* testsuite/30_threads/lock_guard/requirements: New.
	* testsuite/30_threads/lock_guard/requirements/typedefs.cc: New.
	* testsuite/30_threads/lock_guard/requirements/
	explicit_instantiation.cc: New.
	* testsuite/30_threads/headers: New.
	* testsuite/30_threads/headers/mutex: New.
	* testsuite/30_threads/headers/mutex/types_std_c++0x.cc: New.
	* testsuite/30_threads/headers/mutex/std_c++0x_neg.cc: New.
	* testsuite/30_threads/headers/condition_variable: New.
	* testsuite/30_threads/headers/condition_variable/
	types_std_c++0x.cc: New.
	* testsuite/30_threads/headers/condition_variable/std_c++0x_neg.cc: New.
	* testsuite/30_threads/once_flag: New.
	* testsuite/30_threads/unique_lock: New.
	* testsuite/30_threads/unique_lock/requirements: New.
	* testsuite/30_threads/unique_lock/requirements/typedefs.cc: New.
	* testsuite/30_threads/unique_lock/requirements/
	explicit_instantiation.cc: New.
	* testsuite/17_intro/headers/c++200x/all.cc: Add new includes.

From-SVN: r135007
This commit is contained in:
Benjamin Kosnik 2008-05-06 21:11:47 +00:00
parent 006601890b
commit 68a97d242c
40 changed files with 2010 additions and 72 deletions

View File

@ -1,3 +1,74 @@
2008-05-06 Benjamin Kosnik <bkoz@redhat.com>
* include/std/condition_variable: New.
* include/std/mutex: New.
* src/condition_variable.cc: New.
* src/mutex.cc: New.
* include/bits/functexcept.h: Add __throw_system_error varients.
* src/functexcept.cc: Same.
* config/abi/pre/gnu.ver: Add exports.
* doc/xml/manual/using.xml: Add new includes.
* doc/doxygen/user.cfg.in: Doxygen support.
* doc/doxygen/doxygroups.cc: Same.
* include/Makefile.am: Add mutex, condition_variable.
* include/Makefile.in: Regenerated.
* src/Makefile.am: Add mutex.cc, condition_variable.cc.
* src/Makefile.in: Regenerated.
* testsuite/30_threads: New.
* testsuite/30_threads/lock_error: New.
* testsuite/30_threads/mutex: New.
* testsuite/30_threads/mutex/dest: New.
* testsuite/30_threads/mutex/dest/destructor_locked.cc: New.
* testsuite/30_threads/mutex/native_handle: New.
* testsuite/30_threads/mutex/native_handle/1.cc: New.
* testsuite/30_threads/mutex/cons: New.
* testsuite/30_threads/mutex/cons/assign_neg.cc: New.
* testsuite/30_threads/mutex/cons/1.cc: New.
* testsuite/30_threads/mutex/cons/copy_neg.cc: New.
* testsuite/30_threads/mutex/requirements: New.
* testsuite/30_threads/mutex/requirements/typedefs.cc: New.
* testsuite/30_threads/mutex/try_lock: New.
* testsuite/30_threads/mutex/try_lock/1.cc: New.
* testsuite/30_threads/mutex/try_lock/2.cc: New.
* testsuite/30_threads/mutex/lock: New.
* testsuite/30_threads/mutex/lock/1.cc: New.
* testsuite/30_threads/mutex/unlock: New.
* testsuite/30_threads/mutex/unlock/1.cc: New.
* testsuite/30_threads/recursive_mutex: New.
* testsuite/30_threads/recursive_mutex/dest: New.
* testsuite/30_threads/recursive_mutex/dest/destructor_locked.cc: New.
* testsuite/30_threads/recursive_mutex/native_handle: New.
* testsuite/30_threads/recursive_mutex/native_handle/1.cc: New.
* testsuite/30_threads/recursive_mutex/cons: New.
* testsuite/30_threads/recursive_mutex/cons/assign_neg.cc: New.
* testsuite/30_threads/recursive_mutex/cons/1.cc: New.
* testsuite/30_threads/recursive_mutex/cons/copy_neg.cc: New.
* testsuite/30_threads/recursive_mutex/requirements: New.
* testsuite/30_threads/recursive_mutex/requirements/typedefs.cc: New.
* testsuite/30_threads/lock_guard: New.
* testsuite/30_threads/lock_guard/requirements: New.
* testsuite/30_threads/lock_guard/requirements/typedefs.cc: New.
* testsuite/30_threads/lock_guard/requirements/
explicit_instantiation.cc: New.
* testsuite/30_threads/headers: New.
* testsuite/30_threads/headers/mutex: New.
* testsuite/30_threads/headers/mutex/types_std_c++0x.cc: New.
* testsuite/30_threads/headers/mutex/std_c++0x_neg.cc: New.
* testsuite/30_threads/headers/condition_variable: New.
* testsuite/30_threads/headers/condition_variable/
types_std_c++0x.cc: New.
* testsuite/30_threads/headers/condition_variable/std_c++0x_neg.cc: New.
* testsuite/30_threads/once_flag: New.
* testsuite/30_threads/unique_lock: New.
* testsuite/30_threads/unique_lock/requirements: New.
* testsuite/30_threads/unique_lock/requirements/typedefs.cc: New.
* testsuite/30_threads/unique_lock/requirements/
explicit_instantiation.cc: New.
* testsuite/17_intro/headers/c++200x/all.cc: Add new includes.
2008-05-06 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36130

View File

@ -62,7 +62,10 @@ GLIBCXX_3.4 {
std::c[a-g]*;
# std::char_traits;
# std::c[i-z]*;
std::c[i-s]*;
std::c[i-n]*;
# std::condition_variable;
std::co[^n]*;
std::c[p-s]*;
std::c[u-z]*;
# std::[d-g]*;
std::d[a-d]*;
@ -832,6 +835,24 @@ GLIBCXX_3.4.11 {
atomic_flag_test_and_set_explicit;
atomic_global_fence_compatibility;
# mutex
_ZSt10adopt_lock;
_ZSt10defer_lock;
_ZSt11try_to_lock;
_ZTISt10lock_error;
_ZTVSt10lock_error;
_ZTSSt10lock_error;
_ZNKSt10lock_error4whatEv;
# condition_variable
_ZNSt18condition_variable10notify_allEv;
_ZNSt18condition_variable10notify_oneEv;
_ZNSt18condition_variableC1Ev;
_ZNSt18condition_variableC2Ev;
_ZNSt18condition_variableD1Ev;
_ZNSt18condition_variableD2Ev;
# system_error
_ZSt15system_category;
@ -847,6 +868,9 @@ GLIBCXX_3.4.11 {
_ZNKSt4hashISt10error_codeEclES0_;
_ZSt20__throw_system_errorPKc;
_ZSt20__throw_system_errori;
# date_time
_ZSt15get_system_timev;

View File

@ -34,6 +34,9 @@
/** @namespace std::placeholders
* @brief ISO C++ 0x entities sub namespace for functional.
*/
/** @namespace std::this_thread
* @brief ISO C++ 0x entities sub namespace for thread.
*/
/** @namespace __gnu_cxx
* @brief GNU extensions for public use.
*/

View File

@ -468,6 +468,7 @@ INPUT = @srcdir@/libsupc++/cxxabi.h \
include/algorithm \
include/array \
include/bitset \
include/condition_variable \
include/date_time \
include/deque \
include/fstream \
@ -483,6 +484,7 @@ INPUT = @srcdir@/libsupc++/cxxabi.h \
include/locale \
include/map \
include/memory \
include/mutex \
include/numeric \
include/ostream \
include/queue \
@ -495,6 +497,7 @@ INPUT = @srcdir@/libsupc++/cxxabi.h \
include/streambuf \
include/string \
include/system_error \
include/thread \
include/tuple \
include/type_traits \
include/unordered_map \
@ -516,6 +519,7 @@ INPUT = @srcdir@/libsupc++/cxxabi.h \
include/csetjmp \
include/csignal \
include/cstdarg \
include/cstdatomic \
include/cstdbool \
include/cstddef \
include/cstdint \
@ -1162,7 +1166,8 @@ INCLUDE_FILE_PATTERNS =
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.
PREDEFINED = __GTHREADS \
PREDEFINED = __cplusplus \
__GTHREADS \
"_GLIBCXX_STD_P= " \
"_GLIBCXX_STD_D= " \
_GLIBCXX_STD=std \

View File

@ -169,6 +169,7 @@
<row><entry><filename class="headerfile">exception</filename></entry><entry><filename class="headerfile">iterator</filename></entry><entry><filename class="headerfile">ostream</filename></entry><entry><filename class="headerfile">streambuf</filename></entry><entry><filename class="headerfile">utility</filename></entry></row>
<row><entry><filename class="headerfile">fstream</filename></entry><entry><filename class="headerfile">limits</filename></entry><entry><filename class="headerfile">queue</filename></entry><entry><filename class="headerfile">string</filename></entry><entry><filename class="headerfile">valarray</filename></entry></row>
<row><entry><filename class="headerfile">functional</filename></entry><entry><filename class="headerfile">list</filename></entry><entry><filename class="headerfile">random</filename></entry><entry><filename class="headerfile">system_error</filename></entry><entry><filename class="headerfile">vector</filename></entry></row>
<row><entry><filename class="headerfile">condition_variable</filename></entry><entry><filename class="headerfile">mutex</filename></entry><entry><filename class="headerfile">thread</filename></entry><entry></entry><entry></entry></row>
</tbody>
</tgroup>
</table>
@ -189,6 +190,7 @@
<row><entry><filename class="headerfile">cctype</filename></entry><entry><filename class="headerfile">ciso646</filename></entry><entry><filename class="headerfile">csignal</filename></entry><entry><filename class="headerfile">cstdio</filename></entry><entry><filename class="headerfile">cuchar</filename></entry></row>
<row><entry><filename class="headerfile">cerrno</filename></entry><entry><filename class="headerfile">climits</filename></entry><entry><filename class="headerfile">cstdarg</filename></entry><entry><filename class="headerfile">cstdlib</filename></entry><entry><filename class="headerfile">cwchar</filename></entry></row>
<row><entry><filename class="headerfile">cfenv</filename></entry><entry><filename class="headerfile">clocale</filename></entry><entry><filename class="headerfile">cstdbool</filename></entry><entry><filename class="headerfile">cstring</filename></entry><entry><filename class="headerfile">cwctype</filename></entry></row>
<row><entry><filename class="headerfile">cstdatomic</filename></entry><entry></entry><entry></entry><entry></entry><entry></entry></row>
</tbody>
</tgroup>
</table>

View File

@ -33,6 +33,7 @@ std_headers = \
${std_srcdir}/bitset \
${std_srcdir}/c++0x_warning.h \
${std_srcdir}/complex \
${std_srcdir}/condition_variable \
${std_srcdir}/date_time \
${std_srcdir}/deque \
${std_srcdir}/fstream \
@ -48,6 +49,7 @@ std_headers = \
${std_srcdir}/locale \
${std_srcdir}/map \
${std_srcdir}/memory \
${std_srcdir}/mutex \
${std_srcdir}/numeric \
${std_srcdir}/ostream \
${std_srcdir}/queue \

View File

@ -286,6 +286,7 @@ std_headers = \
${std_srcdir}/bitset \
${std_srcdir}/c++0x_warning.h \
${std_srcdir}/complex \
${std_srcdir}/condition_variable \
${std_srcdir}/date_time \
${std_srcdir}/deque \
${std_srcdir}/fstream \
@ -301,6 +302,7 @@ std_headers = \
${std_srcdir}/locale \
${std_srcdir}/map \
${std_srcdir}/memory \
${std_srcdir}/mutex \
${std_srcdir}/numeric \
${std_srcdir}/ostream \
${std_srcdir}/queue \

View File

@ -1,6 +1,6 @@
// Function-Based Exception Support -*- C++ -*-
// Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc.
// Copyright (C) 2001, 2004, 2005, 2008 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
@ -86,6 +86,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
void
__throw_underflow_error(const char*) __attribute__((__noreturn__));
void
__throw_system_error(const char*) __attribute__((__noreturn__));
void
__throw_system_error(int) __attribute__((__noreturn__));
// Helpers for exception objects in basic_ios
void
__throw_ios_failure(const char*) __attribute__((__noreturn__));

View File

@ -0,0 +1,162 @@
// <condition_variable> -*- C++ -*-
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/** @file condition_variable
* This is a Standard C++ Library header.
*/
#ifndef _GLIBCXX_CONDITION_VARIABLE
#define _GLIBCXX_CONDITION_VARIABLE 1
#pragma GCC system_header
#ifndef __GXX_EXPERIMENTAL_CXX0X__
# include <c++0x_warning.h>
#endif
#include <mutex> // unique_lock
namespace std
{
// XXX
class system_time;
/// condition_variable
class condition_variable
{
public:
#if __GTHREAD_HAS_COND
typedef __gthread_cond_t native_handle_type;
#else
typedef int native_handle_type;
#endif
condition_variable();
~condition_variable();
void
notify_one();
void
notify_all();
void
wait(unique_lock<mutex>& __lock);
template<typename _Predicate>
void
wait(unique_lock<mutex>& __lock, _Predicate __p)
{
while (!__p())
wait(__lock);
}
template<typename _Duration>
bool
timed_wait(unique_lock<mutex>& __lock, const _Duration& __rtime);
bool
timed_wait(unique_lock<mutex>& __lock, const system_time& __atime);
template<typename _Predicate>
bool
timed_wait(unique_lock<mutex>& __lock, const system_time& __atime,
_Predicate pred);
template<typename _Duration, typename _Predicate>
bool
timed_wait(unique_lock<mutex>& __lock, const _Duration& __rtime,
_Predicate pred);
native_handle_type
native_handle() { return _M_cond; }
private:
native_handle_type _M_cond;
condition_variable(const condition_variable&);
condition_variable& operator=(const condition_variable&);
};
/// condition_variable_any
// Like above, only mutex may not have try_lock.
class condition_variable_any
{
public:
#if __GTHREAD_HAS_COND
typedef __gthread_cond_t native_handle_type;
#else
typedef int native_handle_type;
#endif
condition_variable_any();
~condition_variable_any();
void
notify_one();
void
notify_all();
template<typename _Lock>
void
wait(_Lock& __lock);
template<typename _Lock, typename _Predicate>
void
wait(_Lock& __lock, _Predicate __p);
template<typename _Lock>
bool
timed_wait(_Lock& __lock, const system_time& __atime);
template<typename _Lock, typename _Duration>
bool
timed_wait(_Lock& __lock, const _Duration& __rtime);
template<typename _Lock, typename _Predicate>
bool
timed_wait(_Lock& __lock, const system_time& __atime, _Predicate __p);
template<typename _Lock, typename _Duration, typename _Predicate>
bool
timed_wait(_Lock& __lock, const _Duration& __rtime, _Predicate __p);
native_handle_type
native_handle() { return _M_cond; }
private:
native_handle_type _M_cond;
condition_variable_any(const condition_variable_any&);
condition_variable_any& operator=(const condition_variable_any&);
};
}
#endif

View File

@ -0,0 +1,385 @@
// <mutex> -*- C++ -*-
// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
// 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 2, 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 COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/** @file mutex
* This is a Standard C++ Library header.
*/
#ifndef _GLIBCXX_MUTEX
#define _GLIBCXX_MUTEX 1
#pragma GCC system_header
#ifndef __GXX_EXPERIMENTAL_CXX0X__
# include <c++0x_warning.h>
#endif
#include <exception>
#include <cstddef>
#include <bits/functexcept.h>
#include <bits/gthr.h>
namespace std
{
// XXX
class system_time;
/// mutex
class mutex
{
public:
typedef __gthread_mutex_t native_handle_type;
mutex()
{
#if defined __GTHREAD_MUTEX_INIT
native_handle_type __tmp = __GTHREAD_MUTEX_INIT;
_M_mutex = __tmp;
#else
int __e = __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex);
// EAGAIN, ENOMEM, EPERM, EBUSY(may), EINVAL(may)
if ( __e)
__throw_system_error(__e);
#endif
}
void
lock()
{
int __e = __gthread_mutex_lock(&_M_mutex);
// EINVAL, EAGAIN, EBUSY, EINVAL, EDEADLK(may)
if ( __e)
__throw_system_error(__e);
}
bool
try_lock()
{
int __e = __gthread_mutex_trylock(&_M_mutex);
// EINVAL, EAGAIN, EBUSY
if ( __e)
__throw_system_error(__e);
else
return true;
}
void
unlock()
{
int __e = __gthread_mutex_unlock(&_M_mutex);
// EINVAL, EAGAIN, EPERM
if ( __e)
__throw_system_error(__e);
}
native_handle_type
native_handle()
{ return _M_mutex; }
private:
native_handle_type _M_mutex;
mutex(const mutex&);
mutex& operator=(const mutex&);
};
/// recursive_mutex
class recursive_mutex
{
public:
typedef __gthread_recursive_mutex_t native_handle_type;
recursive_mutex()
{
#if defined __GTHREAD_RECURSIVE_MUTEX_INIT
native_handle_type __tmp = __GTHREAD_RECURSIVE_MUTEX_INIT;
_M_mutex = __tmp;
#else
int __e = __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION(&_M_mutex);
// EAGAIN, ENOMEM, EPERM, EBUSY(may), EINVAL(may)
if ( __e)
__throw_system_error(__e);
#endif
}
void
lock()
{
int __e = __gthread_recursive_mutex_lock(&_M_mutex);
// EINVAL, EAGAIN, EBUSY, EINVAL, EDEADLK(may)
if ( __e)
__throw_system_error(__e);
}
bool
try_lock()
{
int __e = __gthread_recursive_mutex_trylock(&_M_mutex);
// EINVAL, EAGAIN, EBUSY
if ( __e)
__throw_system_error(__e);
else
return true;
}
void
unlock()
{
int __e = __gthread_recursive_mutex_unlock(&_M_mutex);
// EINVAL, EAGAIN, EBUSY
if ( __e)
__throw_system_error(__e);
}
native_handle_type
native_handle() { return _M_mutex; }
private:
native_handle_type _M_mutex;
recursive_mutex(const recursive_mutex&);
recursive_mutex& operator=(const recursive_mutex&);
};
// class timed_mutex;
// class recursive_timed_mutex;
/// Do not acquire ownership of the mutex.
struct defer_lock_t { };
/// Try to acquire ownership of the mutex without blocking.
struct try_to_lock_t { };
/// Assume the calling thread has already obtained mutex ownership
/// and manage it.
struct adopt_lock_t { };
extern const defer_lock_t defer_lock;
extern const try_to_lock_t try_to_lock;
extern const adopt_lock_t adopt_lock;
/// Thrown to indicate errors with lock operations.
class lock_error : public exception
{
public:
virtual const char*
what() const throw();
};
/// @brief Scoped lock idiom.
// Acquire the mutex here with a constructor call, then release with
// the destructor call in accordance with RAII style.
template<typename _Mutex>
class lock_guard
{
public:
typedef _Mutex mutex_type;
explicit lock_guard(mutex_type& __m) : _M_device(__m)
{ _M_device.lock(); }
lock_guard(mutex_type& __m, adopt_lock_t __a) : _M_device(__m)
{ _M_device.lock(); }
~lock_guard()
{ _M_device.unlock(); }
private:
mutex_type& _M_device;
lock_guard(lock_guard const&);
lock_guard& operator=(lock_guard const&);
};
/// unique_lock
template<typename _Mutex>
class unique_lock
{
public:
typedef _Mutex mutex_type;
unique_lock() : _M_device(NULL), _M_owns(false) { }
explicit unique_lock(mutex_type& __m) : _M_device(&__m)
{
lock();
_M_owns = true;
}
unique_lock(mutex_type& __m, defer_lock_t)
: _M_device(&__m), _M_owns(false) { }
unique_lock(mutex_type& __m, try_to_lock_t)
: _M_device(&__m), _M_owns(_M_device->try_lock()) { }
unique_lock(mutex_type& __m, adopt_lock_t)
: _M_device(&__m), _M_owns(true)
{
// XXX calling thread owns mutex
}
unique_lock(mutex_type& __m, const system_time& abs_time);
template<typename _Duration>
unique_lock(mutex_type& __m, const _Duration& rel_time);
~unique_lock()
{
if (_M_owns)
unlock();
}
unique_lock(unique_lock&&);
unique_lock& operator=(unique_lock&&);
void
lock()
{
if (_M_device && !_M_owns)
_M_device->lock();
else
throw lock_error();
}
bool
try_lock()
{
bool __ret = false;
if (_M_device && !_M_owns)
__ret = _M_device->try_lock();
else
throw lock_error();
return __ret;
}
void
unlock()
{
if (_M_device && _M_owns)
_M_device->unlock();
else
throw lock_error();
}
template<typename _Duration>
bool timed_lock(const _Duration& rel_time);
bool
timed_lock(const system_time& abs_time);
void
swap(unique_lock&& __u);
mutex_type*
release()
{
mutex_type* __ret = _M_device;
_M_device = NULL;
_M_owns = false;
return __ret;
}
bool
owns_lock() const { return _M_owns; }
operator bool () const { return owns_lock(); }
mutex_type*
mutex() const
{ return _M_device; }
private:
unique_lock(unique_lock const&);
unique_lock& operator=(unique_lock const&);
mutex_type* _M_device;
bool _M_owns; // XXX use atomic_bool
};
template<typename _Mutex>
void
swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y);
template<typename _Mutex>
void
swap(unique_lock<_Mutex>&& __x, unique_lock<_Mutex>& __y);
template<typename _Mutex>
void
swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>&& __y);
template<typename _L1, typename _L2, typename ..._L3>
int
try_lock(_L1&, _L2&, _L3&...);
template<typename _L1, typename _L2, typename ..._L3>
void
lock(_L1&, _L2&, _L3&...);
/// once_flag
struct once_flag
{
typedef __gthread_once_t __native_type;
once_flag() : _M_once(__GTHREAD_ONCE_INIT) { }
__native_type&
_M_get() { return _M_once; }
private:
__native_type _M_once;
once_flag(const once_flag&);
once_flag& operator=(const once_flag&);
};
template<typename _Callable, typename... _Args>
void
call_once(once_flag& __once, _Callable __f, _Args&&... __args)
{
int __e = __gthread_once(&(__once._M_get()), __f(__args...));
if ( __e)
__throw_system_error(__e);
}
}
#endif

View File

@ -183,6 +183,8 @@ sources = \
valarray-inst.cc \
wlocale-inst.cc \
wstring-inst.cc \
mutex.cc \
condition_variable.cc \
${host_sources} \
${host_sources_extra}
@ -229,11 +231,26 @@ parallel_settings.o: parallel_settings.cc
$(CXXCOMPILE) $(PARALLEL_FLAGS) -c $<
# Use special rules for the C++0x sources so that the proper flags are passed.
functexcept.lo: functexcept.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
functexcept.o: functexcept.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
system_error.lo: system_error.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
system_error.o: system_error.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
mutex.lo: mutex.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
mutex.o: mutex.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
condition_variable.lo: condition_variable.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
condition_variable.o: condition_variable.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
hash_c++0x.lo: hash_c++0x.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
hash_c++0x.o: hash_c++0x.cc

View File

@ -84,11 +84,11 @@ am__libstdc___la_SOURCES_DIST = atomic.cc bitmap_allocator.cc \
iostream-inst.cc istream-inst.cc istream.cc locale-inst.cc \
misc-inst.cc ostream-inst.cc sstream-inst.cc streambuf-inst.cc \
streambuf.cc string-inst.cc valarray-inst.cc wlocale-inst.cc \
wstring-inst.cc atomicity.cc codecvt_members.cc \
collate_members.cc ctype_members.cc messages_members.cc \
monetary_members.cc numeric_members.cc time_members.cc \
basic_file.cc c++locale.cc compatibility-ldbl.cc \
parallel_list.cc parallel_settings.cc
wstring-inst.cc mutex.cc condition_variable.cc atomicity.cc \
codecvt_members.cc collate_members.cc ctype_members.cc \
messages_members.cc monetary_members.cc numeric_members.cc \
time_members.cc basic_file.cc c++locale.cc \
compatibility-ldbl.cc parallel_list.cc parallel_settings.cc
am__objects_1 = atomicity.lo codecvt_members.lo collate_members.lo \
ctype_members.lo messages_members.lo monetary_members.lo \
numeric_members.lo time_members.lo
@ -109,7 +109,8 @@ am__objects_5 = atomic.lo bitmap_allocator.lo pool_allocator.lo \
istream-inst.lo istream.lo locale-inst.lo misc-inst.lo \
ostream-inst.lo sstream-inst.lo streambuf-inst.lo streambuf.lo \
string-inst.lo valarray-inst.lo wlocale-inst.lo \
wstring-inst.lo $(am__objects_1) $(am__objects_4)
wstring-inst.lo mutex.lo condition_variable.lo \
$(am__objects_1) $(am__objects_4)
am_libstdc___la_OBJECTS = $(am__objects_5)
libstdc___la_OBJECTS = $(am_libstdc___la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
@ -419,6 +420,8 @@ sources = \
valarray-inst.cc \
wlocale-inst.cc \
wstring-inst.cc \
mutex.cc \
condition_variable.cc \
${host_sources} \
${host_sources_extra}
@ -823,11 +826,26 @@ parallel_settings.o: parallel_settings.cc
$(CXXCOMPILE) $(PARALLEL_FLAGS) -c $<
# Use special rules for the C++0x sources so that the proper flags are passed.
functexcept.lo: functexcept.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
functexcept.o: functexcept.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
system_error.lo: system_error.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
system_error.o: system_error.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
mutex.lo: mutex.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
mutex.o: mutex.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
condition_variable.lo: condition_variable.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
condition_variable.o: condition_variable.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
hash_c++0x.lo: hash_c++0x.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
hash_c++0x.o: hash_c++0x.cc

View File

@ -0,0 +1,84 @@
// mutex -*- C++ -*-
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <condition_variable>
namespace std
{
condition_variable::condition_variable()
{
#if __GTHREAD_HAS_COND
# if defined __GTHREAD_COND_INIT
native_handle_type __tmp = __GTHREAD_COND_INIT;
_M_cond = __tmp;
# else
int __e = __gthread_cond_init(&_M_cond, NULL);
if ( __e)
__throw_system_error(__e);
# endif
#endif
}
condition_variable::~condition_variable()
{
#if __GTHREAD_HAS_COND
// XXX no thread blocked
int __e = pthread_cond_destroy(&_M_cond);
// if __e == EBUSY then blocked
#endif
}
void
condition_variable::notify_one()
{
#if __GTHREAD_HAS_COND
int __e = pthread_cond_signal(&_M_cond);
// XXX not in spec
// EINVAL
if ( __e)
__throw_system_error(__e);
#endif
}
void
condition_variable::notify_all()
{
#if __GTHREAD_HAS_COND
int __e = pthread_cond_broadcast(&_M_cond);
// XXX not in spec
// EINVAL
if ( __e)
__throw_system_error(__e);
#endif
}
}

View File

@ -29,6 +29,7 @@
#include <cstdlib>
#include <exception>
#include <stdexcept>
#include <system_error>
#include <new>
#include <typeinfo>
#include <ios>
@ -95,6 +96,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__throw_underflow_error(const char* __s)
{ throw underflow_error(_(__s)); }
void
__throw_system_error(const char* __s)
{ throw system_error(_(__s)); }
void
__throw_system_error(int __i)
{ throw system_error(error_code(__i, system_category)); }
void
__throw_ios_failure(const char* __s)
{ throw ios_base::failure(_(__s)); }
@ -151,6 +160,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__throw_underflow_error(const char*)
{ std::abort(); }
void
__throw_system_error(const char* __s)
{ std::abort(); }
void
__throw_system_error(int __i)
{ std::abort(); }
void
__throw_ios_failure(const char*)
{ std::abort(); }

42
libstdc++-v3/src/mutex.cc Normal file
View File

@ -0,0 +1,42 @@
// mutex -*- C++ -*-
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
namespace std
{
const defer_lock_t defer_lock = defer_lock_t();
const try_to_lock_t try_to_lock = try_to_lock_t();
const adopt_lock_t adopt_lock = adopt_lock_t();
const char*
lock_error::what() const throw()
{ return "std::lock_error"; }
}

View File

@ -95,6 +95,7 @@
#include <algorithm>
#include <array>
#include <bitset>
#include <condition_variable>
#include <complex>
#include <date_time>
#include <deque>
@ -112,6 +113,7 @@
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>

View File

@ -0,0 +1,27 @@
// { dg-do compile }
// { dg-options "-std=gnu++98" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <condition_variable> // { dg-excess-errors "In file included from" }
// { dg-error "upcoming ISO" "" { target *-*-* } 36 }

View File

@ -0,0 +1,28 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <condition_variable>
void test01()
{
typedef std::condition_variable c_t;
typedef std::condition_variable_any ca_t;
}

View File

@ -0,0 +1,27 @@
// { dg-do compile }
// { dg-options "-std=gnu++98" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <mutex> // { dg-excess-errors "In file included from" }
// { dg-error "upcoming ISO" "" { target *-*-* } 36 }

View File

@ -0,0 +1,40 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <mutex>
void test01()
{
typedef std::mutex mutext_t;
typedef std::recursive_mutex rmutext_t;
typedef std::defer_lock_t dl_t;
typedef std::try_to_lock_t ttl_t;
typedef std::adopt_lock_t al_t;
using std::defer_lock;
using std::try_to_lock;
using std::adopt_lock;
typedef std::lock_error error_t;
typedef std::once_flag once_t;
}

View File

@ -0,0 +1,39 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// 2008-03-14 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// NB: This file is for testing with NO OTHER INCLUDES.
#include <mutex>
namespace std
{
template class lock_guard<mutex>;
}

View File

@ -0,0 +1,41 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// 2008-03-14 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// NB: This file is for testing with NO OTHER INCLUDES.
#include <mutex>
void test01()
{
// Check for required typedefs
typedef std::lock_guard<std::mutex> test_type;
typedef test_type::mutex_type mutex_type;
}

View File

@ -0,0 +1,53 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
typedef std::mutex mutex_type;
try
{
mutex_type m1;
}
catch (const std::system_error& e)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,42 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
void test01()
{
// assign
typedef std::mutex mutex_type;
mutex_type m1;
mutex_type m2;
m1 = m2;
}
// { dg-error "within this context" "" { target *-*-* } 39 }
// { dg-error "is private" "" { target *-*-* } 113 }

View File

@ -0,0 +1,41 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
void test01()
{
// assign
typedef std::mutex mutex_type;
mutex_type m1;
mutex_type m2(m1);
}
// { dg-error "within this context" "" { target *-*-* } 38 }
// { dg-error "is private" "" { target *-*-* } 112 }

View File

@ -0,0 +1,55 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
typedef std::mutex mutex_type;
try
{
mutex_type m;
m.lock();
}
catch (const std::system_error& e)
{
// Destroying locked mutex raises system error, or undefined.
// POSIX == may fail with EBUSY.
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,67 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
typedef std::mutex mutex_type;
try
{
mutex_type m;
m.lock();
// Lock already locked mutex, should be ok.
// XXX
try
{
m.lock();
}
catch (const std::system_error& e)
{
VERIFY( false );
}
m.unlock();
}
catch (const std::system_error& e)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,54 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
typedef std::mutex mutex_type;
try
{
mutex_type m;
mutex_type::native_handle_type n = m.native_handle();
}
catch (const std::system_error& e)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,39 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// 2008-03-18 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
void test01()
{
// Check for required typedefs
typedef std::mutex test_type;
typedef test_type::native_handle_type type;
}

View File

@ -0,0 +1,56 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
typedef std::mutex mutex_type;
try
{
mutex_type m;
bool b = m.try_lock();
VERIFY( b );
m.unlock();
}
catch (const std::system_error& e)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,67 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
typedef std::mutex mutex_type;
try
{
mutex_type m;
m.lock();
bool b;
try
{
b = m.try_lock();
VERIFY( b );
}
catch (const std::system_error& e)
{
VERIFY( false );
}
m.unlock();
}
catch (const std::system_error& e)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,56 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
typedef std::mutex mutex_type;
try
{
// Unlock mutex that hasn't been locked.
mutex_type m;
m.unlock();
}
catch (const std::system_error& e)
{
// POSIX == EPERM
VERIFY( true );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,53 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
typedef std::recursive_mutex mutex_type;
try
{
mutex_type m1;
}
catch (const std::system_error& e)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,42 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
void test01()
{
// assign
typedef std::recursive_mutex mutex_type;
mutex_type m1;
mutex_type m2;
m1 = m2;
}
// { dg-error "within this context" "" { target *-*-* } 39 }
// { dg-error "is private" "" { target *-*-* } 177 }

View File

@ -0,0 +1,41 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
void test01()
{
// assign
typedef std::recursive_mutex mutex_type;
mutex_type m1;
mutex_type m2(m1);
}
// { dg-error "within this context" "" { target *-*-* } 38 }
// { dg-error "is private" "" { target *-*-* } 176 }

View File

@ -0,0 +1,55 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
typedef std::recursive_mutex mutex_type;
try
{
mutex_type m;
m.lock();
}
catch (const std::system_error& e)
{
// Destroying locked mutex raises system error, or undefined.
// POSIX == may fail with EBUSY.
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,54 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
#include <system_error>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
typedef std::recursive_mutex mutex_type;
try
{
mutex_type m;
mutex_type::native_handle_type n = m.native_handle();
}
catch (const std::system_error& e)
{
VERIFY( false );
}
catch (...)
{
VERIFY( false );
}
return 0;
}

View File

@ -0,0 +1,39 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// 2008-03-18 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <mutex>
void test01()
{
// Check for required typedefs
typedef std::recursive_mutex test_type;
typedef test_type::native_handle_type type;
}

View File

@ -0,0 +1,39 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// 2008-03-14 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// NB: This file is for testing with NO OTHER INCLUDES.
#include <mutex>
namespace std
{
template class unique_lock<mutex>;
}

View File

@ -0,0 +1,41 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// 2008-03-14 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// NB: This file is for testing with NO OTHER INCLUDES.
#include <mutex>
void test01()
{
// Check for required typedefs
typedef std::unique_lock<std::mutex> test_type;
typedef test_type::mutex_type mutex_type;
}