Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 32 lines (29 sloc) 0.661 kB
6bf7d3d @ko1 * prelude.rb: added. run this script on startup.
ko1 authored
1 class Mutex
a828a65 @knu * prelude.rb, .document: Stuff in prelude.rb should be documented
knu authored
2 # call-seq:
3 # mutex.synchronize { ... }
4 #
5 # Obtains a lock, runs the block, and releases the lock when the
6 # block completes. See the example under Mutex.
85e3b47 @ko1 * prelude.rb: fix Mutex#synchronize definition.
ko1 authored
7 def synchronize
8 self.lock
6244e50 @ko1 * thread.c: fix Mutex to be interruptable lock.
ko1 authored
9 begin
10 yield
11 ensure
6871c34 * prelude.rb (Mutex::synchronize): capture exception from unlock.
matz authored
12 self.unlock rescue nil
6244e50 @ko1 * thread.c: fix Mutex to be interruptable lock.
ko1 authored
13 end
6bf7d3d @ko1 * prelude.rb: added. run this script on startup.
ko1 authored
14 end
15 end
16
c289cf3 @ko1 * prelude.rb: add Thread.exclusive. This class method
ko1 authored
17 class Thread
e707e05 @nurse Fix :nodoc: definition. [ruby-dev:40949]
nurse authored
18 MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new # :nodoc:
a828a65 @knu * prelude.rb, .document: Stuff in prelude.rb should be documented
knu authored
19
20 # call-seq:
21 # Thread.exclusive { block } => obj
3a47cf3 @nobu * remove trailing spaces.
nobu authored
22 #
a828a65 @knu * prelude.rb, .document: Stuff in prelude.rb should be documented
knu authored
23 # Wraps a block in Thread.critical, restoring the original value
24 # upon exit from the critical section, and returns the value of the
25 # block.
c289cf3 @ko1 * prelude.rb: add Thread.exclusive. This class method
ko1 authored
26 def self.exclusive
27 MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{
28 yield
29 }
30 end
31 end
Something went wrong with that request. Please try again.