summaryrefslogtreecommitdiff
path: root/sal
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
commit3bd56343e3842725458680b0ea9ed4d2ddb72319 (patch)
treef8fcc17e9518134266d888f7548437576845db38 /sal
parent16c3e65481995d8a7e5456ed0ba5daa063286716 (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')
-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 d705c5eee..3e5f1ef8f 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;