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
This commit is contained in:
qsr@chromium.org 2012-03-08 18:47:26 +00:00
parent 76acc0edcd
commit fe7f63632f

View File

@ -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.