summaryrefslogtreecommitdiff
path: root/sal/rtl/source/uuid.cxx
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2005-05-02 12:21:22 +0000
committerOliver Bolte <obo@openoffice.org>2005-05-02 12:21:22 +0000
commit49656c8e025624cabac4b4a483917ecdb2097968 (patch)
treee28f59ded3bcddd756db9dfe297bb8e4155fa5da /sal/rtl/source/uuid.cxx
parent5b83c24a9429aa5b1cfef00d75f754c863d658e9 (diff)
INTEGRATION: CWS hrobeta2 (1.4.82); FILE MERGED
2005/02/03 11:17:52 sb 1.4.82.1: #i41904# Ensure thread safe construction of function-local statics (patch supplied by cmc).
Diffstat (limited to 'sal/rtl/source/uuid.cxx')
-rw-r--r--sal/rtl/source/uuid.cxx20
1 files changed, 13 insertions, 7 deletions
diff --git a/sal/rtl/source/uuid.cxx b/sal/rtl/source/uuid.cxx
index c05b1805e96f..09aac706ee3d 100644
--- a/sal/rtl/source/uuid.cxx
+++ b/sal/rtl/source/uuid.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: uuid.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: rt $ $Date: 2004-06-17 13:28:50 $
+ * last change: $Author: obo $ $Date: 2005-05-02 13:21:22 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -73,6 +73,7 @@
#include <rtl/random.h>
#include <rtl/uuid.h>
#include <rtl/digest.h>
+#include "rtl/instance.hxx"
#define SWAP_INT32_TO_NETWORK(x)\
{ sal_uInt32 y = x;\
@@ -171,13 +172,14 @@ static sal_uInt64 getSystemTime( )
return nNow + nTicks;
}
+namespace {
-class UuidRandomPoolHolder
+class Pool
{
rtlRandomPool pool;
public:
- UuidRandomPoolHolder() : pool( rtl_random_createPool() ) {}
- ~UuidRandomPoolHolder();
+ Pool() : pool( rtl_random_createPool() ) {}
+ ~Pool();
rtlRandomError addBytes( const void *Buffer, sal_Size Bytes )
{
@@ -190,17 +192,21 @@ public:
}
};
-UuidRandomPoolHolder::~UuidRandomPoolHolder()
+Pool::~Pool()
{
if( pool )
rtl_random_destroyPool( pool );
}
+struct PoolHolder: public rtl::Static< Pool, PoolHolder > {};
+
+}
+
static sal_uInt16 getInt16RandomValue( sal_uInt64 nSystemTime )
{
sal_uInt16 n;
- static UuidRandomPoolHolder pool;
+ Pool & pool = PoolHolder::get();
OSL_VERIFY( rtl_Random_E_None == pool.addBytes( &nSystemTime, sizeof( nSystemTime ) ) );
OSL_VERIFY( rtl_Random_E_None == pool.getBytes( &n, 2 ) );
return n;