ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.144 by root, Fri Jan 19 15:55:27 2007 UTC vs.
Revision 1.152 by root, Tue Jan 23 03:17:56 2007 UTC

107} 107}
108 108
109int 109int
110attachable::refcnt_cnt () const 110attachable::refcnt_cnt () const
111{ 111{
112 return refcnt + (self ? SvREFCNT (self) : 0); 112 return refcnt + (self ? SvREFCNT (self) - 1 : 0);
113} 113}
114 114
115void 115void
116attachable::optimise () 116attachable::optimise ()
117{ 117{
118 if (self 118 if (self
119 && SvREFCNT (self) == 1 119 && SvREFCNT (self) == 1
120 && !HvTOTALKEYS (self)) 120 && !HvTOTALKEYS (self))
121 { 121 {
122 refcnt_inc ();
123 SvREFCNT_dec ((SV *)self); 122 SvREFCNT_dec ((SV *)self);
123 assert (!self);
124 } 124 }
125} 125}
126 126
127// check wether the object really is dead 127// check wether the object really is dead
128void 128void
129attachable::do_check () 129attachable::do_check ()
130{ 130{
131 if (refcnt > 0 || refcnt_cnt () > 0) 131 if (refcnt_cnt () > 0)
132 return; 132 return;
133 133
134 destroy (); 134 destroy ();
135 135
136 if (self) 136 if (self)
164} 164}
165 165
166void 166void
167attachable::check_mortals () 167attachable::check_mortals ()
168{ 168{
169 for (int i = 0; i < mortals.size (); ) 169 static int i = 0;
170
171 for (;;)
170 { 172 {
173 if (i >= mortals.size ())
174 {
175 i = 0;
176
177 if (mortals.size () > 1000)
178 fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ());
179
180 break;
181 }
182
171 attachable *obj = mortals [i]; 183 attachable *obj = mortals [i];
172 184
173 obj->refcnt_chk (); // unborrow from perl, if necessary 185 obj->refcnt_chk (); // unborrow from perl, if necessary
174 186
187 //if (obj->refcnt > 0 || obj->self)
175 if (obj->refcnt || obj->self) 188 if (obj->refcnt || obj->self)
176 { 189 {
177#if 0 190//printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D
178 if (mortals.size() > 5)fprintf (stderr, "%d delaying %d:%p:%s %d (self %p:%d)\n", time(0),i, obj, typeid (*obj).name (),
179 obj->refcnt, obj->self, obj->self ? SvREFCNT(obj->self): - 1);//D
180#endif
181
182 ++i; // further delay freeing 191 ++i; // further delay freeing
192
193 if (!(i & 0x3ff))
194 break;
183 }//D 195 }
184 else 196 else
185 { 197 {
186 //Dfprintf (stderr, "deleteing %d:%p:%s\n", i, obj,typeid (*obj).name ());//D
187 mortals.erase (i); 198 mortals.erase (i);
188 delete obj; 199 delete obj;
189 } 200 }
190 } 201 }
191} 202}
234 245
235 if (!obj->self) 246 if (!obj->self)
236 { 247 {
237 obj->self = newHV (); 248 obj->self = newHV ();
238 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 249 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
239
240 // borrow the refcnt from the object
241 // it is important thta no refcnt_chk is being executed here
242 obj->refcnt_dec ();
243 250
244 // now bless the object _once_ 251 // now bless the object _once_
245 return sv_bless (newRV_inc ((SV *)obj->self), stash); 252 return sv_bless (newRV_inc ((SV *)obj->self), stash);
246 } 253 }
247 else 254 else
313inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 320inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
314 321
315inline SV *to_sv (object & v) { return to_sv (&v); } 322inline SV *to_sv (object & v) { return to_sv (&v); }
316inline SV *to_sv (living & v) { return to_sv (&v); } 323inline SV *to_sv (living & v) { return to_sv (&v); }
317 324
318inline SV *to_sv (New_Face * v) { return to_sv (v->name); } 325inline SV *to_sv (facetile * v) { return to_sv (v->name); }
319inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 326inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
320 327
321inline SV *to_sv (UUID v) 328inline SV *to_sv (UUID v)
322{ 329{
323 char buf[128]; 330 char buf[128];
348inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 355inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
349inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 356inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
350inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } 357inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
351inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 358inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
352 359
353inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } 360inline void sv_to (SV *sv, facetile * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; }
354inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } 361inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); }
355 362
356template<class T> 363template<class T>
357inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 364inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
358 365
895void 902void
896iw::alloc () 903iw::alloc ()
897{ 904{
898 pe = GEventAPI->new_idle (0, 0); 905 pe = GEventAPI->new_idle (0, 0);
899 906
907 WaREENTRANT_off (pe);
900 pe->base.callback = (void *)iw_dispatch; 908 pe->base.callback = (void *)iw_dispatch;
901 pe->base.ext_data = (void *)this; 909 pe->base.ext_data = (void *)this;
902} 910}
903 911
904static void iow_dispatch (pe_event *ev) 912static void iow_dispatch (pe_event *ev)
910void 918void
911iow::alloc () 919iow::alloc ()
912{ 920{
913 pe = GEventAPI->new_io (0, 0); 921 pe = GEventAPI->new_io (0, 0);
914 922
923 WaREENTRANT_off (pe);
915 pe->base.callback = (void *)iow_dispatch; 924 pe->base.callback = (void *)iow_dispatch;
916 pe->base.ext_data = (void *)this; 925 pe->base.ext_data = (void *)this;
917 926
918 pe->fd = -1; 927 pe->fd = -1;
919 pe->poll = 0; 928 pe->poll = 0;
1248 const_iv (FLAG_IS_WATER) 1257 const_iv (FLAG_IS_WATER)
1249 const_iv (FLAG_CONTENT_ON_GEN) 1258 const_iv (FLAG_CONTENT_ON_GEN)
1250 const_iv (FLAG_IS_A_TEMPLATE) 1259 const_iv (FLAG_IS_A_TEMPLATE)
1251 const_iv (FLAG_IS_BUILDABLE) 1260 const_iv (FLAG_IS_BUILDABLE)
1252 const_iv (FLAG_DESTROY_ON_DEATH) 1261 const_iv (FLAG_DESTROY_ON_DEATH)
1253 const_iv (FLAG_NO_SAVE) 1262 const_iv (FLAG_NO_MAP_SAVE)
1254 1263
1255 const_iv (NDI_BLACK) 1264 const_iv (NDI_BLACK)
1256 const_iv (NDI_WHITE) 1265 const_iv (NDI_WHITE)
1257 const_iv (NDI_NAVY) 1266 const_iv (NDI_NAVY)
1258 const_iv (NDI_RED) 1267 const_iv (NDI_RED)
1443 const_iv (ATNR_BLIND) 1452 const_iv (ATNR_BLIND)
1444 const_iv (ATNR_INTERNAL) 1453 const_iv (ATNR_INTERNAL)
1445 const_iv (ATNR_LIFE_STEALING) 1454 const_iv (ATNR_LIFE_STEALING)
1446 const_iv (ATNR_DISEASE) 1455 const_iv (ATNR_DISEASE)
1447 1456
1448 const_iv (MAP_FLUSH)
1449 const_iv (MAP_PLAYER_UNIQUE)
1450 const_iv (MAP_BLOCK)
1451 const_iv (MAP_STYLE)
1452 const_iv (MAP_OVERLAY)
1453
1454 const_iv (MAP_IN_MEMORY) 1457 const_iv (MAP_IN_MEMORY)
1455 const_iv (MAP_SWAPPED) 1458 const_iv (MAP_SWAPPED)
1456 const_iv (MAP_LOADING) 1459 const_iv (MAP_LOADING)
1457 const_iv (MAP_SAVING) 1460 const_iv (MAP_SAVING)
1458 1461
1624void fork_abort (char *cause = "cf::fork_abort") 1627void fork_abort (char *cause = "cf::fork_abort")
1625 1628
1626void cleanup (const char *cause, bool make_core = false) 1629void cleanup (const char *cause, bool make_core = false)
1627 1630
1628void emergency_save () 1631void emergency_save ()
1632
1633UV sv_2watcher (SV *w)
1634 CODE:
1635 RETVAL = (UV)GEventAPI->sv_2watcher (w);
1636 OUTPUT:
1637 RETVAL
1629 1638
1630void _exit (int status = 0) 1639void _exit (int status = 0)
1631 1640
1632#if _POSIX_MEMLOCK 1641#if _POSIX_MEMLOCK
1633 1642
2221 char *origin_map,\ 2230 char *origin_map,\
2222 char *final_map,\ 2231 char *final_map,\
2223 char *exitstyle,\ 2232 char *exitstyle,\
2224 char *this_map,\ 2233 char *this_map,\
2225 char *exit_on_final_map,\ 2234 char *exit_on_final_map,\
2226 int Xsize,\ 2235 int xsize,\
2227 int Ysize,\ 2236 int ysize,\
2228 int expand2x,\ 2237 int expand2x,\
2229 int layoutoptions1,\ 2238 int layoutoptions1,\
2230 int layoutoptions2,\ 2239 int layoutoptions2,\
2231 int layoutoptions3,\ 2240 int layoutoptions3,\
2232 int symmetry,\ 2241 int symmetry,\
2237 int dungeon_depth,\ 2246 int dungeon_depth,\
2238 int decoroptions,\ 2247 int decoroptions,\
2239 int orientation,\ 2248 int orientation,\
2240 int origin_y,\ 2249 int origin_y,\
2241 int origin_x,\ 2250 int origin_x,\
2242 int random_seed,\ 2251 U32 random_seed,\
2243 val64 total_map_hp,\ 2252 val64 total_map_hp,\
2244 int map_layout_style,\ 2253 int map_layout_style,\
2245 int treasureoptions,\ 2254 int treasureoptions,\
2246 int symmetry_used,\ 2255 int symmetry_used,\
2247 region *region,\ 2256 region *region,\
2263 assign (rmp.exit_on_final_map, exit_on_final_map); 2272 assign (rmp.exit_on_final_map, exit_on_final_map);
2264 2273
2265 rmp.origin_map = origin_map; 2274 rmp.origin_map = origin_map;
2266 rmp.final_map = final_map; 2275 rmp.final_map = final_map;
2267 rmp.this_map = this_map; 2276 rmp.this_map = this_map;
2268 rmp.Xsize = Xsize; 2277 rmp.xsize = xsize;
2269 rmp.Ysize = Ysize; 2278 rmp.ysize = ysize;
2270 rmp.expand2x = expand2x; 2279 rmp.expand2x = expand2x;
2271 rmp.layoutoptions1 = layoutoptions1; 2280 rmp.layoutoptions1 = layoutoptions1;
2272 rmp.layoutoptions2 = layoutoptions2; 2281 rmp.layoutoptions2 = layoutoptions2;
2273 rmp.layoutoptions3 = layoutoptions3; 2282 rmp.layoutoptions3 = layoutoptions3;
2274 rmp.symmetry = symmetry; 2283 rmp.symmetry = symmetry;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines