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.44 by root, Sun Dec 31 10:28:36 2006 UTC vs.
Revision 1.48 by root, Sun Jan 7 18:01:09 2007 UTC

120double cfperl_result_DOUBLE (int idx); 120double cfperl_result_DOUBLE (int idx);
121int cfperl_result_INT (int idx); 121int cfperl_result_INT (int idx);
122 122
123////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 123//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
124 124
125INTERFACE_CLASS (attachable)
125struct attachable 126struct attachable
126{ 127{
127 static MGVTBL vtbl; 128 static MGVTBL vtbl;
128 129
129 static unordered_vector<attachable *> mortals; 130 static unordered_vector<attachable *> mortals;
130 static void check_mortals (); 131 MTH static void check_mortals ();
131 132
132 enum { 133 enum {
133 F_DESTROYED = 0x01, 134 F_DESTROYED = 0x01,
134 F_BORROWED = 0x02, 135 F_BORROWED = 0x02,
135 }; 136 };
136 137
137 // object is delete'd after the refcount reaches 0 138 // object is delete'd after the refcount reaches 0
138 mutable int refcnt; 139 mutable int ACC (RW, refcnt);
139 int flags; 140 int ACC (RW, flags);
140 141
141 void refcnt_inc () const { ++refcnt; } 142 MTH void refcnt_inc () const { ++refcnt; }
142 void refcnt_dec () const { --refcnt; } 143 MTH void refcnt_dec () const { --refcnt; }
143 144
144 // check wether the object has died and destroy 145 // check wether the object has died and destroy
145 void refcnt_chk () { if (refcnt <= 0) do_check (); } 146 MTH void refcnt_chk () { if (refcnt <= 0) do_check (); }
146 147
147 // destroy the object unless it was already destroyed 148 // destroy the object unless it was already destroyed
148 // this politely asks everybody interested the reduce 149 // this politely asks everybody interested the reduce
149 // the refcount to 0 as soon as possible. 150 // the refcount to 0 as soon as possible.
150 void destroy (); 151 MTH void destroy ();
151 152
152 // return wether an object was destroyed already 153 // return wether an object was destroyed already
153 bool destroyed () const { return flags & F_DESTROYED; } 154 MTH bool destroyed () const { return flags & F_DESTROYED; }
154 155
155 virtual void gather_callbacks (AV *&callbacks, event_type event) const; 156 virtual void gather_callbacks (AV *&callbacks, event_type event) const;
156 157
157#if 0 158#if 0
158private: 159private:
179 virtual ~attachable (); 180 virtual ~attachable ();
180 181
181 attachable &operator =(const attachable &src); 182 attachable &operator =(const attachable &src);
182 183
183 bool invoke (event_type event, ...); 184 bool invoke (event_type event, ...);
184 void instantiate (); 185 MTH void instantiate ();
185 void reattach (); 186 void reattach ();
186 187
187protected: 188protected:
188 // do the real refcount checking work 189 // do the real refcount checking work
189 void do_check (); 190 void do_check ();
248 } 249 }
249 250
250 *p = '\n'; 251 *p = '\n';
251 } 252 }
252 253
253 void put (keyword k, const char *v) 254 void put (keyword k, const char *v = 0)
254 { 255 {
255 put_string (k, v); 256 put_string (k, v);
256 } 257 }
257 258
258 void put (keyword k, const shstr &v) 259 void put (keyword k, const shstr &v)
323 void put (keyword k, const refptr<T> &v) 324 void put (keyword k, const refptr<T> &v)
324 { 325 {
325 put (k, (T *)v); 326 put (k, (T *)v);
326 } 327 }
327 328
328 bool save (const char *filename); 329 bool save (const char *path);
329 char *as_string (); // like strdup 330 char *as_string (); // like strdup
330 331
331 operator bool () { return !!av; } 332 operator bool () { return !!av; }
332}; 333};
333 334
339{ 340{
340 SV *text; // text part 341 SV *text; // text part
341 AV *av; // perl part 342 AV *av; // perl part
342 char *line; // current beginning of line 343 char *line; // current beginning of line
343 char *last_keyword, *last_value; 344 char *last_keyword, *last_value;
345 const char *name;
344 346
345 operator bool () { return !!text; } 347 operator bool () { return !!text; }
346 348
347 object_thawer (const char *filename = 0); 349 object_thawer (const char *path = 0);
348 object_thawer (const char *data, AV *perlav); 350 object_thawer (const char *data, AV *perlav);
349 ~object_thawer (); 351 ~object_thawer ();
350 352
351 void get (attachable *obj, int oid); 353 void get (attachable *obj, int oid);
352 354
384struct coroapi { 386struct coroapi {
385 static struct CoroAPI *GCoroAPI; 387 static struct CoroAPI *GCoroAPI;
386 388
387 static int nready () { return CORO_NREADY; } 389 static int nready () { return CORO_NREADY; }
388 static int cede () { return CORO_CEDE ; } 390 static int cede () { return CORO_CEDE ; }
391
392 static int cede_counter;
393
394 static void cede_every (int count)
395 {
396 if (++cede_counter >= count)
397 {
398 cede_counter = 0;
399
400 if (coroapi::nready ())
401 coroapi::cede ();
402 }
403 }
389}; 404};
390 405
391struct watcher_base 406struct watcher_base
392{ 407{
393 static struct EventAPI *GEventAPI; 408 static struct EventAPI *GEventAPI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines