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

Comparing deliantra/server/common/logger.C (file contents):
Revision 1.24 by root, Sun Apr 11 17:27:51 2010 UTC vs.
Revision 1.25 by root, Sun Apr 11 17:54:13 2010 UTC

38 char *buf; // includes PREFIX_LEN garbage bytes 38 char *buf; // includes PREFIX_LEN garbage bytes
39 int len; 39 int len;
40 int flags; 40 int flags;
41}; 41};
42 42
43typedef std::vector<logline, slice_allocator<logline> > logvector;
44
43static SMUTEX(mutex); 45static SMUTEX(mutex);
44static SMUTEX(fdlock); 46static SMUTEX(fdlock);
45static SCOND(cond); 47static SCOND(cond);
46static int logfd = STDERR_FILENO; 48static int logfd = STDERR_FILENO;
47static int logsync = 1; 49static int logsync = 1;
48static std::vector<logline, slice_allocator<logline> > queue; 50static logvector queue;
49 51
50int log_setfd (int fd) 52int log_setfd (int fd)
51{ 53{
52 SMUTEX_LOCK (fdlock); 54 SMUTEX_LOCK (fdlock);
53 int old = logfd; 55 int old = logfd;
131 // this algorithm could result in an ever-increasing vector 133 // this algorithm could result in an ever-increasing vector
132 // size if we log faster than we can write, but if that happens 134 // size if we log faster than we can write, but if that happens
133 // we have bigger problems. 135 // we have bigger problems.
134 if (idx == queue.size ()) 136 if (idx == queue.size ())
135 { 137 {
138 if (idx < 32)
136 queue.clear (); 139 queue.clear ();
140 else
141 logvector ().swap (queue); // free memory, hopefully
142
137 idx = 0; 143 idx = 0;
138 } 144 }
139 145
140 SMUTEX_UNLOCK (mutex); 146 SMUTEX_UNLOCK (mutex);
141 147
145 151
146void 152void
147log_cleanup () 153log_cleanup ()
148{ 154{
149 logsync = 1; 155 logsync = 1;
156 SMUTEX_UNLOCK (fdlock);
150 157
151 for (;;) 158 for (;;)
152 { 159 {
153 int done; 160 int done;
154 161

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines