… | |
… | |
34 | #include <loader.h> |
34 | #include <loader.h> |
35 | |
35 | |
36 | #include <bitset> |
36 | #include <bitset> |
37 | |
37 | |
38 | UUID UUID::cur; |
38 | UUID UUID::cur; |
|
|
39 | static uint64_t seq_next_save; |
39 | static const uint64 UUID_SKIP = 1<<19; |
40 | static const uint64 UUID_GAP = 1<<19; |
40 | |
41 | |
41 | objectvec objects; |
42 | objectvec objects; |
42 | activevec actives; |
43 | activevec actives; |
43 | |
44 | |
44 | short freearr_x[SIZEOFFREE] = { |
45 | short freearr_x[SIZEOFFREE] = { |
… | |
… | |
81 | { |
82 | { |
82 | char filename[MAX_BUF]; |
83 | char filename[MAX_BUF]; |
83 | |
84 | |
84 | sprintf (filename, "%s/uuid", settings.localdir); |
85 | sprintf (filename, "%s/uuid", settings.localdir); |
85 | |
86 | |
|
|
87 | seq_next_save = 0; |
|
|
88 | |
86 | FILE *fp; |
89 | FILE *fp; |
87 | |
90 | |
88 | if (!(fp = fopen (filename, "r"))) |
91 | if (!(fp = fopen (filename, "r"))) |
89 | { |
92 | { |
90 | if (errno == ENOENT) |
93 | if (errno == ENOENT) |
91 | { |
94 | { |
92 | LOG (llevInfo, "RESET uid to 1\n"); |
95 | LOG (llevInfo, "RESET uid to 1\n"); |
93 | UUID::cur.seq = 0; |
96 | UUID::cur.seq = 0; |
94 | write_uuid (UUID_SKIP, true); |
97 | write_uuid (UUID_GAP, true); |
95 | return; |
98 | return; |
96 | } |
99 | } |
97 | |
100 | |
98 | LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); |
101 | LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); |
99 | _exit (1); |
102 | _exit (1); |
… | |
… | |
109 | _exit (1); |
112 | _exit (1); |
110 | } |
113 | } |
111 | |
114 | |
112 | LOG (llevDebug, "read UUID: %s\n", UUID::cur.c_str ()); |
115 | LOG (llevDebug, "read UUID: %s\n", UUID::cur.c_str ()); |
113 | |
116 | |
114 | write_uuid (UUID_SKIP, true); |
117 | write_uuid (UUID_GAP, true); |
115 | fclose (fp); |
118 | fclose (fp); |
116 | } |
119 | } |
117 | |
120 | |
118 | UUID |
121 | UUID |
119 | UUID::gen () |
122 | UUID::gen () |
120 | { |
123 | { |
121 | UUID uid; |
124 | UUID uid; |
122 | |
125 | |
123 | uid.seq = ++cur.seq; |
126 | uid.seq = ++cur.seq; |
124 | |
127 | |
125 | if (expect_false (!(cur.seq & (UUID_SKIP - 1)))) |
128 | if (expect_false (cur.seq >= seq_next_save)) |
|
|
129 | { |
|
|
130 | seq_next_save = UUID::cur.seq + (UUID_GAP >> 1); |
126 | write_uuid (UUID_SKIP, false); |
131 | write_uuid (UUID_GAP, false); |
|
|
132 | } |
|
|
133 | |
127 | |
134 | |
128 | return uid; |
135 | return uid; |
129 | } |
136 | } |
130 | |
137 | |
131 | void |
138 | void |