]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
replacend sleep with nanosleep (threadsafeness).
authorsailer <sailer>
Fri, 21 Feb 2003 18:58:44 +0000 (18:58 +0000)
committersailer <sailer>
Fri, 21 Feb 2003 18:58:44 +0000 (18:58 +0000)
-- Benjamin Sailer

hadaq/ctrlctu.c
hadaq/sniff.c
hadaq/worker.c

index 9fa34f6d2e8462c83ab1ca13b549bdebc09b4e71..edfa6b32379da12093eaa711df1b37bd06627282 100644 (file)
@@ -1,18 +1,18 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/ctrlctu.c,v 6.12 2002-10-09 12:42:17 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/ctrlctu.c,v 6.13 2003-02-21 18:58:44 sailer Exp $";
 
 #define _XOPEN_SOURCE
+#define _POSIX_C_SOURCE 199506L
 #define SYSLOG_NAMES
 #include <unistd.h>
-#include <stddef.h>
 
 #include <errno.h>
+#include <stddef.h>
 #include <setjmp.h>
-#include <stdlib.h>
-#include <stdio.h>
 #include <signal.h>
-
+#include <stdio.h>
+#include <stdlib.h>
 #include <syslog.h>
-
+#include <time.h>
 
 #include "worker.h"
 
@@ -39,12 +39,12 @@ int main(int argc, char *argv[])
        unsigned long value;
        int oper;
        unsigned long *ctuEnabled;
+       struct timespec t1 = {1, 0};
+       struct timespec t3 = {3, 0};
 
        openlog(argv[0], LOG_PID|LOG_PERROR, LOG_LOCAL0);
        setlogmask(LOG_UPTO(LOG_INFO));
 
-
-
        isStandalone = 1;
        priority = 0;
        while ((i = getopt(argc, argv, "ap:v:")) != -1) {
@@ -84,14 +84,14 @@ int main(int argc, char *argv[])
        }
        Worker_initEnd(worker);
 
-       sleep(1);
+       nanosleep(&t1, NULL);
        system("dtuctrl -t ctu reset");
        system("dtuctrl -t ctu start");
        (*ctuEnabled) = 1;
        if (0 == setjmp(terminateJmp)) {
                pause();
        }
-       sleep(3);
+       nanosleep(&t3, NULL);
        system("dtuctrl -t ctu stop");
        (*ctuEnabled) = 0;
 
index c5f26e453ef8908075d407442af5217e99c7daa7..cd50eb7234c8d15e2190baffb53368c2dd03280a 100644 (file)
@@ -1,16 +1,15 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/sniff.c,v 6.6 2002-10-28 07:41:18 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/sniff.c,v 6.7 2003-02-21 18:58:44 sailer Exp $";
 
 
 #define SYSLOG_NAMES
 #define _GNU_SOURCE
 #include <unistd.h>
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <rpc/rpc.h>
-
+#include <stdio.h>
+#include <stdlib.h>
 #include <syslog.h>
-
+#include <time.h>
 
 #include "online.h"
 
@@ -20,6 +19,7 @@ main(int argc, char *argv[])
        CLIENT *cl;
        char *server;
        int i;
+       struct timespec t = {5, 0};
        struct rpc_err rpcErrS, *rpcErr = &rpcErrS;
        rpcevt rpcEvtS, *rpcEvt = &rpcEvtS;
 
@@ -58,7 +58,7 @@ main(int argc, char *argv[])
                if (NULL == (cl = clnt_create(server, DAQPROG, DAQVERS, "tcp"))) {
                        syslog(LOG_INFO, "online server not running, trying to connect");
                        syslog(LOG_DEBUG, "%s, %d: %s", __FILE__, __LINE__, clnt_spcreateerror(server));
-                       sleep(5);
+                       nanosleep(&t, NULL);
                } else {
                        do {
                                if (NULL == (rpcEvt = onlineevt_1(NULL, cl))) {
index fee3607ece14d08f6afd52a285b45a1b054e08ef..40b4d9fb6e012b73102492684bd07b9e273186f8 100644 (file)
@@ -1,4 +1,4 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/worker.c,v 6.16 2003-02-07 11:44:20 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/worker.c,v 6.17 2003-02-21 18:58:44 sailer Exp $";
 
 #define _POSIX_C_SOURCE 199309L
 #include <unistd.h>
@@ -232,6 +232,7 @@ int Worker_start(const char *path, char *const argv[])
 {
        int retVal;
        Worker myS, *my = &myS;
+       struct timespec t = {1, 0};
 
        strcpy(my->name, argv[0]);
 #ifndef WORKER_NEW_PROTOCOL
@@ -261,7 +262,7 @@ int Worker_start(const char *path, char *const argv[])
                        sigsuspend(sigMask);    /* child to initialize */
 
                        if (sigReceived == SIGCHLD) {
-                               sleep(1);
+                               nanosleep(&t, NULL);
                                wait(NULL);
                                syslog(LOG_DEBUG,
                                           "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
@@ -282,7 +283,7 @@ int Worker_start(const char *path, char *const argv[])
                                        }
                                        closeStatShm(my);
                                }
-                               sleep(1);
+                               nanosleep(&t, NULL);
                        }
                        if (i == timeout) {
                                retVal = -1;
@@ -331,6 +332,7 @@ char *Worker_status(const char *name)
 void Worker_stop(const char *name, int timeout)
 {
        Worker myS, *my = &myS;
+       struct timespec t = {1, 0};
 
        strcpy(my->name, name);
 
@@ -338,7 +340,7 @@ void Worker_stop(const char *name, int timeout)
                my->pid = my->statistics[0].value;
                if (my->pid > 0) {
                        if (0 == kill(my->pid, SIGTERM)) {
-                               sleep(1);               /* LynxOS had problem without this */
+                               nanosleep(&t, NULL); /* LynxOS had problem without this */
                                waitpid(my->pid, NULL, 0);
                        }
                }