--- deliantra/server/include/cfperl.h 2006/12/30 10:16:10 1.42 +++ deliantra/server/include/cfperl.h 2007/01/08 01:19:03 1.49 @@ -37,6 +37,7 @@ #undef do_open #undef do_close #undef ref +#undef seed // perl bug #40256: perl does overwrite those with reentrant versions // but does not initialise their state structures. @@ -47,7 +48,6 @@ // some macros to simplify perl in-calls -// FUNCTION is, afaik, a gnu extension #define CHECK_ERROR \ if (SvTRUE (ERRSV)) \ LOG (llevError, "runtime error in %s: %s\n", __func__, SvPVutf8_nolen (ERRSV)); @@ -122,12 +122,13 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +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, @@ -135,22 +136,23 @@ }; // 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