+ smx_action_t action;
+ smx_host_t host = process->smx_host;
+
+ /* check if the host is active */
+ if (surf_workstation_model->extension.
+ workstation.get_state(host->host) != SURF_RESOURCE_ON) {
+ THROWF(host_error, 0, "Host %s failed, you cannot call this function",
+ host->name);
+ }
+
+ action = xbt_mallocator_get(simix_global->action_mallocator);
+ action->type = SIMIX_ACTION_SLEEP;
+ action->name = NULL;
+#ifdef HAVE_TRACING
+ action->category = NULL;
+#endif
+
+ action->sleep.host = host;
+ action->sleep.surf_sleep =
+ surf_workstation_model->extension.workstation.sleep(host->host, duration);
+
+ surf_workstation_model->action_data_set(action->sleep.surf_sleep, action);
+ XBT_DEBUG("Create sleep action %p", action);
+
+ return action;
+}
+
+void SIMIX_post_process_sleep(smx_action_t action)
+{
+ smx_req_t req;
+ e_smx_state_t state;
+
+ while ((req = xbt_fifo_shift(action->request_list))) {
+
+ switch(surf_workstation_model->action_state_get(action->sleep.surf_sleep)){
+ case SURF_ACTION_FAILED:
+ state = SIMIX_SRC_HOST_FAILURE;
+ break;
+
+ case SURF_ACTION_DONE:
+ state = SIMIX_DONE;
+ break;
+
+ default:
+ THROW_IMPOSSIBLE;
+ break;
+ }
+ req->process_sleep.result = state;
+ req->issuer->waiting_action = NULL;
+ SIMIX_request_answer(req);
+ }
+ SIMIX_process_sleep_destroy(action);
+}
+
+void SIMIX_process_sleep_destroy(smx_action_t action)
+{
+ XBT_DEBUG("Destroy action %p", action);
+ if (action->sleep.surf_sleep)
+ action->sleep.surf_sleep->model_type->action_unref(action->sleep.surf_sleep);
+ xbt_mallocator_release(simix_global->action_mallocator, action);
+}
+
+void SIMIX_process_sleep_suspend(smx_action_t action)
+{
+ surf_workstation_model->suspend(action->sleep.surf_sleep);
+}
+
+void SIMIX_process_sleep_resume(smx_action_t action)
+{
+ surf_workstation_model->resume(action->sleep.surf_sleep);
+}
+
+/**
+ * Calling this function makes the process to yield.
+ * Only the processes can call this function, giving back the control to maestro
+ */
+void SIMIX_process_yield(void)
+{
+ smx_process_t self = SIMIX_process_self();
+
+ XBT_DEBUG("Yield process '%s'", self->name);
+
+ /* Go into sleep and return control to maestro */
+ SIMIX_context_suspend(self->context);
+
+ /* Ok, maestro returned control to us */
+ XBT_DEBUG("Maestro returned control to me: '%s'", self->name);
+
+ if (self->context->iwannadie){
+ XBT_DEBUG("I wanna die!");
+ SIMIX_context_stop(self->context);
+ }
+
+ if (self->doexception) {
+ XBT_DEBUG("Wait, maestro left me an exception");
+ self->doexception = 0;
+ RETHROW;
+ }
+
+ if (self->new_host) {
+ SIMIX_process_change_host(self, self->new_host);
+ self->new_host = NULL;
+ }
+}
+
+/* callback: context fetching */
+xbt_running_ctx_t *SIMIX_process_get_running_context(void)
+{
+ return SIMIX_process_self()->running_ctx;
+}
+
+/* callback: termination */
+void SIMIX_process_exception_terminate(xbt_ex_t * e)
+{
+ xbt_ex_display(e);
+ abort();
+}
+
+smx_context_t SIMIX_process_get_context(smx_process_t p) {
+ return p->context;
+}
+
+void SIMIX_process_set_context(smx_process_t p,smx_context_t c) {
+ p->context = c;