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