… | |
… | |
120 | double cfperl_result_DOUBLE (int idx); |
120 | double cfperl_result_DOUBLE (int idx); |
121 | int cfperl_result_INT (int idx); |
121 | int cfperl_result_INT (int idx); |
122 | |
122 | |
123 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
123 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
124 | |
124 | |
|
|
125 | INTERFACE_CLASS (attachable) |
125 | struct attachable |
126 | struct 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 | |
|
|
145 | MTH int refcnt_cnt () const; |
144 | // check wether the object has died and destroy |
146 | // check wether the object has died and destroy |
145 | void refcnt_chk () { if (refcnt <= 0) do_check (); } |
147 | MTH void refcnt_chk () { if (refcnt <= 0) do_check (); } |
146 | |
148 | |
147 | // destroy the object unless it was already destroyed |
149 | // destroy the object unless it was already destroyed |
148 | // this politely asks everybody interested the reduce |
150 | // this politely asks everybody interested the reduce |
149 | // the refcount to 0 as soon as possible. |
151 | // the refcount to 0 as soon as possible. |
150 | void destroy (); |
152 | MTH void destroy (); |
151 | |
153 | |
152 | // return wether an object was destroyed already |
154 | // return wether an object was destroyed already |
153 | bool destroyed () const { return flags & F_DESTROYED; } |
155 | MTH bool destroyed () const { return flags & F_DESTROYED; } |
154 | |
156 | |
155 | virtual void gather_callbacks (AV *&callbacks, event_type event) const; |
157 | virtual void gather_callbacks (AV *&callbacks, event_type event) const; |
156 | |
158 | |
157 | #if 0 |
159 | #if 0 |
158 | private: |
160 | private: |
… | |
… | |
179 | virtual ~attachable (); |
181 | virtual ~attachable (); |
180 | |
182 | |
181 | attachable &operator =(const attachable &src); |
183 | attachable &operator =(const attachable &src); |
182 | |
184 | |
183 | bool invoke (event_type event, ...); |
185 | bool invoke (event_type event, ...); |
184 | void instantiate (); |
186 | MTH void instantiate (); |
185 | void reattach (); |
187 | void reattach (); |
186 | |
188 | |
187 | protected: |
189 | protected: |
188 | // do the real refcount checking work |
190 | // do the real refcount checking work |
189 | void do_check (); |
191 | void do_check (); |
… | |
… | |
248 | } |
250 | } |
249 | |
251 | |
250 | *p = '\n'; |
252 | *p = '\n'; |
251 | } |
253 | } |
252 | |
254 | |
253 | void put (keyword k, const char *v) |
255 | void put (keyword k, const char *v = 0) |
254 | { |
256 | { |
255 | put_string (k, v); |
257 | put_string (k, v); |
256 | } |
258 | } |
257 | |
259 | |
258 | void put (keyword k, const shstr &v) |
260 | void put (keyword k, const shstr &v) |
… | |
… | |
323 | void put (keyword k, const refptr<T> &v) |
325 | void put (keyword k, const refptr<T> &v) |
324 | { |
326 | { |
325 | put (k, (T *)v); |
327 | put (k, (T *)v); |
326 | } |
328 | } |
327 | |
329 | |
328 | bool save (const char *filename); |
330 | bool save (const char *path); |
329 | char *as_string (); // like strdup |
331 | char *as_string (); // like strdup |
330 | |
332 | |
331 | operator bool () { return !!av; } |
333 | operator bool () { return !!av; } |
332 | }; |
334 | }; |
333 | |
335 | |
… | |
… | |
339 | { |
341 | { |
340 | SV *text; // text part |
342 | SV *text; // text part |
341 | AV *av; // perl part |
343 | AV *av; // perl part |
342 | char *line; // current beginning of line |
344 | char *line; // current beginning of line |
343 | char *last_keyword, *last_value; |
345 | char *last_keyword, *last_value; |
|
|
346 | const char *name; |
344 | |
347 | |
345 | operator bool () { return !!text; } |
348 | operator bool () { return !!text; } |
346 | |
349 | |
347 | object_thawer (const char *filename = 0); |
350 | object_thawer (const char *path = 0); |
348 | object_thawer (const char *data, AV *perlav); |
351 | object_thawer (const char *data, AV *perlav); |
349 | ~object_thawer (); |
352 | ~object_thawer (); |
350 | |
353 | |
351 | void get (attachable *obj, int oid); |
354 | void get (attachable *obj, int oid); |
352 | |
355 | |
… | |
… | |
384 | struct coroapi { |
387 | struct coroapi { |
385 | static struct CoroAPI *GCoroAPI; |
388 | static struct CoroAPI *GCoroAPI; |
386 | |
389 | |
387 | static int nready () { return CORO_NREADY; } |
390 | static int nready () { return CORO_NREADY; } |
388 | 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 | } |
389 | }; |
405 | }; |
390 | |
406 | |
391 | struct watcher_base |
407 | struct watcher_base |
392 | { |
408 | { |
393 | static struct EventAPI *GEventAPI; |
409 | static struct EventAPI *GEventAPI; |