Index: trunk/Ohana/src/opihi/include/pcontrol.h
===================================================================
--- trunk/Ohana/src/opihi/include/pcontrol.h	(revision 8297)
+++ trunk/Ohana/src/opihi/include/pcontrol.h	(revision 8424)
@@ -1,4 +1,5 @@
 # include "data.h"
 # include "basic.h"
+# define THREADED
 
 typedef struct timeval Ptime;
@@ -98,5 +99,7 @@
   int    Nobject;
   int    NOBJECT;
-  // pthread_mutex_t mutex;
+# ifdef THREADED    
+  pthread_mutex_t mutex;
+# endif
 } Stack;
 
@@ -108,4 +111,9 @@
 # define DTIME(A,B) ((A.tv_sec - B.tv_sec) + 1e-6*(A.tv_usec - B.tv_usec))
 # define ZTIME(A) ((A.tv_sec == 0) && (A.tv_usec == 0))
+
+// # define ASSERT(TEST,STRING) { if (!(TEST)) { gprint (GP_ERR, "programming error: %s\n", STRING); abort (); }}
+// # define ABORT(STRING) { gprint (GP_ERR, "programming error: %s\n", STRING); abort (); }
+# define ASSERT(TEST,STRING) { if (!(TEST)) { gprint (GP_ERR, "programming error: %s\n", STRING); raise (SIGINT); exit (2); }}
+# define ABORT(STRING) { gprint (GP_ERR, "programming error: %s\n", STRING); raise (SIGINT); exit (2); }
 
 void InitPcontrol ();
@@ -117,42 +125,57 @@
 void  *PullStackByName (Stack *stack, char *name);
 void  *PullStackByID (Stack *stack, int id);
-void  *FindStackByID (Stack *stack, int id);
-void  *FindStackByName (Stack *stack, char *name);
+int    RemoveStackEntry (Stack *stack, int where);
+void  *RemoveStackByID (Stack *stack, int id);
 void   LockStack (Stack *stack);
 void   UnlockStack (Stack *stack);
 
-int CheckSystem ();
-int CheckBusyJobs (float delay);
-int CheckDoneJobs (float delay);
-int CheckKillJobs (float delay);
-int CheckDoneHosts (float delay);
-int CheckLiveHosts (float delay);
-int CheckDownHosts (float delay);
-int CheckIdleHosts (float delay);
+// void  *FindStackByID (Stack *stack, int id);
+// void  *FindStackByName (Stack *stack, char *name);
+
+/*** CheckSystem.c ***/
+int   CheckSystem ();
+void *CheckSystem_Threaded (void *data);
+int   CheckBusyJobs (float delay);
+int   CheckDoneJobs (float delay);
+int   CheckKillJobs (float delay);
+int   CheckDoneHosts (float delay);
+int   CheckDownHosts (float delay);
+int   CheckIdleHosts (float delay);
+int   CheckLiveHosts (float delay);
+int   SetRunSystem (int state);
+
+/*** own files ***/
+int CheckHost (Host *host);
+int StartHost (Host *host);
 int CheckIdleHost (Host *host);
+int CheckDoneHost (Host *host);
+int CheckBusyJob (Job *job, Host *host);
+int CheckDoneJob (Job *job, Host *host);
+int KillJob (Job *job, Host *host);
+int StartJob (Job *job, Host *host);
+int ResetJob (Job *job);
+int GetJobOutput (char *command, Host *host, IOBuffer *buffer, int Nbytes);
+int PclientCommand (Host *host, char *command, char *response, IOBuffer *buffer);
+int rconnect (char *command, char *hostname, char *shell, int *stdio);
+
+/*** misc files ***/
+int    VerboseMode ();  // in verbose.c
+void   gotsignal (int signum); // in pcontrol.c
+
+/*** IDops.c ***/
 void InitIDs ();
 IDtype NextJobID ();
 IDtype NextHostID ();
 void PrintID (gpDest dest, IDtype ID);
-int CheckBusyJob (Job *job);
-int StartHost (Host *host);
-int CheckDoneHost (Host *host);
-int CheckDoneJob (Job *job);
-int GetJobOutput (char *command, Host *host, IOBuffer *buffer, int Nbytes);
-int ResetJob (Job *job);
-int PclientCommand (Host *host, char *command, char *response, IOBuffer *buffer);
-int rconnect (char *command, char *hostname, char *shell, int *stdio);
-int CheckHost (Host *host);
-
-int PrintJobStack (int Nstack);
-int PrintHostStack (int Nstack);
-
-int    VerboseMode ();
-
-void   gotsignal (int signum);
+
+/*** CheckPoint.c ***/
+int SetCheckPoint ();
+int ClearCheckPoint ();
+int TestCheckPoint ();
 
 /*** HostOps.c ***/
 void   InitHostStacks ();
 Stack *GetHostStack (int StackID);
+char  *GetHostStackName (int StackID);
 Stack *GetHostStackByName (char *name);
 int    PutHost (Host *host, int StackID, int where);
@@ -161,20 +184,18 @@
 Host  *PullHostFromStackByID (int StackID, IDtype ID);
 Host  *PullHostFromStackByName (int StackID, char *name);
-Host  *FindHostByID (IDtype HostID, int *StackID);
-Host  *FindHostByName (char *name, int *StackID);
-Host  *FindHostInStackByID (int StackID, IDtype ID);
-Host  *FindHostInStackByName (int StackID, char *name);
 IDtype AddHost (char *hostname);
 void   DelHost (Host *host);
 
+/*** StopHosts.c ***/
 void   DownHost (Host *host);
 void   OffHost (Host *host);
 int    DownHosts ();
+int    StopHost (Host *host);
 int    HarvestHost (int pid);
-int    StopHost (Host *host);
 
 /*** JobOps.c ***/
 void   InitJobStacks ();
 Stack *GetJobStack (int StackID);
+char  *GetJobStackName (int StackID);
 Stack *GetJobStackByName (char *name);
 int    PutJob (Job *job, int StackID, int where);
@@ -182,6 +203,4 @@
 Job   *PullJobByID (IDtype JobID, int *StackID);
 Job   *PullJobFromStackByID (int StackID, int ID);
-Job   *FindJobByID (IDtype JobID, int *StackID);
-Job   *FindJobInStackByID (int StackID, int ID);
 IDtype AddJob (char *hostname, JobMode mode, int timeout, int argc, char **argv);
 void   DelJob (Job *job);
@@ -189,4 +208,8 @@
 void   LinkJobAndHost (Job *job, Host *host);
 
-int    KillJob (Job *job);
-int    StartJob (Job *job);
+// Job   *FindJobByID (IDtype JobID, int *StackID);
+// Job   *FindJobInStackByID (int StackID, int ID);
+// Host  *FindHostByID (IDtype HostID, int *StackID);
+// Host  *FindHostByName (char *name, int *StackID);
+// Host  *FindHostInStackByID (int StackID, IDtype ID);
+// Host  *FindHostInStackByName (int StackID, char *name);
