Partial MonitorMixin implementation.
This commit is contained in:
1 parent
80284301a7
commit
5aba20cdf7
3 files changed
+76
No files matched your search
@@ -29,4 +29,5 @@ require 'process_shared/binary_semaphore'
|
||||
require 'process_shared/mutex'
|
||||
require 'process_shared/condition_variable'
|
||||
require 'process_shared/monitor'
|
||||
require 'process_shared/monitor_mixin'
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
require 'process_shared'
|
||||
|
||||
module ProcessShared
|
||||
module MonitorMixin
|
||||
def self.extended(obj)
|
||||
obj.send :mon_initialize
|
||||
end
|
||||
|
||||
def mon_enter
|
||||
@mon_monitor.lock
|
||||
end
|
||||
|
||||
def mon_exit
|
||||
@mon_monitor.unlock
|
||||
end
|
||||
|
||||
def mon_synchronize
|
||||
mon_enter
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
mon_exit
|
||||
end
|
||||
end
|
||||
alias_method :synchronize, :mon_synchronize
|
||||
|
||||
def mon_try_enter
|
||||
raise NotImplementedError, 'not implemented'
|
||||
end
|
||||
alias_method :try_mon_enter, :mon_try_enter
|
||||
|
||||
def new_cond
|
||||
raise NotImplementedError, 'not implemented'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mon_initialize
|
||||
@mon_monitor = Monitor.new
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user