]> pd.if.org Git - uuid/blobdiff - internal.c
Removed unused node variable.
[uuid] / internal.c
index 59e1bbf402d05b3416b1c1323e625f1f095b9e16..c911099ff6bee130f9daf05e7730cec1c72f060d 100644 (file)
@@ -127,11 +127,12 @@ static int release_global_lock(void *data) {
 static uint64_t current_time(void) {
        uint64_t now;
        struct timeval tv;
+       static int seq = 0;
        
        /* TODO is this BSD specific? */
        gettimeofday(&tv, 0);
 
-       now = (tv.tv_sec * 10000000ULL + tv.tv_usec * 10ULL) + GREGORIAN;
+       now = (tv.tv_sec * 10000000ULL + tv.tv_usec * 10ULL + seq++ % 10) + GREGORIAN;
        return now;
 }
 
@@ -274,11 +275,19 @@ static uint16_t random_clock_sequence(struct pd_uuid_state *s) {
 }
 
 static int read_state(struct pd_uuid_state *s) {
+       uint64_t        node;
+
        s->available = 0;
        s->node = 0LL;
        s->clock_sequence = 0;
        s->timestamp = 0LL;
 
+       node = current_node(s);
+
+       if (!s->available || s->node != node) {
+               s->clock_sequence = random_clock_sequence(s);
+       }
+
        return 0;
 }
 
@@ -297,6 +306,30 @@ static unsigned long get_bytes(void *buf, unsigned long n, void *state) {
        return i;
 }
 
+int pd_uuid_init(struct pd_uuid_state *s, int flags) {
+       if (!s) return 0;
+
+       s->get_lock = obtain_global_lock;
+       s->release_lock = release_global_lock;
+       s->lock_data = 0;
+
+       if (flags & 0x1) {
+               s->read_state = 0;
+               s->save_state = 0;
+               s->node = current_node(s);
+       } else {
+               s->read_state = read_state;
+               s->save_state = 0;
+       }
+
+       s->random_bytes = get_bytes;
+       s->rng_state = 0;
+
+       s->available = 0;
+
+       return 1;
+}
+
 int pd_uuid_init_state(struct pd_uuid_state *s) {
        if (!s) return 0;
 
@@ -318,7 +351,6 @@ int pd_uuid_init_state(struct pd_uuid_state *s) {
 int pd_uuid_make_v1(struct pd_uuid_state *s, pd_uuid_t *uuid) {
        struct pd_uuid_state    ls;
        uint64_t        now;
-       uint64_t        node;
        int err;
 
        if (!s) {
@@ -341,13 +373,6 @@ int pd_uuid_make_v1(struct pd_uuid_state *s, pd_uuid_t *uuid) {
        }
 
        now = current_time();
-       node = current_node(s);
-
-       if (!s->available || s->node != node) {
-               s->clock_sequence = random_clock_sequence(s);
-       }
-
-       s->node = node;
 
        if (s->available && s->timestamp > now) {
                s->clock_sequence++;