]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
*** empty log message ***
authorhadaq <hadaq>
Fri, 8 Nov 2002 15:14:43 +0000 (15:14 +0000)
committerhadaq <hadaq>
Fri, 8 Nov 2002 15:14:43 +0000 (15:14 +0000)
hadaq/tcldaq.c

index cfb93d9eba1317283402f3acc0017565f1e5fe11..86d5fca2d05a08bee8c6f979ca45e5b1e09de44a 100644 (file)
@@ -1,4 +1,4 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/tcldaq.c,v 6.6 2002-10-28 07:41:18 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/tcldaq.c,v 6.7 2002-11-08 15:14:43 hadaq Exp $";
 
 #define _GNU_SOURCE
 #include <unistd.h>
@@ -6,6 +6,7 @@ static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hada
 #include <stddef.h>
 
 #include <errno.h>
+#include <pthread.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -15,6 +16,10 @@ static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hada
 #include "worker.h"
 #include "agent.h"
 
+#define MAX_NTHR 16
+static pthread_t thr[MAX_NTHR];
+static nThr = 0;
+
 int AgentCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[])
 {
        CLIENT *cl;
@@ -91,24 +96,57 @@ int WorkerCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[]
        return TCL_OK;
 }
 
-int SystemCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[])
-{
+void *doIt(void *args) {
+       char **argv;
        CLIENT *cl;
        int res, *resP;
+       int status = 0;
+
+       puts("thread in");
+       argv = args;
+       sscanf(argv[1], "%p", &cl);
+       if (NULL == (resP = rpcsystem_1(&argv[2], cl))) {
+               status = 1;
+       }
+       puts("thread out");
+}
+
+int SystemCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[])
+{
+       int SystemCmdR;
 
        if (argc < 3) {
                Tcl_AppendResult(interp, "usage: c_system <agent> command", NULL);
-               return TCL_ERROR;
+               SystemCmdR = TCL_ERROR;
+       } else {
+               pthread_create(&thr[nThr++], NULL, doIt, (void *)argv);
+               pthread_join(thr[--nThr], NULL);
+               SystemCmdR = TCL_OK;
        }
-       sscanf(argv[1], "%p", &cl);
+
+       
+#if 0
        if (NULL == (resP = rpcsystem_1(&argv[2], cl))) {
                Tcl_AppendResult(interp, clnt_sperror(cl, "rpcsystem_1"), NULL);
                return TCL_ERROR;
        }
        res = *resP;
        sprintf(interp->result, "%d", res);
+#endif
 
-       return TCL_OK;
+       return SystemCmdR;
+}
+
+int JoinCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[])
+{
+       int JoinCmdR;
+
+       while (--nThr <= 0) {
+               pthread_join(thr[nThr], NULL);
+       }
+       JoinCmdR = 0;
+
+       return JoinCmdR;
 }
 
 int Daq_Init(Tcl_Interp * interp)
@@ -120,6 +158,7 @@ int Daq_Init(Tcl_Interp * interp)
        Tcl_CreateCommand(interp, "c_worker", WorkerCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
        Tcl_CreateCommand(interp, "c_agent", AgentCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
        Tcl_CreateCommand(interp, "c_system", SystemCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
+       Tcl_CreateCommand(interp, "c_join", JoinCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
 
        /*
    * Specify a user-specific startup file to invoke if the application