From: sailer Date: Fri, 21 Feb 2003 18:58:44 +0000 (+0000) Subject: replacend sleep with nanosleep (threadsafeness). X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=790436262aaa5f11e9b02ee11ac017a2f92abd84;p=daqdata.git replacend sleep with nanosleep (threadsafeness). -- Benjamin Sailer --- diff --git a/hadaq/ctrlctu.c b/hadaq/ctrlctu.c index 9fa34f6..edfa6b3 100644 --- a/hadaq/ctrlctu.c +++ b/hadaq/ctrlctu.c @@ -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 -#include #include +#include #include -#include -#include #include - +#include +#include #include - +#include #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; diff --git a/hadaq/sniff.c b/hadaq/sniff.c index c5f26e4..cd50eb7 100644 --- a/hadaq/sniff.c +++ b/hadaq/sniff.c @@ -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 -#include -#include #include - +#include +#include #include - +#include #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))) { diff --git a/hadaq/worker.c b/hadaq/worker.c index fee3607..40b4d9f 100644 --- a/hadaq/worker.c +++ b/hadaq/worker.c @@ -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 @@ -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); } }