Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Since cmake 2.6, else() and endif() don't need to repeat the condition.
[simgrid.git] / examples / gras / mutual_exclusion / simple_token / simple_token.c
index 686d7ec..ef80458 100644 (file)
@@ -24,10 +24,10 @@ int node(int argc, char *argv[]);
 
 /* Global private data */
 typedef struct {
-  gras_socket_t sock;           /* server socket on which I hear */
+  xbt_socket_t sock;           /* server socket on which I hear */
   int remaining_loop;           /* number of loops to do until done */
   int create;                   /* whether I have to create the token */
-  gras_socket_t tosuccessor;    /* how to connect to the successor on ring */
+  xbt_socket_t tosuccessor;    /* how to connect to the successor on ring */
   double start_time;            /* to measure the elapsed time. Only used by the 
                                    node that creates the token */
 } node_data_t;
@@ -36,12 +36,9 @@ typedef struct {
 /* Callback function */
 static int node_cb_stoken_handler(gras_msg_cb_ctx_t ctx, void *payload)
 {
-
-  xbt_ex_t e;
-
   /* 1. Get the payload into the msg variable, and retrieve my caller */
   int msg = *(int *) payload;
-  gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx);
+  xbt_socket_t expeditor = gras_msg_cb_ctx_from(ctx);
 
 
   /* 2. Retrieve the node's state (globals) */
@@ -60,7 +57,7 @@ static int node_cb_stoken_handler(gras_msg_cb_ctx_t ctx, void *payload)
     XBT_INFO("Begin a new loop. Still to do: %d", globals->remaining_loop);
   } else if (!(globals->remaining_loop % supersteps)) {
     XBT_VERB("Got token(%d) from %s remaining_loop=%d",
-          msg, gras_socket_peer_name(expeditor), globals->remaining_loop);
+          msg, xbt_socket_peer_name(expeditor), globals->remaining_loop);
   }
 
   /* 4. If the right shouldn't be stopped yet */
@@ -68,8 +65,8 @@ static int node_cb_stoken_handler(gras_msg_cb_ctx_t ctx, void *payload)
     msg += 1;
 
     XBT_DEBUG("Send token(%d) to %s:%d", msg,
-           gras_socket_peer_name(globals->tosuccessor),
-           gras_socket_peer_port(globals->tosuccessor));
+           xbt_socket_peer_name(globals->tosuccessor),
+           xbt_socket_peer_port(globals->tosuccessor));
 
     /* 5. Send the token as payload of a stoken message to the successor */
     TRY {
@@ -77,9 +74,9 @@ static int node_cb_stoken_handler(gras_msg_cb_ctx_t ctx, void *payload)
 
       /* 6. Deal with errors */
     }
-    CATCH(e) {
+    CATCH_ANONYMOUS {
       gras_socket_close(globals->sock);
-      RETHROW0("Unable to forward token: %s");
+      RETHROWF("Unable to forward token: %s");
     }
 
   }
@@ -110,8 +107,6 @@ int node(int argc, char *argv[])
   int myport;
   int peerport;
 
-  xbt_ex_t e;
-
   /* 1. Init the GRAS infrastructure and declare my globals */
   gras_init(&argc, argv);
   globals = gras_userdata_new(node_data_t);
@@ -138,7 +133,7 @@ int node(int argc, char *argv[])
           myport, host, peerport);
 
   /* 4. Register the known messages.  */
-  gras_msgtype_declare("stoken", gras_datadesc_by_name("int"));
+  gras_msgtype_declare("stoken", xbt_datadesc_by_name("int"));
 
   /* 5. Create my master socket for listening */
   globals->sock = gras_socket_server(myport);
@@ -170,12 +165,13 @@ int node(int argc, char *argv[])
 
     TRY {
       gras_msg_send(globals->tosuccessor, "stoken", &token);
-    } CATCH(e) {
-      RETHROW0("Unable to send the freshly created token: %s");
+    }
+    CATCH_ANONYMOUS {
+      RETHROWF("Unable to send the freshly created token: %s");
     }
   }
 
-  /* 8. Wait up to 10 seconds for an incomming message to handle */
+  /* 8. Wait up to 10 seconds for an incoming message to handle */
   while (globals->remaining_loop > (globals->create ? -1 : 0)) {
     gras_msg_handle(-1);