Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d7fa359e6b04b00f81430f68f228584b3210547c
[simgrid.git] / src / msg / private.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2002,2004,2004 Arnaud Legrand. All rights reserved.        */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef METASIMGRID_PRIVATE_H
9 #define METASIMGRID_PRIVATE_H
10
11 #include "msg/msg.h"
12 #include "surf/surf.h"
13 #include "xbt/fifo.h"
14 #include "xbt/dynar.h"
15 #include "xbt/swag.h"
16 #include "xbt/dict.h"
17 #include "xbt/context.h"
18
19 /**************** datatypes **********************************/
20
21 typedef struct simdata_host {
22   void *host;                   /* SURF modeling */
23   xbt_fifo_t *mbox;             /* array of FIFOs used as a mailboxes  */
24   m_process_t *sleeping;        /* array of process used to know whether a local process is
25                                    waiting for a communication on a channel */
26   xbt_fifo_t process_list;
27 } s_simdata_host_t;
28
29 /********************************* Task **************************************/
30
31 typedef struct simdata_task {
32   surf_action_t compute;        /* SURF modeling of computation  */
33   surf_action_t comm;           /* SURF modeling of communication  */
34   double message_size;          /* Data size  */
35   double computation_amount;    /* Computation size  */
36   xbt_dynar_t sleeping;         /* process to wake-up */
37   m_process_t sender;
38   int using;
39 } s_simdata_task_t;
40
41 /******************************* Process *************************************/
42
43 typedef struct simdata_process {
44   m_host_t host;                /* the host on which the process is running */
45   xbt_context_t context;                /* the context that executes the scheduler fonction */
46   int PID;                      /* used for debugging purposes */
47   int PPID;                     /* The parent PID */
48   m_task_t waiting_task;        
49   int blocked;
50   int suspended;
51   m_host_t put_host;            /* used for debugging purposes */
52   m_channel_t put_channel;      /* used for debugging purposes */
53   int argc;                     /* arguments number if any */
54   char **argv;                  /* arguments table if any */
55   MSG_error_t last_errno;       /* the last value returned by a MSG_function */
56 } s_simdata_process_t;
57
58 /************************** Global variables ********************************/
59 typedef struct MSG_Global {
60   xbt_fifo_t host;
61   xbt_fifo_t process_to_run;
62   xbt_fifo_t process_list;
63   int max_channel;
64   m_process_t current_process;
65   xbt_dict_t registered_functions;
66 } s_MSG_Global_t, *MSG_Global_t;
67
68 extern MSG_Global_t msg_global;
69
70 /*************************************************************/
71
72 #define PROCESS_SET_ERRNO(val) (MSG_process_self()->simdata->last_errno=val)
73 #define PROCESS_GET_ERRNO() (MSG_process_self()->simdata->last_errno)
74 #define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
75 /* #define CHECK_ERRNO()  ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */
76
77 #define CHECK_HOST()  xbt_assert0(surf_workstation_resource->extension_public-> \
78                                   get_state(MSG_host_self()->simdata->host)==SURF_CPU_ON,\
79                                   "Host failed, you cannot call this function.")
80
81 m_host_t __MSG_host_create(const char *name, void *workstation,
82                            void *data);
83 void __MSG_host_destroy(m_host_t host);
84 void __MSG_task_execute(m_process_t process, m_task_t task);
85 MSG_error_t __MSG_wait_for_computation(m_process_t process, m_task_t task);
86 MSG_error_t __MSG_task_wait_event(m_process_t process, m_task_t task);
87
88 MSG_error_t __MSG_process_block(void);
89 MSG_error_t __MSG_process_unblock(m_process_t process);
90 int __MSG_process_isBlocked(m_process_t process);
91
92 #endif