--- deliantra/server/include/cfperl.h 2006/12/31 10:28:36 1.44 +++ deliantra/server/include/cfperl.h 2007/01/23 03:56:45 1.51 @@ -62,6 +62,7 @@ void cfperl_init (); void cfperl_main (); +void cfperl_emergency_save (); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -122,35 +123,36 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +INTERFACE_CLASS (attachable) struct attachable { static MGVTBL vtbl; static unordered_vector mortals; - static void check_mortals (); + MTH static void check_mortals (); enum { F_DESTROYED = 0x01, - F_BORROWED = 0x02, }; // object is delete'd after the refcount reaches 0 - mutable int refcnt; - int flags; + mutable int ACC (RW, refcnt); + int ACC (RW, flags); - void refcnt_inc () const { ++refcnt; } - void refcnt_dec () const { --refcnt; } + MTH void refcnt_inc () const { ++refcnt; } + MTH void refcnt_dec () const { --refcnt; } + MTH int refcnt_cnt () const; // check wether the object has died and destroy - void refcnt_chk () { if (refcnt <= 0) do_check (); } + MTH void refcnt_chk () { if (refcnt <= 0) do_check (); } // destroy the object unless it was already destroyed // this politely asks everybody interested the reduce // the refcount to 0 as soon as possible. - void destroy (); + MTH void destroy (); // return wether an object was destroyed already - bool destroyed () const { return flags & F_DESTROYED; } + MTH bool destroyed () const { return flags & F_DESTROYED; } virtual void gather_callbacks (AV *&callbacks, event_type event) const; @@ -181,7 +183,7 @@ attachable &operator =(const attachable &src); bool invoke (event_type event, ...); - void instantiate (); + MTH void instantiate (); void reattach (); protected: @@ -250,7 +252,7 @@ *p = '\n'; } - void put (keyword k, const char *v) + void put (keyword k, const char *v = 0) { put_string (k, v); } @@ -325,7 +327,7 @@ put (k, (T *)v); } - bool save (const char *filename); + bool save (const char *path); char *as_string (); // like strdup operator bool () { return !!av; } @@ -341,10 +343,11 @@ AV *av; // perl part char *line; // current beginning of line char *last_keyword, *last_value; + const char *name; operator bool () { return !!text; } - object_thawer (const char *filename = 0); + object_thawer (const char *path = 0); object_thawer (const char *data, AV *perlav); ~object_thawer (); @@ -386,6 +389,19 @@ static int nready () { return CORO_NREADY; } static int cede () { return CORO_CEDE ; } + + static int cede_counter; + + static void cede_every (int count) + { + if (++cede_counter >= count) + { + cede_counter = 0; + + if (coroapi::nready ()) + coroapi::cede (); + } + } }; struct watcher_base