ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.134 by root, Thu Jan 4 17:28:49 2007 UTC vs.
Revision 1.135 by root, Thu Jan 4 20:29:46 2007 UTC

179sub to_json($) { 179sub to_json($) {
180 $JSON::Syck::ImplicitUnicode = 0; # work around JSON::Syck bugs 180 $JSON::Syck::ImplicitUnicode = 0; # work around JSON::Syck bugs
181 JSON::Syck::Dump $_[0] 181 JSON::Syck::Dump $_[0]
182} 182}
183 183
184=item my $guard = cf::guard { BLOCK }
185
186Run the given callback when the guard object gets destroyed (useful for
187coroutine cancellations).
188
189You can call C<< ->cancel >> on the guard object to stop the block from
190being executed.
191
192=cut
193
194sub guard(&) {
195 bless \(my $cb = $_[0]), cf::guard::;
196}
197
198sub cf::guard::cancel {
199 ${$_[0]} = sub { };
200}
201
202sub cf::guard::DESTROY {
203 ${$_[0]}->();
204}
205
206=item cf::lock_wait $string 184=item cf::lock_wait $string
207 185
208Wait until the given lock is available. See cf::lock_acquire. 186Wait until the given lock is available. See cf::lock_acquire.
209 187
210=item my $lock = cf::lock_acquire $string 188=item my $lock = cf::lock_acquire $string
211 189
212Wait until the given lock is available and then acquires it and returns 190Wait until the given lock is available and then acquires it and returns
213a guard object. If the guard object gets destroyed (goes out of scope, 191a Coro::guard object. If the guard object gets destroyed (goes out of scope,
214for example when the coroutine gets canceled), the lock is automatically 192for example when the coroutine gets canceled), the lock is automatically
215returned. 193returned.
216 194
217Lock names should begin with a unique identifier (for example, cf::map::find 195Lock names should begin with a unique identifier (for example, cf::map::find
218uses map_find and cf::map::load uses map_load). 196uses map_find and cf::map::load uses map_load).
237 # wait, to be sure we are not locked 215 # wait, to be sure we are not locked
238 lock_wait $key; 216 lock_wait $key;
239 217
240 $LOCK{$key} = []; 218 $LOCK{$key} = [];
241 219
242 cf::guard { 220 Coro::guard {
243 # wake up all waiters, to be on the safe side 221 # wake up all waiters, to be on the safe side
244 $_->ready for @{ delete $LOCK{$key} }; 222 $_->ready for @{ delete $LOCK{$key} };
245 } 223 }
246} 224}
247 225
262} 240}
263 241
264sub freeze_mainloop { 242sub freeze_mainloop {
265 return unless $TICK_WATCHER->is_active; 243 return unless $TICK_WATCHER->is_active;
266 244
267 my $guard = guard { $TICK_WATCHER->start }; 245 my $guard = Coro::guard { $TICK_WATCHER->start };
268 $TICK_WATCHER->stop; 246 $TICK_WATCHER->stop;
269 $guard 247 $guard
270} 248}
271 249
272=item cf::sync_job { BLOCK } 250=item cf::sync_job { BLOCK }
1184 or return; 1162 or return;
1185 1163
1186 my $map = cf::map::new 1164 my $map = cf::map::new
1187 or return; 1165 or return;
1188 1166
1167 # for better error messages only, will be overwritten
1168 $map->path ($path);
1169
1189 $map->load_header ($path) 1170 $map->load_header ($path)
1190 or return; 1171 or return;
1191 1172
1192 $map->{load_path} = $path; 1173 $map->{load_path} = $path;
1193 1174

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines