X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=libstdc%2B%2B-v3%2Fsrc%2Fmutex.cc;h=26435a277839ed92a11e949bca84555848a90cd3;hp=8fae0302fda0686476bcb8d838a59478c968275d;hb=9e57b7da32645abe81d39e4676f219413da5df05;hpb=30f461c5c1995022a4db9586eadf26c773ba51f6 diff --git a/libstdc++-v3/src/mutex.cc b/libstdc++-v3/src/mutex.cc index 8fae0302fda..26435a27783 100644 --- a/libstdc++-v3/src/mutex.cc +++ b/libstdc++-v3/src/mutex.cc @@ -1,6 +1,6 @@ // mutex -*- C++ -*- -// Copyright (C) 2008 Free Software Foundation, Inc. +// Copyright (C) 2008, 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 @@ -30,6 +30,17 @@ #include #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) +#ifndef _GLIBCXX_HAVE_TLS +namespace +{ + std::mutex& + get_once_mutex() + { + static std::mutex once_mutex; + return once_mutex; + } +} +#endif namespace std { @@ -45,11 +56,16 @@ namespace std __thread void* __once_callable; __thread void (*__once_call)(); #else - // explicit instantiation due to -fno-implicit-instantiation + // Explicit instantiation due to -fno-implicit-instantiation. template class function; function __once_functor; - mutex __once_mutex; - unique_lock __once_functor_lock(__once_mutex, defer_lock); + + unique_lock& + __get_once_functor_lock() + { + static unique_lock once_functor_lock(get_once_mutex(), defer_lock); + return once_functor_lock; + } #endif extern "C" @@ -58,7 +74,7 @@ namespace std { #ifndef _GLIBCXX_HAVE_TLS function __once_call = std::move(__once_functor); - __once_functor_lock.unlock(); + __get_once_functor_lock().unlock(); #endif __once_call(); }