summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-07-08 18:45:23 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-07-08 18:45:23 +0200
commit4b6e93d382a622bffedbbaa6b87f94124987e2fd (patch)
tree4e166dd1d6f1ec2b51fe2c70d2973448fa7f212d
parent4cfbc7254a49503a3c980a1b20264915d6b3b807 (diff)
downloadrsyslog-4b6e93d382a622bffedbbaa6b87f94124987e2fd.tar.gz
rsyslog-4b6e93d382a622bffedbbaa6b87f94124987e2fd.tar.xz
rsyslog-4b6e93d382a622bffedbbaa6b87f94124987e2fd.zip
further reduction in code size/complexity due to design change
-rw-r--r--runtime/wti.c5
-rw-r--r--runtime/wti.h1
-rw-r--r--runtime/wtp.c33
-rw-r--r--runtime/wtp.h4
-rw-r--r--tests/nettester.c1
5 files changed, 3 insertions, 41 deletions
diff --git a/runtime/wti.c b/runtime/wti.c
index f6a32c34..769575e1 100644
--- a/runtime/wti.c
+++ b/runtime/wti.c
@@ -162,7 +162,6 @@ wtiCancelThrd(wti_t *pThis)
pthread_cancel(pThis->thrdID);
/* TODO: check: the following check should automatically be done by cancel cleanup handler! 2009-07-08 rgerhards */
wtiSetState(pThis, eWRKTHRD_STOPPED, 0, MUTEX_ALREADY_LOCKED);
- ATOMIC_STORE_1_TO_INT(pThis->pWtp->bThrdStateChanged); /* indicate change, so harverster will be called */
}
d_pthread_mutex_unlock(&pThis->mut);
@@ -244,7 +243,6 @@ wtiWorkerCancelCleanup(void *arg)
d_pthread_mutex_lock(&pWtp->mut);
wtiSetState(pThis, eWRKTHRD_STOPPED, 0, MUTEX_ALREADY_LOCKED);
/* TODO: sync access? I currently think it is NOT needed -- rgerhards, 2008-01-28 */
- ATOMIC_STORE_1_TO_INT(pWtp->bThrdStateChanged); /* indicate change, so harverster will be called */
d_pthread_mutex_unlock(&pWtp->mut);
pthread_setcancelstate(iCancelStateSave, NULL);
@@ -307,8 +305,6 @@ wtiWorker(wti_t *pThis)
/* now we have our identity, on to real processing */
while(1) { /* loop will be broken below - need to do mutex locks */
- /* process any pending thread requests */
-
if(pWtp->pfRateLimiter != NULL) { /* call rate-limiter, if defined */
pWtp->pfRateLimiter(pWtp->pUsr);
}
@@ -364,7 +360,6 @@ RUNLOG_STR("XXX: Worker shutdown");
pWtp->pfOnWorkerShutdown(pWtp->pUsr);
wtiSetState(pThis, eWRKTHRD_STOPPED, 0, MUTEX_ALREADY_LOCKED);
- ATOMIC_STORE_1_TO_INT(pWtp->bThrdStateChanged); /* indicate change, so harverster will be called */
d_pthread_mutex_unlock(&pThis->mut);
pthread_setcancelstate(iCancelStateSave, NULL);
diff --git a/runtime/wti.h b/runtime/wti.h
index 5b7e5baf..8507cb5c 100644
--- a/runtime/wti.h
+++ b/runtime/wti.h
@@ -36,7 +36,6 @@ struct wti_s {
pthread_t thrdID; /* thread ID */
qWrkCmd_t tCurrCmd; /* current command to be carried out by worker */
wtp_t *pWtp; /* my worker thread pool (important if only the work thread instance is passed! */
- //pthread_cond_t condExitDone; /* signaled when the thread exit is done (once per thread existance) */
pthread_mutex_t mut;
batch_t batch; /* pointer to an object array meaningful for current user pointer (e.g. queue pUsr data elemt) */
bool bShutdownRqtd; /* shutdown for this thread requested? 0 - no , 1 - yes */
diff --git a/runtime/wtp.c b/runtime/wtp.c
index b27ce9f0..6d394a18 100644
--- a/runtime/wtp.c
+++ b/runtime/wtp.c
@@ -86,7 +86,6 @@ static rsRetVal NotImplementedDummy() { return RS_RET_NOT_IMPLEMENTED; }
*/
BEGINobjConstruct(wtp) /* be sure to specify the object type also in END macro! */
pthread_mutex_init(&pThis->mut, NULL);
- pthread_mutex_init(&pThis->mutThrdShutdwn, NULL);
pthread_cond_init(&pThis->condThrdTrm, NULL);
/* set all function pointers to "not implemented" dummy so that we can safely call them */
pThis->pfChkStopWrkr = NotImplementedDummy;
@@ -152,7 +151,6 @@ CODESTARTobjDestruct(wtp)
/* actual destruction */
pthread_cond_destroy(&pThis->condThrdTrm);
pthread_mutex_destroy(&pThis->mut);
- pthread_mutex_destroy(&pThis->mutThrdShutdwn);
free(pThis->pszDbgHdr);
ENDobjDestruct(wtp)
@@ -277,30 +275,6 @@ wtpShutdownAll(wtp_t *pThis, wtpState_t tShutdownCmd, struct timespec *ptTimeout
#pragma GCC diagnostic warning "-Wempty-body"
-/* indicate that a thread has terminated and awake anyone waiting on it
- * rgerhards, 2008-01-23
- */
-rsRetVal wtpSignalWrkrTermination(wtp_t *pThis)
-{
- DEFiRet;
- /* I leave the mutex code here out as it gives us deadlocks. I think it is not really
- * needed and we are on the safe side. I leave this comment in if practice proves us
- * wrong. The whole thing should be removed after half a year or year if we see there
- * actually is no issue (or revisit it from a theoretical POV).
- * rgerhards, 2008-01-28
- * revisited 2008-09-30, still a bit unclear, leave in
- */
- /*TODO: mutex or not mutex, that's the question ;)DEFVARS_mutexProtection;*/
-
- ISOBJ_TYPE_assert(pThis, wtp);
-
- /*BEGIN_MTX_PROTECTED_OPERATIONS(&pThis->mut, LOCK_MUTEX);*/
- pthread_cond_signal(&pThis->condThrdTrm); /* activate anyone waiting on thread shutdown */
- /*END_MTX_PROTECTED_OPERATIONS(&pThis->mut);*/
- RETiRet;
-}
-
-
/* Unconditionally cancel all running worker threads.
* rgerhards, 2008-01-14
*/
@@ -344,7 +318,7 @@ wtpSetInactivityGuard(wtp_t *pThis, int bNewState, int bLockMutex)
* decrements the worker counter
* rgerhards, 2008-01-20
*/
-void
+static void
wtpWrkrExecCancelCleanup(void *arg)
{
wtp_t *pThis = (wtp_t*) arg;
@@ -352,8 +326,7 @@ wtpWrkrExecCancelCleanup(void *arg)
BEGINfunc
ISOBJ_TYPE_assert(pThis, wtp);
pThis->iCurNumWrkThrd--;
- wtpSignalWrkrTermination(pThis);
-
+ pthread_cond_signal(&pThis->condThrdTrm); /* activate anyone waiting on thread shutdown */
dbgprintf("%s: thread CANCELED with %d workers running.\n", wtpGetDbgHdr(pThis), pThis->iCurNumWrkThrd);
ENDfunc
}
@@ -416,7 +389,7 @@ wtpWorker(void *arg) /* the arg is actually a wti object, even though we are in
pthread_cleanup_pop(0);
pThis->iCurNumWrkThrd--;
- wtpSignalWrkrTermination(pThis);
+ pthread_cond_signal(&pThis->condThrdTrm); /* activate anyone waiting on thread shutdown */
dbgprintf("%s: Worker thread %lx, terminated, num workers now %d\n",
wtpGetDbgHdr(pThis), (unsigned long) pWti, pThis->iCurNumWrkThrd);
diff --git a/runtime/wtp.h b/runtime/wtp.h
index 03bc538f..3afefc2a 100644
--- a/runtime/wtp.h
+++ b/runtime/wtp.h
@@ -30,7 +30,6 @@
/* commands and states for worker threads. */
typedef enum {
eWRKTHRD_STOPPED = 0, /* worker thread is not running (either actually never ran or was shut down) */
- //eWRKTHRD_TERMINATING = 1,/* worker thread has shut down, but some finalzing is still needed */
/* ALL active states MUST be numerically higher than eWRKTHRD_TERMINATED and NONE must be lower! */
eWRKTHRD_RUN_CREATED = 2,/* worker thread has been created, but not yet begun initialization (prob. not yet scheduled) */
eWRKTHRD_RUN_INIT = 3, /* worker thread is initializing, but not yet fully running */
@@ -60,10 +59,8 @@ struct wtp_s {
bool bInactivityGuard;/* prevents inactivity due to race condition */
rsRetVal (*pConsumer)(void *); /* user-supplied consumer function for dewtpd messages */
/* synchronization variables */
- pthread_mutex_t mutThrdShutdwn; /* mutex to guard thread shutdown processing */
pthread_mutex_t mut; /* mutex for the wtp's thread management */
pthread_cond_t condThrdTrm;/* signalled when threads terminate */
- int bThrdStateChanged; /* at least one thread state has changed if 1 */
/* end sync variables */
/* user objects */
void *pUsr; /* pointer to user object (in this case, the queue the wtp belongs to) */
@@ -99,7 +96,6 @@ rsRetVal wtpWakeupWrkr(wtp_t *pThis);
rsRetVal wtpWakeupAllWrkr(wtp_t *pThis);
rsRetVal wtpCancelAll(wtp_t *pThis);
rsRetVal wtpSetDbgHdr(wtp_t *pThis, uchar *pszMsg, size_t lenMsg);
-rsRetVal wtpSignalWrkrTermination(wtp_t *pWtp);
rsRetVal wtpShutdownAll(wtp_t *pThis, wtpState_t tShutdownCmd, struct timespec *ptTimeout);
int wtpGetCurNumWrkr(wtp_t *pThis, int bLockMutex);
PROTOTYPEObjClassInit(wtp);
diff --git a/tests/nettester.c b/tests/nettester.c
index 73abc46e..41b093c5 100644
--- a/tests/nettester.c
+++ b/tests/nettester.c
@@ -133,7 +133,6 @@ tcpSend(char *buf, int lenBuf)
fprintf(stderr, "connect() failed\n");
return(1);
} else {
- fprintf(stderr, "connect() failed, retry %d\n", retries);
usleep(100000); /* ms = 1000 us! */
}
}