Class: CallingFunction

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
MemberNames
Defined in:
ext/generate_gvl_code.rb

Overview

the zkrb_call_zoo_* function

Constant Summary collapse

PREFIX =
'zkrb_call'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MemberNames

#member_names

Constructor Details

#initialize(zoo_fn_name, struct, wrapper_fn) ⇒ CallingFunction

Returns a new instance of CallingFunction.



143
144
145
146
147
# File 'ext/generate_gvl_code.rb', line 143

def initialize(zoo_fn_name, struct, wrapper_fn)
  @zoo_fn_name, @struct, @wrapper_fn = zoo_fn_name, struct, wrapper_fn

  @name = "#{PREFIX}_#{zoo_fn_name}"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



141
142
143
# File 'ext/generate_gvl_code.rb', line 141

def name
  @name
end

#structObject (readonly)

Returns the value of attribute struct.



141
142
143
# File 'ext/generate_gvl_code.rb', line 141

def struct
  @struct
end

#wrapper_fnObject (readonly)

Returns the value of attribute wrapper_fn.



141
142
143
# File 'ext/generate_gvl_code.rb', line 141

def wrapper_fn
  @wrapper_fn
end

#zoo_fn_nameObject (readonly)

Returns the value of attribute zoo_fn_name.



141
142
143
# File 'ext/generate_gvl_code.rb', line 141

def zoo_fn_name
  @zoo_fn_name
end

Instance Method Details

#bodyObject



180
181
182
# File 'ext/generate_gvl_code.rb', line 180

def body
  @body ||= [top, rb_thread_blocking_region_call, bottom].join("\n")
end

#bottomObject



172
173
174
175
176
177
178
# File 'ext/generate_gvl_code.rb', line 172

def bottom
  <<-EOS

return args.rc;
}
  EOS
end

#fn_signatureObject



149
150
151
# File 'ext/generate_gvl_code.rb', line 149

def fn_signature
  @fn_signature ||= "int #{name}(#{typed_args.join(', ')})"
end

#initializer_linesObject



153
154
155
# File 'ext/generate_gvl_code.rb', line 153

def initializer_lines
  @initializer_lines ||= member_names.map { |n| "    .#{n} = #{n}" }.join(",\n")
end

#rb_thread_blocking_region_callObject



168
169
170
# File 'ext/generate_gvl_code.rb', line 168

def rb_thread_blocking_region_call
  "  zkrb_thread_blocking_region(#{wrapper_fn.name}, (void *)&args);"
end

#topObject



157
158
159
160
161
162
163
164
165
166
# File 'ext/generate_gvl_code.rb', line 157

def top
  <<-EOS
// wrapper that calls #{zoo_fn_name} via #{wrapper_fn.name} inside rb_thread_blocking_region
#{fn_signature} {
#{struct.name} args = {
  .rc = ZKRB_FAIL,
#{initializer_lines}
};
  EOS
end