diff options
author | qsr@chromium.org <qsr@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2012-03-08 18:47:26 +0000 |
---|---|---|
committer | qsr@chromium.org <qsr@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2012-03-08 18:47:26 +0000 |
commit | fe7f63632f5cd24bea65d1ef2de88ccbab9b8602 (patch) | |
tree | e7e0c52f08a76ebc1623f63929792be63b8a1b8f /src/common/linux | |
parent | Removing breakpad_exc_server and all references. (diff) | |
download | breakpad-fe7f63632f5cd24bea65d1ef2de88ccbab9b8602.tar.xz |
Remove static initializer in linux/guid_creator.cc.
There was a static initializer generated for this file in Chrome for Android.
Patch by pliard@chromium.org
Original review: http://breakpad.appspot.com/359001/
Review URL: https://breakpad.appspot.com/359002
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@931 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/common/linux')
-rw-r--r-- | src/common/linux/guid_creator.cc | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/common/linux/guid_creator.cc b/src/common/linux/guid_creator.cc index 678f5904..426f93a1 100644 --- a/src/common/linux/guid_creator.cc +++ b/src/common/linux/guid_creator.cc @@ -30,6 +30,7 @@ #include "common/linux/guid_creator.h" #include <assert.h> +#include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <time.h> @@ -45,10 +46,6 @@ // class GUIDGenerator { public: - GUIDGenerator() { - srandom(time(NULL)); - } - static u_int32_t BytesToUInt32(const u_int8_t bytes[]) { return ((u_int32_t) bytes[0] | ((u_int32_t) bytes[1] << 8) @@ -63,7 +60,8 @@ class GUIDGenerator { bytes[3] = (n >> 24) & 0xff; } - bool CreateGUID(GUID *guid) const { + static bool CreateGUID(GUID *guid) { + InitOnce(); guid->data1 = random(); guid->data2 = (u_int16_t)(random()); guid->data3 = (u_int16_t)(random()); @@ -71,13 +69,23 @@ class GUIDGenerator { UInt32ToBytes(&guid->data4[4], random()); return true; } + + private: + static void InitOnce() { + pthread_once(&once_control, &InitOnceImpl); + } + + static void InitOnceImpl() { + srandom(time(NULL)); + } + + static pthread_once_t once_control; }; -// Guid generator. -const GUIDGenerator kGuidGenerator; +pthread_once_t GUIDGenerator::once_control = PTHREAD_ONCE_INIT; bool CreateGUID(GUID *guid) { - return kGuidGenerator.CreateGUID(guid); + return GUIDGenerator::CreateGUID(guid); } // Parse guid to string. |