stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r566892 - /incubator/stdcxx/trunk/src/locale_classic.cpp
Date Fri, 17 Aug 2007 00:36:23 GMT
Author: sebor
Date: Thu Aug 16 17:36:22 2007
New Revision: 566892

URL: http://svn.apache.org/viewvc?view=rev&rev=566892
Log:
2007-08-17  Martin Sebor  <sebor@roguewave.com>

	STDCXX-523
	* locale_classic.cpp (__rw_classic): New. Namespace-scope buffer
	backing the classic locale object.
	(__rw_classic_once_init): New. One-time initialization flag for
	the classic locale object.
	(__rw_init_classic): New. One-time initialization function for
	the classic locale object.
	(classic): Used __rw_once() to initialize the classic locale
	object.

Modified:
    incubator/stdcxx/trunk/src/locale_classic.cpp

Modified: incubator/stdcxx/trunk/src/locale_classic.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/src/locale_classic.cpp?view=diff&rev=566892&r1=566891&r2=566892
==============================================================================
--- incubator/stdcxx/trunk/src/locale_classic.cpp (original)
+++ incubator/stdcxx/trunk/src/locale_classic.cpp Thu Aug 16 17:36:22 2007
@@ -22,37 +22,73 @@
  * implied.   See  the License  for  the  specific language  governing
  * permissions and limitations under the License.
  *
- * Copyright 1994-2006 Rogue Wave Software.
+ * Copyright 2001-2007 Rogue Wave Software, Inc.
  * 
  **************************************************************************/
 
 #define _RWSTD_LIB_SRC
-
-#include <new>
 #include <rw/_defs.h>
 
-#include <loc/_locale.h>
+#include <new>             // for placment new
+
+#include <loc/_locale.h>   // for locale
+#include "once.h"          // for __rw_once()
+
+
+_RWSTD_NAMESPACE (__rw) { 
 
-#include "locale_body.h"
+// static buffer for the classic "C" locale object
+static union {
+    void* _C_align;
+    char  _C_buf [sizeof (_STD::locale)];
+} __rw_classic;
 
 
-_RWSTD_NAMESPACE (std) { 
+// init-once flag for the classic "C" locale object
+static __rw_once_t
+__rw_classic_once_init = _RWSTD_ONCE_INIT;
 
 
-/* static */ const locale& locale::classic ()
+extern "C" {
+
+// one-time initializer for the classic "C" locale object
+static void
+__rw_init_classic ()
 {
-    // classic locale will not be destroyed during program runtime
-    static _RW::__rw_locale *pbody = _RW::__rw_locale::_C_manage (0, "C");
+#ifdef _RWSTDDEBUG
+
+    static int init;
+
+    // paranoid check: verify that one-time initialization works
+    _RWSTD_ASSERT (0 == init);
+
+    ++init;
 
-    static union {
-        void* _C_align;
-        char  _C_buf [sizeof (locale)];
-    } classic_locale;
+#endif   // _RWSTDDEBUG
+
+    // construct the classic "C" locale in the provided buffer
+    new (&__rw_classic) _STD::locale ("C");
+}
+
+}   // extern "C"
+
+}   // namespace __rw
+
+
+_RWSTD_NAMESPACE (std) {
+
+
+/* static */ const locale& locale::
+classic ()
+{
+    // initialize classic locale in the static buffer exactly once
+    _RW::__rw_once (&_RW::__rw_classic_once_init, _RW::__rw_init_classic);
 
-    _RWSTD_ASSERT (0 != pbody);
+    // cast the address of the buffer to a locale pointer
+    const locale* const pclassic =
+        _RWSTD_REINTERPRET_CAST (locale*, &_RW::__rw_classic);
 
-    // multiple initialization by multiple threads is benign
-    static locale *pclassic = new (&classic_locale) locale (*pbody);
+    _RWSTD_ASSERT (0 != pclassic->_C_body);
 
     return *pclassic;
 }



Mime
View raw message