OSDN Git Service

2010-02-25 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / mutex
index bdd5193..7a1e259 100644 (file)
@@ -1,12 +1,12 @@
 // <mutex> -*- C++ -*-
 
-// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
 // terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
+// 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,
 // 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.
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
 
-// 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.
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
 
 /** @file mutex
  *  This is a Standard C++ Library header.
@@ -38,7 +33,7 @@
 #pragma GCC system_header
 
 #ifndef __GXX_EXPERIMENTAL_CXX0X__
-# include <c++0x_warning.h>
+# include <bits/c++0x_warning.h>
 #else
 
 #include <tuple>
 
 namespace std
 {
+  /**
+   * @defgroup mutexes Mutexes
+   * @ingroup concurrency
+   *
+   * Classes for mutex support.
+   * @{
+   */
+
   /// mutex
   class mutex
   {
@@ -383,14 +386,6 @@ namespace std
   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.
@@ -560,7 +555,7 @@ namespace std
       }
 
       void
-      swap(unique_lock&& __u)
+      swap(unique_lock& __u)
       {
        std::swap(_M_device, __u._M_device);
        std::swap(_M_owns, __u._M_owns);
@@ -579,7 +574,7 @@ namespace std
       owns_lock() const
       { return _M_owns; }
 
-      /* explicit */ operator bool () const
+      explicit operator bool() const
       { return owns_lock(); }
 
       mutex_type*
@@ -596,16 +591,6 @@ namespace std
     swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y)
     { __x.swap(__y); }
 
-  template<typename _Mutex>
-    inline void
-    swap(unique_lock<_Mutex>&& __x, unique_lock<_Mutex>& __y)
-    { __x.swap(__y); }
-
-  template<typename _Mutex>
-    inline void
-    swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>&& __y)
-    { __x.swap(__y); }
-
   template<int _Idx>
     struct __unlock_impl
     {
@@ -682,6 +667,7 @@ namespace std
       return __try_lock_impl<0>::__do_try_lock(__locks);
     }
 
+  /// lock
   template<typename _L1, typename _L2, typename ..._L3>
     void
     lock(_L1&, _L2&, _L3&...);
@@ -721,36 +707,42 @@ namespace std
 #else
   extern function<void()> __once_functor;
 
-  extern unique_lock<mutex>&
-  __get_once_functor_lock();
+  extern void
+  __set_once_functor_lock_ptr(unique_lock<mutex>*);
+
+  extern mutex&
+  __get_once_mutex();
 #endif
 
   extern "C" void __once_proxy();
 
+  /// call_once
   template<typename _Callable, typename... _Args>
     void
     call_once(once_flag& __once, _Callable __f, _Args&&... __args)
     {
 #ifdef _GLIBCXX_HAVE_TLS
-      auto __bound_functor = bind(__f, __args...);
+      auto __bound_functor = std::bind<void>(__f, __args...);
       __once_callable = &__bound_functor;
       __once_call = &__once_call_impl<decltype(__bound_functor)>;
 #else
-      unique_lock<mutex>& __functor_lock = __get_once_functor_lock();
-      __functor_lock.lock();
-      __once_functor = bind(__f, __args...);
+      unique_lock<mutex> __functor_lock(__get_once_mutex());
+      __once_functor = std::bind<void>(__f, __args...);
+      __set_once_functor_lock_ptr(&__functor_lock);
 #endif
 
       int __e = __gthread_once(&(__once._M_once), &__once_proxy);
 
 #ifndef _GLIBCXX_HAVE_TLS
       if (__functor_lock)
-       __functor_lock.unlock();
+        __set_once_functor_lock_ptr(0);
 #endif
 
       if (__e)
        __throw_system_error(__e);
     }
+
+  // @} group mutexes
 }
 
 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1