ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/object.C
(Generate patch)

Comparing deliantra/server/common/object.C (file contents):
Revision 1.203 by root, Fri Apr 11 13:59:05 2008 UTC vs.
Revision 1.204 by root, Fri Apr 11 17:01:52 2008 UTC

34#include <loader.h> 34#include <loader.h>
35 35
36#include <bitset> 36#include <bitset>
37 37
38UUID UUID::cur; 38UUID UUID::cur;
39static uint64_t seq_next_save;
39static const uint64 UUID_SKIP = 1<<19; 40static const uint64 UUID_GAP = 1<<19;
40 41
41objectvec objects; 42objectvec objects;
42activevec actives; 43activevec actives;
43 44
44short freearr_x[SIZEOFFREE] = { 45short 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
118UUID 121UUID
119UUID::gen () 122UUID::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
131void 138void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines