From cb7f903730f097ebaa02dd12b3280a11e79b256b Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 16 Jul 2009 12:42:45 +0200 Subject: some code simplification --- runtime/wti.c | 14 ++++++-------- runtime/wti.h | 2 +- runtime/wtp.c | 4 ++-- runtime/wtp.h | 5 ++--- 4 files changed, 11 insertions(+), 14 deletions(-) (limited to 'runtime') diff --git a/runtime/wti.c b/runtime/wti.c index 9233cb4c..0ba1fe54 100644 --- a/runtime/wti.c +++ b/runtime/wti.c @@ -100,11 +100,10 @@ wtiGetState(wti_t *pThis, int bLockMutex) /* send a command to a specific thread - * bActiveOnly specifies if the command should be sent only when the worker is - * in an active state. -- rgerhards, 2008-01-20 + * rgerhards, 2008-01-20 */ rsRetVal -wtiSetState(wti_t *pThis, qWrkCmd_t tCmd, int bActiveOnly, int bLockMutex) +wtiSetState(wti_t *pThis, qWrkCmd_t tCmd, int bLockMutex) { DEFiRet; qWrkCmd_t tCurrCmd; @@ -117,8 +116,7 @@ wtiSetState(wti_t *pThis, qWrkCmd_t tCmd, int bActiveOnly, int bLockMutex) tCurrCmd = pThis->tCurrCmd; /* all worker states must be followed sequentially, only termination can be set in any state */ - if( (bActiveOnly && (tCurrCmd < eWRKTHRD_RUN_CREATED)) - || (tCurrCmd > tCmd && !(tCmd == eWRKTHRD_STOPPED))) { + if(tCurrCmd > tCmd && !(tCmd == eWRKTHRD_STOPPED)) { DBGPRINTF("%s: command %d can not be accepted in current %d processing state - ignored\n", wtiGetDbgHdr(pThis), tCmd, tCurrCmd); } else { @@ -161,7 +159,7 @@ wtiCancelThrd(wti_t *pThis) dbgoprint((obj_t*) pThis, "canceling worker thread, curr stat %d\n", pThis->tCurrCmd); 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); + wtiSetState(pThis, eWRKTHRD_STOPPED, MUTEX_ALREADY_LOCKED); } d_pthread_mutex_unlock(&pThis->mut); @@ -241,7 +239,7 @@ wtiWorkerCancelCleanup(void *arg) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &iCancelStateSave); d_pthread_mutex_lock(&pWtp->mut); - wtiSetState(pThis, eWRKTHRD_STOPPED, 0, MUTEX_ALREADY_LOCKED); + wtiSetState(pThis, eWRKTHRD_STOPPED, MUTEX_ALREADY_LOCKED); /* TODO: sync access? I currently think it is NOT needed -- rgerhards, 2008-01-28 */ d_pthread_mutex_unlock(&pWtp->mut); @@ -358,7 +356,7 @@ wtiWorker(wti_t *pThis) pWtp->pfOnWorkerShutdown(pWtp->pUsr); - wtiSetState(pThis, eWRKTHRD_STOPPED, 0, MUTEX_ALREADY_LOCKED); + wtiSetState(pThis, eWRKTHRD_STOPPED, MUTEX_ALREADY_LOCKED); d_pthread_mutex_unlock(&pThis->mut); pthread_setcancelstate(iCancelStateSave, NULL); diff --git a/runtime/wti.h b/runtime/wti.h index 8507cb5c..56901165 100644 --- a/runtime/wti.h +++ b/runtime/wti.h @@ -52,7 +52,7 @@ rsRetVal wtiDestruct(wti_t **ppThis); rsRetVal wtiWorker(wti_t *pThis); rsRetVal wtiProcessThrdChanges(wti_t *pThis, int bLockMutex); rsRetVal wtiSetDbgHdr(wti_t *pThis, uchar *pszMsg, size_t lenMsg); -rsRetVal wtiSetState(wti_t *pThis, qWrkCmd_t tCmd, int bActiveOnly, int bLockMutex); +rsRetVal wtiSetState(wti_t *pThis, qWrkCmd_t tCmd, int bLockMutex); rsRetVal wtiJoinThrd(wti_t *pThis); rsRetVal wtiCancelThrd(wti_t *pThis); qWrkCmd_t wtiGetState(wti_t *pThis, int bLockMutex); diff --git a/runtime/wtp.c b/runtime/wtp.c index 6d394a18..0beef263 100644 --- a/runtime/wtp.c +++ b/runtime/wtp.c @@ -372,7 +372,7 @@ wtpWorker(void *arg) /* the arg is actually a wti object, even though we are in * because someone may have requested us to shut down even before we got a chance to do * our init. That would be a bad race... -- rgerhards, 2008-01-16 */ - wtiSetState(pWti, eWRKTHRD_RUNNING, 0, MUTEX_ALREADY_LOCKED); /* we are running now! */ + wtiSetState(pWti, eWRKTHRD_RUNNING, MUTEX_ALREADY_LOCKED); /* we are running now! */ do { END_MTX_PROTECTED_OPERATIONS(&pThis->mut); @@ -430,7 +430,7 @@ wtpStartWrkr(wtp_t *pThis, int bLockMutex) ABORT_FINALIZE(RS_RET_NO_MORE_THREADS); pWti = pThis->pWrkr[i]; - wtiSetState(pWti, eWRKTHRD_RUN_CREATED, 0, LOCK_MUTEX); + wtiSetState(pWti, eWRKTHRD_RUN_CREATED, LOCK_MUTEX); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); iState = pthread_create(&(pWti->thrdID), &attr, wtpWorker, (void*) pWti); diff --git a/runtime/wtp.h b/runtime/wtp.h index 3afefc2a..6b4054b8 100644 --- a/runtime/wtp.h +++ b/runtime/wtp.h @@ -31,12 +31,11 @@ typedef enum { eWRKTHRD_STOPPED = 0, /* worker thread is not running (either actually never ran or was shut down) */ /* 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 */ + eWRKTHRD_RUN_CREATED = 2,/* worker thread has been created, but is not fully running (prob. not yet scheduled) */ eWRKTHRD_RUNNING = 4, /* worker thread is up and running and shall continue to do so */ eWRKTHRD_SHUTDOWN = 5, /* worker thread is running but shall terminate when wtp is empty */ eWRKTHRD_SHUTDOWN_IMMEDIATE = 6/* worker thread is running but shall terminate even if wtp is full */ - /* SHUTDOWN_IMMEDIATE MUST alsways be the numerically highest state! */ + /* SHUTDOWN_IMMEDIATE MUST always be the numerically highest state! */ } qWrkCmd_t; -- cgit