Class: CrystalRuby::ArcMutex
- Inherits:
-
Object
- Object
- CrystalRuby::ArcMutex
- Defined in:
- lib/crystalruby/arc_mutex.rb
Instance Method Summary collapse
- #init_mutex! ⇒ Object
- #lock ⇒ Object
- #phtread_mutex ⇒ Object
- #synchronize ⇒ Object
- #to_ptr ⇒ Object
- #unlock ⇒ Object
Instance Method Details
#init_mutex! ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/crystalruby/arc_mutex.rb', line 29 def init_mutex! mutex = LibC::PThreadMutexT.new res = LibC.pthread_mutex_init(mutex, nil) raise "Failed to initialize mutex" unless res.zero? mutex end |
#lock ⇒ Object
37 38 39 40 |
# File 'lib/crystalruby/arc_mutex.rb', line 37 def lock res = LibC.pthread_mutex_lock(phtread_mutex) raise "Failed to lock mutex" unless res.zero? end |
#phtread_mutex ⇒ Object
15 16 17 |
# File 'lib/crystalruby/arc_mutex.rb', line 15 def phtread_mutex @phtread_mutex ||= init_mutex! end |
#synchronize ⇒ Object
19 20 21 22 23 |
# File 'lib/crystalruby/arc_mutex.rb', line 19 def synchronize lock yield unlock end |
#to_ptr ⇒ Object
25 26 27 |
# File 'lib/crystalruby/arc_mutex.rb', line 25 def to_ptr phtread_mutex.pointer end |
#unlock ⇒ Object
42 43 44 45 |
# File 'lib/crystalruby/arc_mutex.rb', line 42 def unlock res = LibC.pthread_mutex_unlock(phtread_mutex) raise "Failed to unlock mutex" unless res.zero? end |