Class: Mutex
- Inherits:
-
Object
- Object
- Mutex
- Defined in:
- lib/rubysl/thread/thread.rb
Instance Method Summary collapse
-
#initialize ⇒ Mutex
constructor
A new instance of Mutex.
- #lock ⇒ Object
- #locked? ⇒ Boolean
-
#marshal_dump ⇒ Object
Check and only allow it to be marshal’d if there are no waiters.
-
#marshal_load(bunk) ⇒ Object
Implemented because we must since we use marshal_load PLUS we need to create AND prime @lock.
- #synchronize ⇒ Object
- #try_lock ⇒ Object
- #unlock ⇒ Object
Constructor Details
#initialize ⇒ Mutex
Returns a new instance of Mutex.
41 42 43 |
# File 'lib/rubysl/thread/thread.rb', line 41 def initialize @owner = nil end |
Instance Method Details
#lock ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rubysl/thread/thread.rb', line 73 def lock Rubinius. if @owner == Thread.current raise ThreadError, "Recursively locking not allowed" end Rubinius.lock self @owner = Thread.current Rubinius. return self end |
#locked? ⇒ Boolean
58 59 60 |
# File 'lib/rubysl/thread/thread.rb', line 58 def locked? Rubinius.locked?(self) end |
#marshal_dump ⇒ Object
Check and only allow it to be marshal’d if there are no waiters.
46 47 48 49 |
# File 'lib/rubysl/thread/thread.rb', line 46 def marshal_dump raise "Unable to dump locked mutex" unless @waiters.empty? 1 end |
#marshal_load(bunk) ⇒ Object
Implemented because we must since we use marshal_load PLUS we need to create AND prime @lock. If we didn’t do this, then Marshal wouldn’t prime the lock anyway.
54 55 56 |
# File 'lib/rubysl/thread/thread.rb', line 54 def marshal_load(bunk) initialize end |
#synchronize ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/rubysl/thread/thread.rb', line 96 def synchronize lock begin yield ensure unlock end end |
#try_lock ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rubysl/thread/thread.rb', line 62 def try_lock # Locking implies a memory barrier, so we don't need to use # one explicitly. if Rubinius.try_lock(self) @owner = Thread.current true else false end end |