get-current_time -- get time as 60 bit 100ns ticks since whenever. Compensate for the fact that real clock resolution is less than 100ns. */
| 238 | /* get-current_time -- get time as 60 bit 100ns ticks since whenever. |
| 239 | Compensate for the fact that real clock resolution is less than 100ns. */ |
| 240 | static void get_current_time(uuid_time_t * timestamp) |
| 241 | { |
| 242 | uuid_time_t time_now; |
| 243 | static uuid_time_t time_last; |
| 244 | static unsigned16 uuids_this_tick; |
| 245 | static int inited = 0; |
| 246 | |
| 247 | if (!inited) { |
| 248 | get_system_time(&time_now); |
| 249 | uuids_this_tick = UUIDS_PER_TICK; |
| 250 | inited = 1; |
| 251 | }; |
| 252 | |
| 253 | while (1) { |
| 254 | get_system_time(&time_now); |
| 255 | |
| 256 | /* if clock reading changed since last UUID generated... */ |
| 257 | if (time_last != time_now) { |
| 258 | /* reset count of uuids gen'd with this clock reading */ |
| 259 | uuids_this_tick = 0; |
| 260 | break; |
| 261 | }; |
| 262 | if (uuids_this_tick < UUIDS_PER_TICK) { |
| 263 | uuids_this_tick++; |
| 264 | break; |
| 265 | }; /* going too fast for our clock; spin */ |
| 266 | }; /* add the count of uuids to low order bits of the clock reading */ |
| 267 | |
| 268 | *timestamp = time_now + uuids_this_tick; |
| 269 | time_last = time_now; |
| 270 | } |
| 271 | |
| 272 | /* true_random -- generate a crypto-quality random number. |
| 273 | This sample doesn't do that. */ |
no test coverage detected