Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8be954c18d59c64d3f20248e286aaf89d9dd4c2c
[simgrid.git] / src / simix / smx_action.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
4    All rights reserved.                                          */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "private.h"
10 #include "xbt/log.h"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_action, simix,
13                                 "Logging specific to SIMIX (action)");
14
15 /************************************* Actions *********************************/
16
17 smx_action_t SIMIX_communicate(smx_host_t sender,smx_host_t receiver, double size)
18 {
19         return xbt_new0(s_smx_action_t,1);
20 }
21
22 smx_action_t SIMIX_execute(smx_host_t host,double amount)
23 {
24         return xbt_new0(s_smx_action_t,1);
25 }
26
27 SIMIX_error_t SIMIX_action_cancel(smx_action_t action)
28 {
29
30         return SIMIX_OK;
31 }
32
33 void SIMIX_action_set_priority(smx_action_t action, double priority)
34 {
35         return;
36 }
37
38 SIMIX_error_t SIMIX_action_destroy(smx_action_t action)
39 {
40         return SIMIX_OK;
41 }
42
43 void SIMIX_create_link(smx_action_t action, smx_cond_t cond)
44 {
45
46 }
47
48 SIMIX_error_t __SIMIX_wait_for_action(smx_process_t process, smx_action_t action)
49 {
50         e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM;
51         simdata_action_t simdata = action->simdata;
52
53         xbt_assert0(((process != NULL) && (action != NULL) && (action->simdata != NULL)), "Invalid parameters");
54         
55         /* change context while the action is running  */
56         do {
57                 xbt_context_yield();
58                 state=surf_workstation_resource->common_public->action_get_state(simdata->surf_action);
59         } while (state==SURF_ACTION_RUNNING);
60         
61         /* action finished, we can continue */
62
63         if(state == SURF_ACTION_DONE) {
64                 if(surf_workstation_resource->common_public->action_free(simdata->surf_action)) 
65                         simdata->surf_action = NULL;
66                 SIMIX_RETURN(SIMIX_OK);
67         } else if(surf_workstation_resource->extension_public->
68                         get_state(SIMIX_process_get_host(process)->simdata->host) 
69                         == SURF_CPU_OFF) {
70                 if(surf_workstation_resource->common_public->action_free(simdata->surf_action)) 
71                         simdata->surf_action = NULL;
72                 SIMIX_RETURN(SIMIX_HOST_FAILURE);
73         } else {
74                 if(surf_workstation_resource->common_public->action_free(simdata->surf_action)) 
75                         simdata->surf_action = NULL;
76                 SIMIX_RETURN(SIMIX_ACTION_CANCELLED);
77         }
78
79 }