Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use msg_process_t instead of m_process_t
[simgrid.git] / src / bindings / lua / lua_task.c
index 0305642..1326b2a 100644 (file)
@@ -192,8 +192,8 @@ void sglua_task_unregister(lua_State* L, m_task_t task) {
  * \param src_process the sender
  * \param dst_process the receiver
  */
-static void task_copy_callback(m_task_t task, m_process_t src_process,
-    m_process_t dst_process) {
+static void task_copy_callback(m_task_t task, msg_process_t src_process,
+    msg_process_t dst_process) {
 
   lua_State* src = MSG_process_get_data(src_process);
   lua_State* dst = MSG_process_get_data(dst_process);
@@ -205,7 +205,8 @@ static void task_copy_callback(m_task_t task, m_process_t src_process,
   sglua_copy_value(src, dst);
                                   /* src: ... task
                                      dst: ... task */
-  sglua_task_register(dst);             /* dst: ... */
+  sglua_task_register(dst);
+                                  /* dst: ... */
 
   /* the receiver is now the owner of the task and may destroy it:
    * make the sender forget the C task so that it doesn't garbage */
@@ -225,6 +226,7 @@ static void task_copy_callback(m_task_t task, m_process_t src_process,
  * - Argument 1 (task): the task to send
  * - Argument 2 (string or compatible): mailbox name, as a real string or any
  * type convertible to string (numbers always are)
+ * - Argument 3 (number, optional): timeout (default is no timeout)
  * - Return values (boolean + string): true if the communication was successful,
  * or false plus an error string in case of failure, which may be "timeout",
  * "host failure" or "transfer failure"
@@ -233,12 +235,19 @@ static int l_task_send(lua_State* L)
 {
   m_task_t task = sglua_check_task(L, 1);
   const char* mailbox = luaL_checkstring(L, 2);
-                                  /* task mailbox ... */
+  double timeout;
+  if (lua_gettop(L) >= 3) {
+    timeout = luaL_checknumber(L, 3);
+  }
+  else {
+    timeout = -1;
+    /* no timeout by default */
+  }
   lua_settop(L, 1);
                                   /* task */
   sglua_task_register(L);
                                   /* -- */
-  MSG_error_t res = MSG_task_send(task, mailbox);
+  MSG_error_t res = MSG_task_send_with_timeout(task, mailbox, timeout);
 
   if (res == MSG_OK) {
     lua_pushboolean(L, 1);
@@ -329,7 +338,7 @@ static int l_task_recv(lua_State* L)
 {
   m_task_t task = NULL;
   const char* mailbox = luaL_checkstring(L, 1);
-  int timeout;
+  double timeout;
   if (lua_gettop(L) >= 2) {
                                   /* mailbox timeout ... */
     timeout = luaL_checknumber(L, 2);