ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/cfperl.h
(Generate patch)

Comparing deliantra/server/include/cfperl.h (file contents):
Revision 1.43 by root, Sat Dec 30 15:07:59 2006 UTC vs.
Revision 1.51 by root, Tue Jan 23 03:56:45 2007 UTC

35 35
36// same here, massive symbol spamming 36// same here, massive symbol spamming
37#undef do_open 37#undef do_open
38#undef do_close 38#undef do_close
39#undef ref 39#undef ref
40#undef seed
40 41
41// perl bug #40256: perl does overwrite those with reentrant versions 42// perl bug #40256: perl does overwrite those with reentrant versions
42// but does not initialise their state structures. 43// but does not initialise their state structures.
43#undef random 44#undef random
44#undef crypt 45#undef crypt
59 60
60////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 61//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61 62
62void cfperl_init (); 63void cfperl_init ();
63void cfperl_main (); 64void cfperl_main ();
65void cfperl_emergency_save ();
64 66
65////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 67//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66 68
67// virtual server time, excluding time jumps and lag 69// virtual server time, excluding time jumps and lag
68extern double runtime; 70extern double runtime;
119double cfperl_result_DOUBLE (int idx); 121double cfperl_result_DOUBLE (int idx);
120int cfperl_result_INT (int idx); 122int cfperl_result_INT (int idx);
121 123
122////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 124//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
123 125
126INTERFACE_CLASS (attachable)
124struct attachable 127struct attachable
125{ 128{
126 static MGVTBL vtbl; 129 static MGVTBL vtbl;
127 130
128 static unordered_vector<attachable *> mortals; 131 static unordered_vector<attachable *> mortals;
129 static void check_mortals (); 132 MTH static void check_mortals ();
130 133
131 enum { 134 enum {
132 F_DESTROYED = 0x01, 135 F_DESTROYED = 0x01,
133 F_BORROWED = 0x02,
134 }; 136 };
135 137
136 // object is delete'd after the refcount reaches 0 138 // object is delete'd after the refcount reaches 0
137 mutable int refcnt; 139 mutable int ACC (RW, refcnt);
138 int flags; 140 int ACC (RW, flags);
139 141
140 void refcnt_inc () const { ++refcnt; } 142 MTH void refcnt_inc () const { ++refcnt; }
141 void refcnt_dec () const { --refcnt; } 143 MTH void refcnt_dec () const { --refcnt; }
142 144
145 MTH int refcnt_cnt () const;
143 // check wether the object has died and destroy 146 // check wether the object has died and destroy
144 void refcnt_chk () { if (refcnt <= 0) do_check (); } 147 MTH void refcnt_chk () { if (refcnt <= 0) do_check (); }
145 148
146 // destroy the object unless it was already destroyed 149 // destroy the object unless it was already destroyed
147 // this politely asks everybody interested the reduce 150 // this politely asks everybody interested the reduce
148 // the refcount to 0 as soon as possible. 151 // the refcount to 0 as soon as possible.
149 void destroy (); 152 MTH void destroy ();
150 153
151 // return wether an object was destroyed already 154 // return wether an object was destroyed already
152 bool destroyed () const { return flags & F_DESTROYED; } 155 MTH bool destroyed () const { return flags & F_DESTROYED; }
153 156
154 virtual void gather_callbacks (AV *&callbacks, event_type event) const; 157 virtual void gather_callbacks (AV *&callbacks, event_type event) const;
155 158
156#if 0 159#if 0
157private: 160private:
178 virtual ~attachable (); 181 virtual ~attachable ();
179 182
180 attachable &operator =(const attachable &src); 183 attachable &operator =(const attachable &src);
181 184
182 bool invoke (event_type event, ...); 185 bool invoke (event_type event, ...);
183 void instantiate (); 186 MTH void instantiate ();
184 void reattach (); 187 void reattach ();
185 188
186protected: 189protected:
187 // do the real refcount checking work 190 // do the real refcount checking work
188 void do_check (); 191 void do_check ();
247 } 250 }
248 251
249 *p = '\n'; 252 *p = '\n';
250 } 253 }
251 254
252 void put (keyword k, const char *v) 255 void put (keyword k, const char *v = 0)
253 { 256 {
254 put_string (k, v); 257 put_string (k, v);
255 } 258 }
256 259
257 void put (keyword k, const shstr &v) 260 void put (keyword k, const shstr &v)
322 void put (keyword k, const refptr<T> &v) 325 void put (keyword k, const refptr<T> &v)
323 { 326 {
324 put (k, (T *)v); 327 put (k, (T *)v);
325 } 328 }
326 329
327 bool save (const char *filename); 330 bool save (const char *path);
328 char *as_string (); // like strdup 331 char *as_string (); // like strdup
329 332
330 operator bool () { return !!av; } 333 operator bool () { return !!av; }
331}; 334};
332 335
338{ 341{
339 SV *text; // text part 342 SV *text; // text part
340 AV *av; // perl part 343 AV *av; // perl part
341 char *line; // current beginning of line 344 char *line; // current beginning of line
342 char *last_keyword, *last_value; 345 char *last_keyword, *last_value;
346 const char *name;
343 347
344 operator bool () { return !!text; } 348 operator bool () { return !!text; }
345 349
346 object_thawer (const char *filename = 0); 350 object_thawer (const char *path = 0);
347 object_thawer (const char *data, AV *perlav); 351 object_thawer (const char *data, AV *perlav);
348 ~object_thawer (); 352 ~object_thawer ();
349 353
350 void get (attachable *obj, int oid); 354 void get (attachable *obj, int oid);
351 355
383struct coroapi { 387struct coroapi {
384 static struct CoroAPI *GCoroAPI; 388 static struct CoroAPI *GCoroAPI;
385 389
386 static int nready () { return CORO_NREADY; } 390 static int nready () { return CORO_NREADY; }
387 static int cede () { return CORO_CEDE ; } 391 static int cede () { return CORO_CEDE ; }
392
393 static int cede_counter;
394
395 static void cede_every (int count)
396 {
397 if (++cede_counter >= count)
398 {
399 cede_counter = 0;
400
401 if (coroapi::nready ())
402 coroapi::cede ();
403 }
404 }
388}; 405};
389 406
390struct watcher_base 407struct watcher_base
391{ 408{
392 static struct EventAPI *GEventAPI; 409 static struct EventAPI *GEventAPI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines