- return '''
-inline static %s simcall_BODY_%s(%s) {
- smx_process_t self = SIMIX_process_self();
-
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) simcall_HANDLER_%s(%s);
- /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
+ res = [' ']
+ res.append('inline static %s simcall_BODY_%s(%s) {'%(self.res.rettype(),
+ self.name,
+ ', '.join('%s %s'%(arg.rettype(), arg.name) for arg in self.args)))
+ res.append(' smx_process_t self = SIMIX_process_self();')
+ res.append('')
+ res.append(' /* Go to that function to follow the code flow through the simcall barrier */')
+ if self.need_handler:
+ res.append(' if (0) simcall_HANDLER_%s(%s);'%(self.name,
+ ', '.join(["&self->simcall"]+ [arg.name for arg in self.args])))
+ else:
+ res.append(' if (0) SIMIX_%s(%s);'%(self.name,
+ ', '.join(arg.name for arg in self.args)))
+ res.append(' /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */')
+ res.append('')
+ res.append(' self->simcall.call = SIMCALL_%s;'%(self.name.upper()))
+ res.append(' memset(&self->simcall.result, 0, sizeof(self->simcall.result));')
+ res.append(' memset(self->simcall.args, 0, sizeof(self->simcall.args));')
+ res.append('\n'.join(' self->simcall.args[%d].%s = (%s) %s;'%(i, arg.field(), arg.type, arg.name)
+ for i, arg in enumerate(self.args)))
+ res.append(' if (self != simix_global->maestro_process) {')
+ res.append(' XBT_DEBUG("Yield process \'%s\' on simcall %s (%d)", self->name,')
+ res.append(' SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);')
+ res.append(' SIMIX_process_yield(self);')
+ res.append(' } else {')
+ res.append(' SIMIX_simcall_handle(&self->simcall, 0);')
+ res.append(' } ')
+ if self.res.type != 'void':
+ res.append(' return self->simcall.result.%s;'%self.res.field())
+ else:
+ res.append(' ')
+ res.append(' }')
+ return '\n'.join(res)