From 4db6bc0f6ea65d3de4d17002c6284cb0bc2909aa Mon Sep 17 00:00:00 2001
From: Benjamin Kosnik <bkoz@redhat.com>
Date: Wed, 7 May 2008 00:55:51 +0000
Subject: [PATCH] mutex (mutex::mutex): Fix usage of initializing macro.

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

	* include/std/mutex (mutex::mutex): Fix usage of initializing macro.
	(recursive_mutex::recursive_mutex): Same.
	(once_flag::once_flag): Same.
	* testsuite/30_threads/mutex/cons/assign_neg.cc: Fix line numbers.
	* testsuite/30_threads/mutex/cons/copy_neg.cc: Same.
	* testsuite/30_threads/recursive_mutex/cons/assign_neg.cc: Same.
	* testsuite/30_threads/recursive_mutex/cons/copy_neg.cc: Same.

From-SVN: r135015
---
 libstdc++-v3/ChangeLog                        |  10 ++
 libstdc++-v3/include/std/mutex                | 152 +++++++++---------
 .../30_threads/mutex/cons/assign_neg.cc       |   2 +-
 .../30_threads/mutex/cons/copy_neg.cc         |   2 +-
 .../recursive_mutex/cons/assign_neg.cc        |   2 +-
 .../recursive_mutex/cons/copy_neg.cc          |   2 +-
 6 files changed, 90 insertions(+), 80 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 456be98f38d2..ecba4a379a9a 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,13 @@
+2008-05-06  Benjamin Kosnik  <bkoz@redhat.com>
+
+	* include/std/mutex (mutex::mutex): Fix usage of initializing macro.
+	(recursive_mutex::recursive_mutex): Same.
+	(once_flag::once_flag): Same.
+	* testsuite/30_threads/mutex/cons/assign_neg.cc: Fix line numbers.
+	* testsuite/30_threads/mutex/cons/copy_neg.cc: Same.
+	* testsuite/30_threads/recursive_mutex/cons/assign_neg.cc: Same.
+	* testsuite/30_threads/recursive_mutex/cons/copy_neg.cc: Same.
+	
 2008-05-06  Benjamin Kosnik  <bkoz@redhat.com>
 
 	* include/std/condition_variable: New.
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index 57e817fcc794..935b16e57c29 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -1,6 +1,6 @@
 // <mutex> -*- C++ -*-
 
-// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 
+// 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
@@ -44,9 +44,9 @@
 #include <exception>
 #include <cstddef>
 #include <bits/functexcept.h>
-#include <bits/gthr.h> 
+#include <bits/gthr.h>
 
-namespace std 
+namespace std
 {
   // XXX
   class system_time;
@@ -63,47 +63,45 @@ namespace std
       native_handle_type __tmp = __GTHREAD_MUTEX_INIT;
       _M_mutex = __tmp;
 #else
-      int __e = __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex); 
+      __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex);
+#endif
 
       // EAGAIN, ENOMEM, EPERM, EBUSY(may), EINVAL(may)
-      if ( __e)
-       __throw_system_error(__e);      
-#endif
     }
 
-    void 
+    void
     lock()
     {
       int __e = __gthread_mutex_lock(&_M_mutex);
 
       // EINVAL, EAGAIN, EBUSY, EINVAL, EDEADLK(may)
-     if ( __e)
+     if (__e)
        __throw_system_error(__e);
     }
- 
-    bool 
+
+    bool
     try_lock()
     {
       int __e = __gthread_mutex_trylock(&_M_mutex);
 
       // EINVAL, EAGAIN, EBUSY
-     if ( __e)
+     if (__e)
        __throw_system_error(__e);
      else
        return true;
     }
 
-    void 
+    void
     unlock()
     {
       int __e = __gthread_mutex_unlock(&_M_mutex);
 
       // EINVAL, EAGAIN, EPERM
-     if ( __e)
+     if (__e)
        __throw_system_error(__e);
     }
 
-    native_handle_type 
+    native_handle_type
     native_handle()
     { return _M_mutex; }
 
@@ -121,53 +119,51 @@ namespace std
     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);
+      __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION(&_M_mutex);
+#endif
 
       // EAGAIN, ENOMEM, EPERM, EBUSY(may), EINVAL(may)
-      if ( __e)
-       __throw_system_error(__e);      
-#endif
     }
 
 
-    void 
+    void
     lock()
-    { 
+    {
       int __e = __gthread_recursive_mutex_lock(&_M_mutex);
 
       // EINVAL, EAGAIN, EBUSY, EINVAL, EDEADLK(may)
-     if ( __e)
+     if (__e)
        __throw_system_error(__e);
     }
-  
-    bool 
+
+    bool
     try_lock()
     {
       int __e = __gthread_recursive_mutex_trylock(&_M_mutex);
 
       // EINVAL, EAGAIN, EBUSY
-     if ( __e)
+     if (__e)
        __throw_system_error(__e);
      else
        return true;
     }
 
-    void 
+    void
     unlock()
-    { 
+    {
       int __e = __gthread_recursive_mutex_unlock(&_M_mutex);
 
       // EINVAL, EAGAIN, EBUSY
-     if ( __e)
+     if (__e)
        __throw_system_error(__e);
     }
 
-    native_handle_type 
+    native_handle_type
     native_handle() { return _M_mutex; }
 
   private:
@@ -191,22 +187,22 @@ namespace std
   /// 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;
+  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* 
+    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> 
+  template<typename _Mutex>
     class lock_guard
     {
     public:
@@ -228,7 +224,7 @@ namespace std
     };
 
   /// unique_lock
-  template<typename _Mutex> 
+  template<typename _Mutex>
     class unique_lock
     {
     public:
@@ -237,18 +233,18 @@ namespace std
       unique_lock() : _M_device(NULL), _M_owns(false) { }
 
       explicit unique_lock(mutex_type& __m) : _M_device(&__m)
-      { 
-	lock(); 
+      {
+	lock();
 	_M_owns = true;
       }
-      
-      unique_lock(mutex_type& __m, defer_lock_t) 
+
+      unique_lock(mutex_type& __m, defer_lock_t)
       : _M_device(&__m), _M_owns(false) { }
 
-      unique_lock(mutex_type& __m, try_to_lock_t) 
+      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) 
+      unique_lock(mutex_type& __m, adopt_lock_t)
       : _M_device(&__m), _M_owns(true)
       {
 	// XXX calling thread owns mutex
@@ -257,7 +253,7 @@ namespace std
       unique_lock(mutex_type& __m, const system_time& abs_time);
 
       template<typename _Duration>
-        unique_lock(mutex_type& __m, const _Duration& rel_time);
+	unique_lock(mutex_type& __m, const _Duration& rel_time);
 
       ~unique_lock()
       {
@@ -270,60 +266,60 @@ namespace std
       unique_lock& operator=(unique_lock&&);
 
 
-      void 
+      void
       lock()
-      { 
+      {
 	if (_M_device && !_M_owns)
-	  _M_device->lock(); 
+	  _M_device->lock();
 	else
 	  throw lock_error();
       }
 
-      bool 
+      bool
       try_lock()
-      { 
+      {
 	bool __ret = false;
 	if (_M_device && !_M_owns)
-	  __ret = _M_device->try_lock(); 
+	  __ret = _M_device->try_lock();
 	else
 	  throw lock_error();
 	return __ret;
       }
 
-      void 
+      void
       unlock()
-      { 
+      {
 	if (_M_device && _M_owns)
-	  _M_device->unlock(); 
+	  _M_device->unlock();
 	else
 	  throw lock_error();
       }
 
 
       template<typename _Duration>
-        bool timed_lock(const _Duration& rel_time);
+	bool timed_lock(const _Duration& rel_time);
 
-      bool 
+      bool
       timed_lock(const system_time& abs_time);
 
-      void 
+      void
       swap(unique_lock&& __u);
 
-      mutex_type* 
-      release() 
-      { 
-	mutex_type* __ret = _M_device; 
+      mutex_type*
+      release()
+      {
+	mutex_type* __ret = _M_device;
 	_M_device = NULL;
 	_M_owns = false;
 	return __ret;
       }
 
-      bool 
+      bool
       owns_lock() const { return _M_owns; }
 
       operator bool () const { return owns_lock(); }
 
-      mutex_type* 
+      mutex_type*
       mutex() const
       { return _M_device; }
 
@@ -331,36 +327,40 @@ namespace std
       unique_lock(unique_lock const&);
       unique_lock& operator=(unique_lock const&);
 
-      mutex_type* 	_M_device;
-      bool 		_M_owns; // XXX use atomic_bool
+      mutex_type*	_M_device;
+      bool		_M_owns; // XXX use atomic_bool
     };
 
   template<typename _Mutex>
-    void 
+    void
     swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y);
 
   template<typename _Mutex>
-    void 
+    void
     swap(unique_lock<_Mutex>&& __x, unique_lock<_Mutex>& __y);
 
   template<typename _Mutex>
-    void 
+    void
     swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>&& __y);
 
-  template<typename _L1, typename _L2, typename ..._L3> 
-    int 
+  template<typename _L1, typename _L2, typename ..._L3>
+    int
     try_lock(_L1&, _L2&, _L3&...);
 
-  template<typename _L1, typename _L2, typename ..._L3> 
-    void 
+  template<typename _L1, typename _L2, typename ..._L3>
+    void
     lock(_L1&, _L2&, _L3&...);
 
   /// once_flag
-  struct once_flag 
+  struct once_flag
   {
     typedef __gthread_once_t __native_type;
 
-    once_flag() : _M_once(__GTHREAD_ONCE_INIT) { }
+    once_flag()
+    {
+      __native_type __tmp = __GTHREAD_ONCE_INIT;
+      _M_once = __tmp;
+    }
 
     __native_type&
     _M_get() { return _M_once; }
@@ -372,11 +372,11 @@ namespace std
   };
 
   template<typename _Callable, typename... _Args>
-    void 
+    void
     call_once(once_flag& __once, _Callable __f, _Args&&... __args)
     {
-      int __e = __gthread_once(&(__once._M_get()), __f(__args...)); 
-      if ( __e)
+      int __e = __gthread_once(&(__once._M_get()), __f(__args...));
+      if (__e)
 	__throw_system_error(__e);
     }
 }
diff --git a/libstdc++-v3/testsuite/30_threads/mutex/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/mutex/cons/assign_neg.cc
index 650dc967195c..8a4d413c5869 100644
--- a/libstdc++-v3/testsuite/30_threads/mutex/cons/assign_neg.cc
+++ b/libstdc++-v3/testsuite/30_threads/mutex/cons/assign_neg.cc
@@ -39,4 +39,4 @@ void test01()
   m1 = m2;
 }
 // { dg-error "within this context" "" { target *-*-* } 39 } 
-// { dg-error "is private" "" { target *-*-* } 113 } 
+// { dg-error "is private" "" { target *-*-* } 111 } 
diff --git a/libstdc++-v3/testsuite/30_threads/mutex/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/mutex/cons/copy_neg.cc
index 82d5e5eb4e77..76bc7614391f 100644
--- a/libstdc++-v3/testsuite/30_threads/mutex/cons/copy_neg.cc
+++ b/libstdc++-v3/testsuite/30_threads/mutex/cons/copy_neg.cc
@@ -38,4 +38,4 @@ void test01()
   mutex_type m2(m1);
 }
 // { dg-error "within this context" "" { target *-*-* } 38 } 
-// { dg-error "is private" "" { target *-*-* } 112 } 
+// { dg-error "is private" "" { target *-*-* } 110 } 
diff --git a/libstdc++-v3/testsuite/30_threads/recursive_mutex/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/recursive_mutex/cons/assign_neg.cc
index 5d83a708e584..54877e427e19 100644
--- a/libstdc++-v3/testsuite/30_threads/recursive_mutex/cons/assign_neg.cc
+++ b/libstdc++-v3/testsuite/30_threads/recursive_mutex/cons/assign_neg.cc
@@ -39,4 +39,4 @@ void test01()
   m1 = m2;
 }
 // { dg-error "within this context" "" { target *-*-* } 39 } 
-// { dg-error "is private" "" { target *-*-* } 177 } 
+// { dg-error "is private" "" { target *-*-* } 173 } 
diff --git a/libstdc++-v3/testsuite/30_threads/recursive_mutex/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/recursive_mutex/cons/copy_neg.cc
index b0d0b9d4a1ad..80a38b3e6eb7 100644
--- a/libstdc++-v3/testsuite/30_threads/recursive_mutex/cons/copy_neg.cc
+++ b/libstdc++-v3/testsuite/30_threads/recursive_mutex/cons/copy_neg.cc
@@ -38,4 +38,4 @@ void test01()
   mutex_type m2(m1);
 }
 // { dg-error "within this context" "" { target *-*-* } 38 } 
-// { dg-error "is private" "" { target *-*-* } 176 } 
+// { dg-error "is private" "" { target *-*-* } 172 } 
-- 
GitLab