Class: Asynchronous::MemoryObj
Instance Method Summary
collapse
Constructor Details
#initialize(obj) ⇒ MemoryObj
Returns a new instance of MemoryObj.
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/asynchronous/shared_memory.rb', line 29
def initialize(obj)
@data= ::ProcessShared::SharedMemory.new(
::Asynchronous.memory_allocation_size)
@mutex= ::ProcessShared::Mutex.new
@data.write_object(obj)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/asynchronous/shared_memory.rb', line 49
def method_missing(method, *args, &block)
new_value= nil
original_value= nil
return_value= nil
mutex_obj= nil
if ::Asynchronous.global_mutex == true
mutex_obj= ::Asynchronous::Global.mutex
else
mutex_obj= @mutex
end
mutex_obj.synchronize do
new_value= asynchronous_get_value
begin
original_value= new_value.dup
rescue ::TypeError
original_value= new_value
end
return_value= new_value.__send__(method,*args,&block)
unless new_value == original_value
asynchronous_set_value new_value
end
end
return return_value
end
|
Instance Method Details
#asynchronous_get_value ⇒ Object
45
46
47
|
# File 'lib/asynchronous/shared_memory.rb', line 45
def asynchronous_get_value
return @data.read_object
end
|
#asynchronous_set_value(obj) ⇒ Object
Also known as:
asynchronous_set_value=
40
41
42
|
# File 'lib/asynchronous/shared_memory.rb', line 40
def asynchronous_set_value obj
return @data.write_object obj
end
|