[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r28742 - msh/src
From: |
gnunet |
Subject: |
[GNUnet-SVN] r28742 - msh/src |
Date: |
Wed, 21 Aug 2013 14:07:11 +0200 |
Author: harsha
Date: 2013-08-21 14:07:11 +0200 (Wed, 21 Aug 2013)
New Revision: 28742
Modified:
msh/src/mshd.c
msh/src/mtypes.h
Log:
terminate after finishing the main task
Modified: msh/src/mshd.c
===================================================================
--- msh/src/mshd.c 2013-08-21 11:29:03 UTC (rev 28741)
+++ msh/src/mshd.c 2013-08-21 12:07:11 UTC (rev 28742)
@@ -23,6 +23,12 @@
GNUNET_log_from_strerror (kind, "mshd", cmd)
/**
+ * Polling interval for checking termination signal
+ */
+#define POLL_SHUTDOWN_INTERVAL \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
+
+/**
* Context for verifying addresses
*/
struct VerifyAddressesCtx
@@ -249,6 +255,11 @@
GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
/**
+ * Shutdown polling task
+ */
+GNUNET_SCHEDULER_TaskIdentifier poll_shutdown_task;
+
+/**
* Random hashcode for authentication
*/
struct GNUNET_HashCode shash;
@@ -420,6 +431,64 @@
/**
+ * Task to check if we received a shutdown signal through MPI message from
+ * instance 0. This task is to be run every 500ms
+ *
+ * @param cls NULL
+ * @param tc scheduler task context
+ */
+static void
+poll_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ MPI_Status status;
+ int flag;
+
+ poll_shutdown_task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
+ return;
+ flag = 0;
+ if (MPI_SUCCESS != MPI_Iprobe(0, MSH_MTYPE_SHUTDOWN, MPI_COMM_WORLD, &flag,
+ MPI_STATUS_IGNORE))
+ {
+ GNUNET_break (0);
+ goto reschedule;
+ }
+ if (0 == flag)
+ goto reschedule;
+ LOG_DEBUG ("Got termination signal. Shutting down\n");
+ GNUNET_SCHEDULER_shutdown (); /* We terminate */
+ return;
+
+ reschedule:
+ poll_shutdown_task = GNUNET_SCHEDULER_add_delayed (POLL_SHUTDOWN_INTERVAL,
+ &poll_shutdown, NULL);
+}
+
+
+/**
+ * Sends termination signal to all other instances through MPI messaging
+ */
+static void
+send_term_signal ()
+{
+ unsigned int cnt;
+ MPI_Request *req;
+
+ /* We broadcase termination signal. Can't use MPI_Bcast here... */
+ req = GNUNET_malloc (sizeof (MPI_Request) * (nproc - 1));
+ for (cnt = 1; cnt < nproc; cnt++)
+ {
+ GNUNET_assert (MPI_SUCCESS ==
+ MPI_Isend (&cnt, 1, MPI_INT, cnt, MSH_MTYPE_SHUTDOWN,
+ MPI_COMM_WORLD, &req[cnt - 1]));
+ }
+ GNUNET_assert (MPI_SUCCESS == MPI_Waitall (nproc - 1, req,
+ MPI_STATUSES_IGNORE));
+ GNUNET_free (req);
+}
+
+
+/**
* Callbacks of this type can be supplied to MSH_monitor_process() to be
* notified when the corresponding processes exits.
*
@@ -432,8 +501,9 @@
{
GNUNET_OS_process_destroy (proc);
proc = NULL;
- LOG (GNUNET_ERROR_TYPE_INFO, "Main process died. Exiting.\n");
+ LOG (GNUNET_ERROR_TYPE_INFO, "Main process died. Exiting.\n");
GNUNET_SCHEDULER_shutdown ();
+ send_term_signal ();
}
@@ -500,10 +570,14 @@
{
LOG_ERROR ("Unable to start process `%s'\n", run_args[0]);
GNUNET_SCHEDULER_shutdown ();
+ send_term_signal ();
return;
}
MSH_monitor_process (proc, &proc_exit_cb, NULL);
+ return;
}
+ poll_shutdown_task = GNUNET_SCHEDULER_add_delayed (POLL_SHUTDOWN_INTERVAL,
+ &poll_shutdown, NULL);
}
Modified: msh/src/mtypes.h
===================================================================
--- msh/src/mtypes.h 2013-08-21 11:29:03 UTC (rev 28741)
+++ msh/src/mtypes.h 2013-08-21 12:07:11 UTC (rev 28742)
@@ -97,11 +97,22 @@
* MPI tag numbers for each message type
*********************************************************************/
+/**
+ * Tag number for address verification messages
+ */
#define MSH_MTYPE_VERIFY_ADDRESSES 100
+/**
+ * Tag number for address messages
+ */
#define MSH_MTYPE_INSTANCE_ADDRESS 101
+/**
+ * Tag number for message signalling that MSHD instances should shutdown
+ */
+#define MSH_MTYPE_SHUTDOWN 102
+
/****************************************************************/
/* MSH Daemon and MSH command line tool communication messsages */
/****************************************************************/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r28742 - msh/src,
gnunet <=