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.



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

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.



139
140
141
# File 'ext/generate_gvl_code.rb', line 139

def name
  @name
end

#structObject (readonly)

Returns the value of attribute struct.



139
140
141
# File 'ext/generate_gvl_code.rb', line 139

def struct
  @struct
end

#wrapper_fnObject (readonly)

Returns the value of attribute wrapper_fn.



139
140
141
# File 'ext/generate_gvl_code.rb', line 139

def wrapper_fn
  @wrapper_fn
end

#zoo_fn_nameObject (readonly)

Returns the value of attribute zoo_fn_name.



139
140
141
# File 'ext/generate_gvl_code.rb', line 139

def zoo_fn_name
  @zoo_fn_name
end

Instance Method Details

#bodyObject



178
179
180
# File 'ext/generate_gvl_code.rb', line 178

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

#bottomObject



170
171
172
173
174
175
176
# File 'ext/generate_gvl_code.rb', line 170

def bottom
  <<-EOS

return args.rc;
}
  EOS
end

#fn_signatureObject



147
148
149
# File 'ext/generate_gvl_code.rb', line 147

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

#initializer_linesObject



151
152
153
# File 'ext/generate_gvl_code.rb', line 151

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

#rb_thread_blocking_region_callObject



166
167
168
# File 'ext/generate_gvl_code.rb', line 166

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

#topObject



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

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