git://git.onelab.eu
/
sliver-openvswitch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ofproto-dpif: Guard rule statistics with a mutex.
[sliver-openvswitch.git]
/
lib
/
uuid.c
diff --git
a/lib/uuid.c
b/lib/uuid.c
index
e259024
..
18748ea
100644
(file)
--- a/
lib/uuid.c
+++ b/
lib/uuid.c
@@
-1,4
+1,4
@@
-/* Copyright (c) 2008, 2009, 2010
Nicira Networks
+/* Copyright (c) 2008, 2009, 2010
, 2011, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-26,7
+26,9
@@
#include "aes128.h"
#include "entropy.h"
#include "aes128.h"
#include "entropy.h"
+#include "ovs-thread.h"
#include "sha1.h"
#include "sha1.h"
+#include "timeval.h"
#include "util.h"
static struct aes128 key;
#include "util.h"
static struct aes128 key;
@@
-48,11
+50,8
@@
static void do_init(void);
void
uuid_init(void)
{
void
uuid_init(void)
{
- static bool inited;
- if (!inited) {
- do_init();
- inited = true;
- }
+ static pthread_once_t once = PTHREAD_ONCE_INIT;
+ pthread_once(&once, do_init);
}
/* Generates a new random UUID in 'uuid'.
}
/* Generates a new random UUID in 'uuid'.
@@
-82,15
+81,22
@@
uuid_init(void)
void
uuid_generate(struct uuid *uuid)
{
void
uuid_generate(struct uuid *uuid)
{
+ static struct ovs_mutex mutex = OVS_ADAPTIVE_MUTEX_INITIALIZER;
+ uint64_t copy[2];
+
uuid_init();
uuid_init();
- /* Increment the counter. */
+ /* Copy out the counter's current value, then increment it. */
+ ovs_mutex_lock(&mutex);
+ copy[0] = counter[0];
+ copy[1] = counter[1];
if (++counter[1] == 0) {
counter[0]++;
}
if (++counter[1] == 0) {
counter[0]++;
}
+ ovs_mutex_unlock(&mutex);
/* AES output is exactly 16 bytes, so we encrypt directly into 'uuid'. */
/* AES output is exactly 16 bytes, so we encrypt directly into 'uuid'. */
- aes128_encrypt(&key, co
unter
, uuid);
+ aes128_encrypt(&key, co
py
, uuid);
/* Set bits to indicate a random UUID. See RFC 4122 section 4.4. */
uuid->parts[2] &= ~0xc0000000;
/* Set bits to indicate a random UUID. See RFC 4122 section 4.4. */
uuid->parts[2] &= ~0xc0000000;
@@
-212,9
+218,7
@@
do_init(void)
/* Get seed data. */
get_entropy_or_die(random_seed, sizeof random_seed);
/* Get seed data. */
get_entropy_or_die(random_seed, sizeof random_seed);
- if (gettimeofday(&now, NULL)) {
- ovs_fatal(errno, "gettimeofday failed");
- }
+ xgettimeofday(&now);
pid = getpid();
ppid = getppid();
uid = getuid();
pid = getpid();
ppid = getppid();
uid = getuid();