summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2011-10-31 17:50:40 +0100
committerStephan Bergmann <sbergman@redhat.com>2011-11-01 17:10:13 +0100
commit451c945da28818d3791dcaf85716ceae8fa70e61 (patch)
treedaecedbd2207cebd7c86a8e9950b2db199c61073 /sal
parentf8f02136d8984ebd0a1a79fa3169e61e53521215 (diff)
Fixed rtl_getGlobalProcessId implementation (moved from C to C++).
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/source/rtl_process.cxx (renamed from sal/rtl/source/rtl_process.c)54
1 files changed, 33 insertions, 21 deletions
diff --git a/sal/rtl/source/rtl_process.c b/sal/rtl/source/rtl_process.cxx
index 0845f46f5723..e20b3338ba88 100644
--- a/sal/rtl/source/rtl_process.c
+++ b/sal/rtl/source/rtl_process.cxx
@@ -25,27 +25,39 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-#include <string.h>
-#include <osl/mutex.h>
-#include <rtl/uuid.h>
-
-/* rtl_getCommandArg, rtl_getCommandArgCount see cmdargs.cxx */
-
-void SAL_CALL rtl_getGlobalProcessId( sal_uInt8 *pTargetUUID )
-{
- static sal_uInt8 *pUuid = 0;
- if( ! pUuid )
- {
- osl_acquireMutex( * osl_getGlobalMutex() );
- if( ! pUuid )
- {
- static sal_uInt8 aUuid[16];
- rtl_createUuid( aUuid , 0 , sal_False );
- pUuid = aUuid;
- }
- osl_releaseMutex( * osl_getGlobalMutex() );
- }
- memcpy( pTargetUUID , pUuid , 16 );
+
+#include "precompiled_sal.hxx"
+#include "sal/config.h"
+
+#include <cstring>
+
+#include "boost/noncopyable.hpp"
+#include "rtl/instance.hxx"
+#include "rtl/process.h"
+#include "rtl/uuid.h"
+#include "sal/types.h"
+
+namespace {
+
+class Id: private boost::noncopyable {
+public:
+ Id() { rtl_createUuid(uuid_, 0, false); }
+
+ void copy(sal_uInt8 * target) const
+ { std::memcpy(target, uuid_, UUID_SIZE); }
+
+private:
+ enum { UUID_SIZE = 16 };
+
+ sal_uInt8 uuid_[UUID_SIZE];
+};
+
+struct theId: public rtl::Static< Id, theId > {};
+
+}
+
+void rtl_getGlobalProcessId(sal_uInt8 * pTargetUUID) {
+ theId::get().copy(pTargetUUID);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */