hakuban 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,73 +3,113 @@ require 'socket'
3
3
 
4
4
  module Hakuban
5
5
 
6
- class LocalExchange < FFIObject
6
+ class Exchange < FFIObject
7
7
 
8
- def initialize(name: false, &block)
8
+ def initialize(&block)
9
+ super()
9
10
  Hakuban::hakuban_initialize
10
11
  Hakuban::logger_initialize("hakuban=warn", skip_if_already_initialized: true)
11
- name = LocalExchange.default_name if name == false
12
- pointer = FFI::hakuban_local_exchange_new(name).unwrap
13
- initialize_pointer(pointer, :hakuban_local_exchange_drop, :hakuban_local_exchange_clone)
14
- self.do_and_drop_or_return(&block)
15
- end
16
-
17
- def self.default_name
18
- "#{Socket.gethostname}:#{File.basename(caller_locations(0..1)[1].path)}:#{$$}"
12
+ Thread.handle_interrupt(Object => :never) {
13
+ pointer = FFI::hakuban_exchange_new().unwrap
14
+ initialize_pointer(pointer, :hakuban_exchange_drop, :hakuban_exchange_clone)
15
+ self.do_and_drop_or_return(&block)
16
+ }
19
17
  end
20
18
 
21
19
  public
22
20
 
23
- def object(tags, descriptor=nil)
21
+ def object_observe_contract(tags, descriptor=nil)
22
+ if tags.kind_of? ObjectDescriptor
23
+ ObjectObserveContractBuilder.new(self, tags)
24
+ else
25
+ ObjectObserveContractBuilder.new(self, ObjectDescriptor.new(tags, descriptor))
26
+ end
27
+ end
28
+
29
+ def object_expose_contract(tags, descriptor=nil)
24
30
  if tags.kind_of? ObjectDescriptor
25
- ObjectBuilder.new(self, tags)
31
+ ObjectExposeContractBuilder.new(self, tags)
26
32
  else
27
- ObjectBuilder.new(self, ObjectDescriptor.new(tags, descriptor))
33
+ ObjectExposeContractBuilder.new(self, ObjectDescriptor.new(tags, descriptor))
28
34
  end
29
35
  end
30
36
 
31
- def tag(descriptor)
37
+ def tag_observe_contract(descriptor)
32
38
  if descriptor.kind_of? TagDescriptor
33
- TagBuilder.new(self, descriptor)
39
+ TagObserveContractBuilder.new(self, descriptor)
34
40
  else
35
- TagBuilder.new(self, TagDescriptor.new(descriptor))
41
+ TagObserveContractBuilder.new(self, TagDescriptor.new(descriptor))
42
+ end
43
+ end
44
+
45
+ def tag_expose_contract(descriptor)
46
+ if descriptor.kind_of? TagDescriptor
47
+ TagExposeContractBuilder.new(self, descriptor)
48
+ else
49
+ TagExposeContractBuilder.new(self, TagDescriptor.new(descriptor))
36
50
  end
37
51
  end
38
52
 
39
53
  end
40
54
 
41
55
 
42
- class ObjectBuilder
56
+ class ObjectObserveContractBuilder
43
57
 
44
- def initialize(store, descriptor)
45
- @store, @descriptor = store, descriptor
58
+ def initialize(exchange, descriptor)
59
+ @exchange, @descriptor = exchange, descriptor
46
60
  end
47
61
 
48
- def observe(&block)
49
- ObjectObserveContract.send(:new, @store, @descriptor).do_and_drop_or_return(&block)
62
+ def build(&block)
63
+ ObjectObserveContract.send(:new, @exchange, @descriptor, &block)
50
64
  end
51
65
 
52
- def expose(&block)
53
- ObjectExposeContract.send(:new, @store, @descriptor).do_and_drop_or_return(&block)
66
+ end
67
+
68
+ class ObjectExposeContractBuilder
69
+
70
+ def initialize(exchange, descriptor)
71
+ @exchange, @descriptor = exchange, descriptor
72
+ @capacity = 1
73
+ end
74
+
75
+ def with_capacity(capacity)
76
+ @capacity = capacity
77
+ end
78
+
79
+ def build(&block)
80
+ ObjectExposeContract.send(:new, @exchange, @descriptor, @capacity, &block)
54
81
  end
55
82
 
56
83
  end
57
84
 
58
85
 
59
- class TagBuilder
86
+ class TagObserveContractBuilder
60
87
 
61
- def initialize(store, descriptor)
62
- @store, @descriptor = store, descriptor
88
+ def initialize(exchange, descriptor)
89
+ @exchange, @descriptor = exchange, descriptor
63
90
  end
64
91
 
65
- def observe(&block)
66
- TagObserveContract.send(:new, @store, @descriptor).do_and_drop_or_return(&block)
92
+ def build(&block)
93
+ TagObserveContract.send(:new, @exchange, @descriptor, &block)
67
94
  end
68
95
 
69
- def expose(&block)
70
- TagExposeContract.send(:new, @store, @descriptor).do_and_drop_or_return(&block)
96
+ end
97
+
98
+ class TagExposeContractBuilder
99
+
100
+ def initialize(exchange, descriptor)
101
+ @exchange, @descriptor = exchange, descriptor
102
+ @capacity = 1
103
+ end
104
+
105
+ def with_capacity(capacity)
106
+ @capacity = capacity
107
+ end
108
+
109
+ def build(&block)
110
+ TagExposeContract.send(:new, @exchange, @descriptor, @capacity, &block)
71
111
  end
72
112
 
73
113
  end
74
-
114
+
75
115
  end
@@ -7,25 +7,40 @@ module Hakuban
7
7
 
8
8
  class PointerAlreadyDropped < Exception; end
9
9
 
10
+ def initialize
11
+ @pointer_mutex = Mutex.new
12
+ end
13
+
14
+ private def initialize_from_ffi_pointer(pointer, drop_fn, clone_fn)
15
+ @pointer_mutex = Mutex.new
16
+ initialize_pointer(pointer, drop_fn, clone_fn)
17
+ end
18
+
19
+
20
+ def self.from_ffi_pointer(cls, pointer)
21
+ cls.allocate.tap { |new_instance| new_instance.initialize_from_ffi_pointer(pointer) }
22
+ end
23
+
10
24
  private def initialize_pointer(pointer, drop_fn, clone_fn)
11
25
  @pointer, @drop_fn, @clone_fn = pointer.address, drop_fn, clone_fn
12
- @mutex ||= Mutex.new
13
- @drop_requested = false
14
- @drop_locked_by = Set.new
15
- @drop_locked_by_condvar = nil
16
26
  ObjectSpace.define_finalizer(self, FFIObject::generate_finalizer(drop_fn, @pointer))
17
27
  end
18
-
28
+
19
29
 
20
30
  def initialize_copy(original)
21
- raise "#{self.class.name} can't be cloned. Consider making a new one instead." if @clone_fn.nil?
22
- @mutex.synchronize {
23
- raise "#{self.class.name} can't be cloned after 'drop' has been called on it." if @pointer.nil?
24
- @pointer = FFI::method(@clone_fn).call(::FFI::Pointer.new(@pointer)).address
25
- @mutex = Mutex.new
26
- @drop_requested = false
27
- @drop_locked_by = Set.new
28
- @drop_locked_by_condvar = nil
31
+ Thread.handle_interrupt(Object => :never) {
32
+ if @clone_fn.nil?
33
+ @pointer_mutex.synchronize {
34
+ raise PointerAlreadyDropped if original.instance_variable_get(:@pointer).nil?
35
+ original.instance_variable_set(:@pointer, nil)
36
+ ObjectSpace.undefine_finalizer(original)
37
+ }
38
+ else
39
+ original.with_pointer { |pointer|
40
+ @pointer = FFI::method(@clone_fn).call(::FFI::Pointer.new(pointer)).address
41
+ }
42
+ end
43
+ @pointer_mutex = Mutex.new
29
44
  ObjectSpace.undefine_finalizer(self)
30
45
  ObjectSpace.define_finalizer(self, FFIObject::generate_finalizer(@drop_fn, @pointer))
31
46
  }
@@ -33,9 +48,12 @@ module Hakuban
33
48
 
34
49
 
35
50
  def with_pointer
36
- @mutex.synchronize {
37
- raise PointerAlreadyDropped if dropped?
38
- yield ::FFI::Pointer.new(@pointer)
51
+ @pointer_mutex.synchronize {
52
+ if @pointer
53
+ yield ::FFI::Pointer.new(@pointer)
54
+ else
55
+ raise PointerAlreadyDropped
56
+ end
39
57
  }
40
58
  end
41
59
 
@@ -57,40 +75,20 @@ module Hakuban
57
75
 
58
76
 
59
77
  def drop
60
- @mutex.synchronize {
61
- #TODO: wait here till dropped?
62
- return if @drop_requested
63
- @drop_requested = true
64
- @drop_locked_by.each { |queue| queue << :dropping }
65
- @drop_locked_by_condvar ||= ConditionVariable.new
66
- @drop_locked_by_condvar.wait(@mutex) while @drop_locked_by.size > 0
67
- return if dropped?
68
- ObjectSpace.undefine_finalizer(self)
69
- FFI::method(@drop_fn).call(::FFI::Pointer.new(@pointer))
70
- @pointer = @finalizer = nil
71
- }
72
- end
73
-
74
-
75
- def drop_lock(queue)
76
- @mutex.synchronize {
77
- raise FFIObject::PointerAlreadyDropped if @drop_requested
78
- @drop_locked_by << queue
79
- }
80
- true
81
- end
82
-
83
-
84
- def drop_release(queue)
85
- @mutex.synchronize {
86
- @drop_locked_by.delete(queue)
87
- @drop_locked_by_condvar.broadcast if @drop_locked_by_condvar
78
+ @pointer_mutex.synchronize {
79
+ Thread.handle_interrupt(Object => :never) {
80
+ if !!@pointer
81
+ ObjectSpace.undefine_finalizer(self)
82
+ FFI::method(@drop_fn).call(::FFI::Pointer.new(@pointer))
83
+ @pointer = nil
84
+ end
85
+ }
88
86
  }
89
87
  end
90
88
 
91
89
 
92
90
  def dropped?
93
- @pointer.nil?
91
+ !@pointer
94
92
  end
95
93
 
96
94
 
@@ -101,8 +99,9 @@ module Hakuban
101
99
  end
102
100
 
103
101
 
104
- def do_and_drop
105
- Thread.handle_interrupt(Object => :never) {
102
+ # this should always be called with interrupts disabled, in the same section where pointer creation occurs
103
+ def do_and_drop_or_return(&block)
104
+ if block
106
105
  begin
107
106
  Thread.handle_interrupt(Object => :immediate) {
108
107
  yield self
@@ -110,18 +109,10 @@ module Hakuban
110
109
  ensure
111
110
  self.drop
112
111
  end
113
- }
114
- end
115
-
116
-
117
- def do_and_drop_or_return(&block)
118
- if block
119
- do_and_drop(&block)
120
112
  else
121
113
  self
122
114
  end
123
115
  end
124
-
125
116
 
126
117
  def inspect
127
118
  "#<#{self.class.name} #{self.dropped? ? "DROPPED" : "%016X"%@pointer}>"
data/lib/hakuban/ffi.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
  require 'ffi'
3
3
  require 'hakuban/ffi-object'
4
-
4
+ require 'hakuban/refinements'
5
5
 
6
6
  module Hakuban::FFI
7
7
 
@@ -16,9 +16,10 @@ module Hakuban::FFI
16
16
  class FFIErrorInvalidLogLevel < FFIError; end
17
17
  class FFIErrorUnknownError < FFIError; end
18
18
 
19
+
19
20
  class FFIResultStatus < FFI::Struct
20
21
  layout :id, :uint8
21
- ENUM = [:Ok, :Pending, :NotAvailable, :InvalidString, :InvalidJSON, :InvalidURL, :InvalidLogLevel, :UnknownError]
22
+ ENUM = [:Ok, :Pointer, :Pending, :EndOfStream, :InvalidString, :InvalidJSON, :InvalidURL, :InvalidLogLevel, :LoggerInitializationError, :ConnectionTerminated].freeze
22
23
 
23
24
  def to_sym
24
25
  ENUM[self[:id]]
@@ -31,196 +32,99 @@ module Hakuban::FFI
31
32
 
32
33
 
33
34
  class FFIResult < FFI::Struct
34
- FFIResultStatus::ENUM.each { |sym|
35
- define_method(("is_"+sym.to_s+"?").to_sym) {
36
- FFIResultStatus::ENUM[self[:status][:id]] == sym
37
- }
38
- }
39
- end
40
-
41
-
42
- class FFIResultWithNothing < FFIResult
43
- layout :status, FFIResultStatus
44
-
45
- def unwrap
46
- return nil if self[:status].to_sym == :NotAvailable
47
- raise self[:status].to_exception if self[:status].to_sym != :Ok
48
- nil
49
- end
50
- end
51
-
52
-
53
- class FFIResultWithPointer < FFIResult
54
35
  layout :status, FFIResultStatus, :pointer, :pointer
55
36
 
56
37
  def unwrap
57
- return nil if self[:status].to_sym == :NotAvailable
58
- raise self[:status].to_exception if self[:status].to_sym != :Ok
38
+ return true if self[:status].to_sym == :Ok
39
+ return nil if self[:status].to_sym == :EndOfStream
40
+ raise self[:status].to_exception if self[:status].to_sym != :Pointer
59
41
  self[:pointer]
60
42
  end
61
- end
62
-
63
-
64
- class Callbacks
65
-
66
- attr_reader :waker
67
-
68
- def initialize
69
- @queues = {}
70
- @queues_sequence = 0
71
- @queues_mutex = Mutex.new
72
- @waker = proc { |pointer|
73
- queue_id = pointer.address
74
- @queues_mutex.synchronize {
75
- @queues[queue_id]&.each { |queue|
76
- queue << :wake
77
- }
78
- }
79
- }
80
- end
81
-
82
- def register_queue(queue)
83
- @queues_mutex.synchronize {
84
- @queues_sequence = (@queues_sequence+1) % 2**32
85
- queue_id = @queues_sequence
86
- (@queues[queue_id] ||= Set.new) << queue
87
- queue_id
88
- }
89
- end
90
-
91
- def unregister_queue(queue_id)
92
- @queues_mutex.synchronize {
93
- @queues[queue_id].delete(queue_id)
94
- @queues.delete(queue_id) if @queues[queue_id].empty?
95
- }
96
- end
97
- end
98
43
 
99
-
100
- class FFIFutureReturningNothing < FFI::Struct
101
- layout :pointer, :pointer
102
-
103
- @@callbacks = Callbacks.new
104
-
105
- def self.create_and_await(owner)
106
- Thread.handle_interrupt(Object => :never) {
107
- begin
108
- queue = queue_id = drop_locked = pointer = nil
109
- Thread.handle_interrupt(Object => :immediate) {
110
- queue = Queue.new
111
- queue_id = @@callbacks.register_queue(queue)
112
- drop_locked = owner.drop_lock(queue)
113
- return nil if !pointer = owner.with_pointer { |pointer| yield pointer }
114
- loop {
115
- result = owner.with_pointer { Hakuban::FFI::hakuban_future_returning_nothing_poll(pointer[:pointer],@@callbacks.waker,::FFI::Pointer.new(queue_id)) }
116
- return result if not result.is_Pending?
117
- # Currently the only future returning nothing is guaranteed to complete at first poll
118
- # :unreachable:
119
- raise Hakuban::FFIObject::PointerAlreadyDropped if queue.pop == :dropping
120
- # :unreachable:
121
- }
122
- }
123
- ensure
124
- Hakuban::FFI::hakuban_future_returning_nothing_drop(pointer[:pointer]) if pointer
125
- owner.drop_release(queue) if drop_locked
126
- @@callbacks.unregister_queue(queue_id)
127
- end
128
- }
44
+ def status
45
+ self[:status].to_sym
129
46
  end
130
47
  end
131
48
 
132
49
 
133
- class FFIFutureReturningPointer < FFI::Struct
134
- layout :pointer, :pointer
135
-
136
- @@callbacks = Callbacks.new
137
-
138
- def self.create_and_await(owner)
139
- Thread.handle_interrupt(Object => :never) {
140
- begin
141
- queue = queue_id = drop_locked = pointer = nil
142
- Thread.handle_interrupt(Object => :immediate) {
143
- queue = Queue.new
144
- queue_id = @@callbacks.register_queue(queue)
145
- drop_locked = owner.drop_lock(queue)
146
- return nil if !pointer = owner.with_pointer { |pointer| yield pointer }
147
- loop {
148
- result = owner.with_pointer { Hakuban::FFI::hakuban_future_returning_pointer_poll(pointer[:pointer],@@callbacks.waker,::FFI::Pointer.new(queue_id)) }
149
- return result if not result.is_Pending?
150
- raise Hakuban::FFIObject::PointerAlreadyDropped if queue.pop == :dropping
151
- }
152
- }
153
- ensure
154
- Hakuban::FFI::hakuban_future_returning_pointer_drop(pointer[:pointer]) if pointer
155
- owner.drop_release(queue) if drop_locked
156
- @@callbacks.unregister_queue(queue_id)
157
- end
158
- }
50
+ class FFIFuture
51
+
52
+ using ThreadExt
53
+
54
+ #This HAS to be called with interrupts disabled.
55
+ #If both, internal exception, and an interrupt fire, pay attention not to drop one of them.
56
+ def self.await(future_pointer)
57
+ error = result_thread = result = nil
58
+ future_pointer_for_blocking_await = Hakuban::FFI::hakuban_future_clone(future_pointer)
59
+ begin
60
+ # ThreadError gets raised here on process shutdown
61
+ result_thread = Thread.new { Hakuban::FFI::hakuban_future_await(future_pointer_for_blocking_await) }
62
+ Thread.handle_interrupt(Object => :immediate) { result_thread.join }
63
+ rescue Object => e
64
+ error = e
65
+ end
66
+ Hakuban::FFI::hakuban_future_drop(future_pointer)
67
+ if result_thread
68
+ result = result_thread.join_with_warning
69
+ else
70
+ Hakuban::FFI::hakuban_future_drop(future_pointer_for_blocking_await)
71
+ end
72
+ return [result, error]
159
73
  end
74
+
160
75
  end
161
76
 
162
77
 
163
78
  class FFIArray < FFI::Struct
164
79
  layout :length, :size_t, :pointer, :pointer
165
80
  end
166
-
167
81
 
168
- # Every function which can cause a wake() has to be "blocking: true".
169
- # Otherwise they are very likely to deadlock on GVL and other locks acquired by RemoteExchange on incomming message.
170
- # FIXME: way too many functions are marked as blocking here
171
82
 
172
- callback :waker, [ :pointer ], :void
83
+ # Every function which can cause a callback has to be "blocking: true".
84
+ # Otherwise they are very likely to deadlock on GVL and other locks acquired by Connection(s) on incomming message
85
+ # Fortunately, we don't use callbacks any more. And the only function with unbounded execution time is the future-await. So, only setting that one as blocking.
86
+
87
+ callback :waker, [ :pointer ], :void
173
88
 
174
- attach_function :hakuban_logger_initialize, [ :string ], FFIResultWithNothing.by_value
89
+ attach_function :hakuban_logger_initialize, [ :string ], FFIResult.by_value
175
90
 
176
- attach_function :hakuban_local_exchange_new, [ :string ], FFIResultWithPointer.by_value
177
- attach_function :hakuban_local_exchange_drop, [ :pointer ], :void
178
- attach_function :hakuban_local_exchange_clone, [ :pointer ], :pointer
91
+ attach_function :hakuban_exchange_new, [ ], FFIResult.by_value
92
+ attach_function :hakuban_exchange_drop, [ :pointer ], :void
93
+ attach_function :hakuban_exchange_clone, [ :pointer ], :pointer
179
94
 
180
95
  attach_function :hakuban_tokio_init_multi_thread, [ :size_t ], :pointer
181
- attach_function :hakuban_tokio_websocket_connector_new, [ :pointer, :pointer, :string ], FFIResultWithPointer.by_value
182
- attach_function :hakuban_tokio_websocket_connector_drop, [ :pointer ], :void, blocking: true
183
-
184
- attach_function :hakuban_object_observe_contract_new, [ :pointer, :pointer ], :pointer, blocking: true
185
- attach_function :hakuban_object_observe_contract_drop, [ :pointer ], :void, blocking: true
186
- attach_function :hakuban_object_observe_contract_terminate, [ :pointer ], :void, blocking: true
187
- attach_function :hakuban_object_observe_contract_next, [ :pointer ], FFIFutureReturningPointer.by_value, blocking: true
188
- attach_function :hakuban_object_observe_contract_ready, [ :pointer ], FFIResultWithPointer.by_value, blocking: true
189
-
190
- attach_function :hakuban_object_expose_contract_new, [ :pointer, :pointer ], :pointer, blocking: true
191
- attach_function :hakuban_object_expose_contract_drop, [ :pointer ], :void, blocking: true
192
- attach_function :hakuban_object_expose_contract_terminate, [ :pointer ], :void, blocking: true
193
- attach_function :hakuban_object_expose_contract_next, [ :pointer ], FFIFutureReturningPointer.by_value, blocking: true
194
- attach_function :hakuban_object_expose_contract_ready, [ :pointer ], FFIResultWithPointer.by_value, blocking: true
195
-
196
- attach_function :hakuban_tag_observe_contract_new, [ :pointer, :pointer ], :pointer, blocking: true
197
- attach_function :hakuban_tag_observe_contract_drop, [ :pointer ], :void, blocking: true
198
- attach_function :hakuban_tag_observe_contract_terminate, [ :pointer ], :void, blocking: true
199
- attach_function :hakuban_tag_observe_contract_next, [ :pointer ], FFIFutureReturningPointer.by_value, blocking: true
200
- attach_function :hakuban_tag_observe_contract_ready, [ :pointer ], FFIArray.by_value, blocking: true
201
-
202
- attach_function :hakuban_tag_expose_contract_new, [ :pointer, :pointer ], :pointer, blocking: true
203
- attach_function :hakuban_tag_expose_contract_drop, [ :pointer ], :void, blocking: true
204
- attach_function :hakuban_tag_expose_contract_terminate, [ :pointer ], :void, blocking: true
205
- attach_function :hakuban_tag_expose_contract_next, [ :pointer ], FFIFutureReturningPointer.by_value, blocking: true
206
- attach_function :hakuban_tag_expose_contract_ready, [ :pointer ], FFIArray.by_value, blocking: true
207
-
208
- attach_function :hakuban_object_state_stream_drop, [ :pointer ], :void, blocking: true
209
- attach_function :hakuban_object_state_stream_next, [ :pointer ], FFIFutureReturningPointer.by_value, blocking: true
210
- attach_function :hakuban_object_state_stream_current, [ :pointer ], FFIResultWithPointer.by_value
96
+ attach_function :hakuban_tokio_websocket_connector_new, [ :pointer, :pointer, :string ], FFIResult.by_value
97
+ attach_function :hakuban_tokio_websocket_connector_drop, [ :pointer ], :void
98
+
99
+ attach_function :hakuban_object_observe_contract_new, [ :pointer, :pointer ], :pointer
100
+ attach_function :hakuban_object_observe_contract_drop, [ :pointer ], :void
101
+ attach_function :hakuban_object_observe_contract_next, [ :pointer ], :pointer
102
+
103
+ attach_function :hakuban_object_expose_contract_new, [ :pointer, :pointer, :uint32 ], :pointer
104
+ attach_function :hakuban_object_expose_contract_drop, [ :pointer ], :void
105
+ attach_function :hakuban_object_expose_contract_next, [ :pointer ], :pointer
106
+
107
+ attach_function :hakuban_tag_observe_contract_new, [ :pointer, :pointer ], :pointer
108
+ attach_function :hakuban_tag_observe_contract_drop, [ :pointer ], :void
109
+ attach_function :hakuban_tag_observe_contract_next, [ :pointer ], :pointer
110
+
111
+ attach_function :hakuban_tag_expose_contract_new, [ :pointer, :pointer, :uint32 ], :pointer
112
+ attach_function :hakuban_tag_expose_contract_drop, [ :pointer ], :void
113
+ attach_function :hakuban_tag_expose_contract_next, [ :pointer ], :pointer
114
+
115
+ attach_function :hakuban_object_state_stream_drop, [ :pointer ], :void
116
+ attach_function :hakuban_object_state_stream_next, [ :pointer ], :pointer
211
117
  attach_function :hakuban_object_state_stream_descriptor, [ :pointer ], :pointer
212
118
 
213
- attach_function :hakuban_object_state_sink_drop, [ :pointer ], :void, blocking: true
214
- attach_function :hakuban_object_state_sink_next, [ :pointer ], FFIFutureReturningPointer.by_value, blocking: true
215
- attach_function :hakuban_object_state_sink_send, [ :pointer, :pointer ], FFIFutureReturningNothing.by_value, blocking: true
216
- attach_function :hakuban_object_state_sink_current, [ :pointer ], FFIResultWithPointer.by_value, blocking: true
119
+ attach_function :hakuban_object_state_sink_drop, [ :pointer ], :void
120
+ attach_function :hakuban_object_state_sink_next, [ :pointer ], :pointer
121
+ attach_function :hakuban_object_state_sink_send, [ :pointer, :pointer ], :pointer
217
122
  attach_function :hakuban_object_state_sink_descriptor, [ :pointer ], :pointer
218
- attach_function :hakuban_object_state_sink_desynchronize, [ :pointer ], :void, blocking: true
219
123
 
220
124
  attach_function :hakuban_object_state_sink_params_drop, [ :pointer ], :void
221
125
  attach_function :hakuban_object_state_sink_params_clone, [ :pointer ], :pointer
222
126
 
223
- attach_function :hakuban_object_state_new, [ :size_t, :pointer, :size_t, :pointer, :size_t, :pointer, :uint64 ], FFIResultWithPointer.by_value
127
+ attach_function :hakuban_object_state_new, [ :size_t, :pointer, :size_t, :pointer, :size_t, :pointer, :uint64 ], FFIResult.by_value
224
128
  attach_function :hakuban_object_state_drop, [ :pointer ], :void
225
129
  attach_function :hakuban_object_state_clone, [ :pointer ], :pointer
226
130
  attach_function :hakuban_object_state_data, [ :pointer ], FFIArray.by_value
@@ -228,23 +132,26 @@ module Hakuban::FFI
228
132
  attach_function :hakuban_object_state_version, [ :pointer ], FFIArray.by_value
229
133
  attach_function :hakuban_object_state_synchronized_ago, [ :pointer ], :uint64
230
134
 
231
- attach_function :hakuban_tag_descriptor_new, [ :string ], FFIResultWithPointer.by_value
135
+ attach_function :hakuban_tag_descriptor_new, [ :string ], FFIResult.by_value
232
136
  attach_function :hakuban_tag_descriptor_drop, [ :pointer ], :void
233
137
  attach_function :hakuban_tag_descriptor_clone, [ :pointer ], :pointer
234
138
  attach_function :hakuban_tag_descriptor_json, [ :pointer ], :string
235
139
 
236
- attach_function :hakuban_object_descriptor_new, [ :string, :size_t, :pointer ], FFIResultWithPointer.by_value
140
+ attach_function :hakuban_object_descriptor_new, [ :string, :size_t, :pointer ], FFIResult.by_value
237
141
  attach_function :hakuban_object_descriptor_drop, [ :pointer ], :void
238
142
  attach_function :hakuban_object_descriptor_clone, [ :pointer ], :pointer
239
143
  attach_function :hakuban_object_descriptor_json, [ :pointer ], :string
240
144
  attach_function :hakuban_object_descriptor_tags, [ :pointer ], FFIArray.by_value
241
145
 
242
- attach_function :hakuban_future_returning_nothing_drop, [ :pointer ], :void, blocking: true
243
- attach_function :hakuban_future_returning_pointer_drop, [ :pointer ], :void, blocking: true
244
- attach_function :hakuban_future_returning_nothing_poll, [ :pointer, :waker, :pointer ], FFIResultWithNothing.by_value, blocking: true
245
- attach_function :hakuban_future_returning_pointer_poll, [ :pointer, :waker, :pointer ], FFIResultWithPointer.by_value, blocking: true
146
+ attach_function :hakuban_future_clone, [ :pointer ], :pointer
147
+ attach_function :hakuban_future_drop, [ :pointer ], :void
148
+ #attach_function :hakuban_future_poll, [ :pointer, :waker, :pointer ], FFIResult.by_value #this is pita to get working right with interrupts, and without leaking memory in weird cases
149
+ attach_function :hakuban_future_await, [ :pointer ], FFIResult.by_value, blocking: true
246
150
 
247
151
  attach_function :hakuban_array_drop, [ FFIArray.by_value ], :void
248
152
 
153
+ FFIResultStatus.freeze
154
+ FFIResult.freeze
155
+ FFIFuture.freeze
156
+ freeze
249
157
  end
250
-
@@ -5,10 +5,10 @@ module Hakuban
5
5
  def self.logger_initialize(default_level, skip_if_already_initialized: false)
6
6
  Hakuban::hakuban_initialize
7
7
  if @@logger_initialized and !skip_if_already_initialized
8
- raise "Logger already initialized. This can't be done more than once. Make sure logger_initialize is called before any LocalExchange gets constructed."
8
+ raise "Logger already initialized. This can't be done more than once. Make sure logger_initialize is called before any Exchange gets constructed."
9
9
  end
10
10
  if not @@logger_initialized
11
- raise "Invalid default log level string" if ! FFI::hakuban_logger_initialize(default_level).is_Ok?
11
+ raise "Invalid default log level string" if FFI::hakuban_logger_initialize(default_level).status != :Ok
12
12
  @@logger_initialized = true
13
13
  end
14
14
  end