- struct pd_uuid_state ls;
- uint64_t now;
- int err;
-
- if (!s) {
- s = &ls;
- pd_uuid_init_state(s);
- }
-
- if (s->get_lock) {
- if ((err = s->get_lock(s->lock_data)) != 0) {
- /* TODO set uuid to nil ? */
- /* be cute and have an "error" uuid? */
- return 0;
- }
- }
-
- if (s->read_state) {
- if ((err = s->read_state(s)) != 0) {
- return 0;
- }
- }
-
- now = current_time();
-
- if (s->available && s->timestamp > now) {
- s->clock_sequence++;
- } else {
- s->timestamp = now;
- }
-
- if (s->save_state) {
- if ((err = s->save_state(s)) != 0) {
- return 0;
- }
- }
-
- if (s->release_lock) {
- if ((err = s->release_lock(s->lock_data)) != 0) {
- /* TODO set uuid to nil ? */
- /* be cute and have an "error" uuid? */
- return 0;
- }
- }
-
- format_uuid(uuid, s, 1);
-
- return 1;