Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Stringify e_smx_req_t just by using macros (remove the special header)
[simgrid.git] / src / simix / smurf_private.h
index 3a31142..0a0bcd8 100644 (file)
 #define _SIMIX_SMURF_PRIVATE_H
 
 /********************************* Requests ***********************************/
-typedef enum {
-  REQ_HOST_GET_BY_NAME,
-  REQ_HOST_GET_NAME,
-  REQ_HOST_GET_PROPERTIES,
-  REQ_HOST_GET_SPEED,
-  REQ_HOST_GET_AVAILABLE_SPEED,
-  REQ_HOST_GET_STATE,
-  REQ_HOST_GET_DATA,
-  REQ_HOST_SET_DATA,
-  REQ_HOST_EXECUTE,
-  REQ_HOST_PARALLEL_EXECUTE,
-  REQ_HOST_EXECUTION_DESTROY,
-  REQ_HOST_EXECUTION_CANCEL,
-  REQ_HOST_EXECUTION_GET_REMAINS,
-  REQ_HOST_EXECUTION_GET_STATE,
-  REQ_HOST_EXECUTION_SET_PRIORITY,
-  REQ_HOST_EXECUTION_WAIT,
-  REQ_PROCESS_CREATE,
-  REQ_PROCESS_KILL,
-  REQ_PROCESS_CHANGE_HOST,
-  REQ_PROCESS_SUSPEND,
-  REQ_PROCESS_RESUME,
-  REQ_PROCESS_COUNT,
-  REQ_PROCESS_GET_DATA,
-  REQ_PROCESS_SET_DATA,
-  REQ_PROCESS_GET_HOST,
-  REQ_PROCESS_GET_NAME,
-  REQ_PROCESS_IS_SUSPENDED,
-  REQ_PROCESS_GET_PROPERTIES,
-  REQ_PROCESS_SLEEP,
-  REQ_RDV_CREATE,
-  REQ_RDV_DESTROY,
-  REQ_RDV_GEY_BY_NAME,
-  REQ_RDV_COMM_COUNT_BY_HOST,
-  REQ_RDV_GET_HEAD,
-  REQ_COMM_ISEND,
-  REQ_COMM_IRECV,
-  REQ_COMM_DESTROY,
-  REQ_COMM_CANCEL,
-  REQ_COMM_WAITANY,
-  REQ_COMM_WAIT,
-  REQ_COMM_TEST,
-  REQ_COMM_GET_REMAINS,
-  REQ_COMM_GET_STATE,
-  REQ_COMM_GET_DATA,
-  REQ_COMM_GET_SRC_BUFF,
-  REQ_COMM_GET_DST_BUFF,
-  REQ_COMM_GET_SRC_BUFF_SIZE,
-  REQ_COMM_GET_DST_BUFF_SIZE,
-  REQ_COMM_GET_SRC_PROC,
-  REQ_COMM_GET_DST_PROC,
+
+/* we want to build the e_smx_t enumeration and the table of the corresponding
+ * strings automatically, using macros */
+
+#define SIMIX_REQ_LIST1 \
+SIMIX_REQ_ENUM_ELEMENT(REQ_NO_REQ),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_BY_NAME),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_NAME),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_PROPERTIES),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_SPEED),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_AVAILABLE_SPEED),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_STATE),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_DATA),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_SET_DATA),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTE),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_PARALLEL_EXECUTE),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_DESTROY),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_CANCEL),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_GET_REMAINS),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_GET_STATE),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_SET_PRIORITY),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_WAIT),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_CREATE),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_KILL),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_CHANGE_HOST),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SUSPEND),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_RESUME),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_COUNT),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_DATA),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SET_DATA),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_HOST),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_NAME),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_IS_SUSPENDED),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_PROPERTIES),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SLEEP),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_CREATE),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_DESTROY),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_GEY_BY_NAME),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_COMM_COUNT_BY_HOST),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_GET_HEAD),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_ISEND),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_IRECV),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_DESTROY),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_CANCEL),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_WAITANY),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_WAIT),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_TEST),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_TESTANY),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_REMAINS),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_STATE),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_DATA),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_DATA),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_BUFF),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_BUFF),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_BUFF_SIZE),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_BUFF_SIZE),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_PROC),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_PROC),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_INIT),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_DESTROY),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_LOCK),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_TRYLOCK),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_UNLOCK),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COND_INIT),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COND_DESTROY),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COND_SIGNAL),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COND_WAIT),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COND_WAIT_TIMEOUT),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_COND_BROADCAST),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_INIT),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_DESTROY),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_RELEASE),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_WOULD_BLOCK),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE_TIMEOUT),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_GET_CAPACITY)
+
+/* REQ_COMM_IS_LATENCY_BOUNDED and REQ_SET_CATEGORY make things complicated
+ * because they are not always present */
 #ifdef HAVE_LATENCY_BOUND_TRACKING
-  REQ_COMM_IS_LATENCY_BOUNDED,
+#define SIMIX_REQ_LIST2 \
+,SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_IS_LATENCY_BOUNDED)
+#else
+#define SIMIX_REQ_LIST2
 #endif
-  REQ_MUTEX_INIT,
-  REQ_MUTEX_DESTROY,
-  REQ_MUTEX_LOCK,
-  REQ_MUTEX_TRYLOCK,
-  REQ_MUTEX_UNLOCK,
-  REQ_COND_INIT,
-  REQ_COND_DESTROY,
-  REQ_COND_SIGNAL,
-  REQ_COND_WAIT,
-  REQ_COND_WAIT_TIMEOUT,
-  REQ_COND_BROADCAST,
-  REQ_SEM_INIT,
-  REQ_SEM_DESTROY,
-  REQ_SEM_RELEASE,
-  REQ_SEM_WOULD_BLOCK,
-  REQ_SEM_ACQUIRE,
-  REQ_SEM_ACQUIRE_TIMEOUT,
-  REQ_SEM_GET_CAPACITY
+
+#ifdef HAVE_TRACING
+#define SIMIX_REQ_LIST3 \
+,SIMIX_REQ_ENUM_ELEMENT(REQ_SET_CATEGORY)
+#else
+#define SIMIX_REQ_LIST3
+#endif
+
+/* SIMIX_REQ_LIST is the final macro to use */
+#define SIMIX_REQ_LIST SIMIX_REQ_LIST1 SIMIX_REQ_LIST2 SIMIX_REQ_LIST3
+
+/* you can redefine the following macro differently to generate something else
+ * with the list of enumeration values (e.g. a table of strings or a table of function pointers) */
+#define SIMIX_REQ_ENUM_ELEMENT(x) x
+
+/**
+ * \brief All possible SIMIX requests.
+ */
+typedef enum {
+SIMIX_REQ_LIST
 } e_smx_req_t;
 
+/**
+ * \brief Represents a SIMIX request.
+ */
 typedef struct s_smx_req {
   s_xbt_swag_hookup_t state_hookup;
   e_smx_req_t call;
@@ -255,7 +291,7 @@ typedef struct s_smx_req {
       const char* name;
       smx_rdv_t result;
     } rdv_get_by_name;
-    
+
     struct {
       smx_rdv_t rdv;
       smx_host_t host;
@@ -266,21 +302,24 @@ typedef struct s_smx_req {
       smx_rdv_t rdv;
       smx_action_t result;
     } rdv_get_head;
+
     struct {
       smx_rdv_t rdv;
       double task_size;
       double rate;
       void *src_buff;
       size_t src_buff_size;
+      int (*match_fun)(void *, void *);
       void *data;
-      smx_action_t result;      
+      smx_action_t result;
     } comm_isend;
 
     struct {
       smx_rdv_t rdv;
       void *dst_buff;
       size_t *dst_buff_size;
+      int (*match_fun)(void *, void *);
+         void *data;
       smx_action_t result;
     } comm_irecv;
 
@@ -291,12 +330,12 @@ typedef struct s_smx_req {
     struct {
       smx_action_t comm;
     } comm_cancel;
+
     struct {
       xbt_dynar_t comms;
       unsigned int result;
     } comm_waitany;
+
     struct {
       smx_action_t comm;
       double timeout;
@@ -307,46 +346,56 @@ typedef struct s_smx_req {
       int result;
     } comm_test;
 
+    struct {
+      xbt_dynar_t comms;
+      int result;
+    } comm_testany;
+
     struct {
       smx_action_t comm;
       double result;
     } comm_get_remains;
+
     struct {
       smx_action_t comm;
       e_smx_state_t result;
     } comm_get_state;
+
     struct {
       smx_action_t comm;
-      void *result;    
-    } comm_get_data;
+      void *result;
+    } comm_get_src_data;
+
+    struct {
+      smx_action_t comm;
+      void *result;
+    } comm_get_dst_data;
+
     struct {
       smx_action_t comm;
       void *result;
     } comm_get_src_buff;
+
     struct {
       smx_action_t comm;
       void *result;
     } comm_get_dst_buff;
-    
+
     struct {
       smx_action_t comm;
       size_t result;
     } comm_get_src_buff_size;
-    
+
     struct {
       smx_action_t comm;
       size_t result;
     } comm_get_dst_buff_size;
-    
+
     struct {
       smx_action_t comm;
       smx_process_t result;
     } comm_get_src_proc;
-    
+
     struct {
       smx_action_t comm;
       smx_process_t result;
@@ -359,6 +408,13 @@ typedef struct s_smx_req {
     } comm_is_latency_bounded;
 #endif
 
+#ifdef HAVE_TRACING
+    struct {
+      smx_action_t action;
+      const char *category;
+    } set_category;
+#endif
+
     struct {
       smx_mutex_t result;
     } mutex_init;
@@ -445,12 +501,12 @@ typedef struct s_smx_req {
 
 void SIMIX_request_init(void);
 void SIMIX_request_destroy(void);
-void SIMIX_request_push(smx_req_t);
+void SIMIX_request_push(void);
 smx_req_t SIMIX_request_pop(void);
 void SIMIX_request_answer(smx_req_t);
-void SIMIX_request_pre(smx_req_t);
+void SIMIX_request_pre(smx_req_t, int);
 void SIMIX_request_post(smx_action_t);
-int SIMIX_request_isVisible(smx_req_t req);
-int SIMIX_request_isEnabled(smx_req_t req);
+XBT_INLINE smx_req_t SIMIX_req_mine(void);
+
 #endif