refactor iparams to use array

this is also prep work for a single doTransaction() output mode api
This commit is contained in:
Rainer Gerhards 2013-11-06 18:07:26 +01:00
parent 7253a2aa3f
commit e3dc604142
3 changed files with 41 additions and 41 deletions

View File

@ -978,19 +978,17 @@ doTransaction(action_t *pThis, wti_t *pWti)
{
actWrkrInfo_t *wrkrInfo;
actWrkrIParams_t *iparamCurr;
int i;
DEFiRet;
wrkrInfo = &(pWti->actWrkrInfo[pThis->iActionNbr]);
dbgprintf("DDDD: doTransaction: action %d, root %p\n", pThis->iActionNbr, wrkrInfo->iparamRoot);
if(wrkrInfo->iparamRoot != NULL) {
iparamCurr = wrkrInfo->iparamRoot;
while(iparamCurr != NULL) {
iRet = actionProcessMessage(pThis, iparamCurr->msgFlags,
iparamCurr->staticActParams,
pWti);
dbgprintf("DDDD: doTransaction loop, iRet %d\n", iRet);
iparamCurr = iparamCurr->next;
}
dbgprintf("DDDD: doTransaction: action %d, currIParams %d\n", pThis->iActionNbr, wrkrInfo->currIParam);
for(i = 0 ; i < wrkrInfo->currIParam ; ++i) {
iparamCurr = wrkrInfo->iparams + i;
iRet = actionProcessMessage(pThis, iparamCurr->msgFlags,
iparamCurr->staticActParams,
pWti);
dbgprintf("DDDD: doTransaction loop, iRet %d\n", iRet);
}
RETiRet;
}
@ -1000,29 +998,25 @@ static void
actionFreeParams(action_t *pThis, wti_t *pWti)
{
actWrkrInfo_t *wrkrInfo;
actWrkrIParams_t *iparamCurr, *iparamDel;
actWrkrIParams_t *iparamCurr;
int i;
int j;
wrkrInfo = &(pWti->actWrkrInfo[pThis->iActionNbr]);
dbgprintf("DDDD: actionFreeParams: action %d, root %p\n", pThis->iActionNbr, wrkrInfo->iparamRoot);
if(wrkrInfo->iparamRoot != NULL) {
iparamCurr = wrkrInfo->iparamRoot;
while(iparamCurr != NULL) {
releaseDoActionParams(pThis, pWti);
iparamDel = iparamCurr;
iparamCurr = iparamCurr->next;
for(j = 0 ; j < CONF_OMOD_NUMSTRINGS_MAXSIZE ; ++j) {
/* TODO: we can save time by not freeing everything,
* but that's left for a later optimization.
*/
free(iparamDel->staticActStrings[j]);
iparamDel->staticActStrings[j] = NULL;
iparamDel->staticLenStrings[j] = 0;
}
free(iparamDel);
dbgprintf("DDDD: actionFreeParams: action %d, currIParam %d\n", pThis->iActionNbr, wrkrInfo->currIParam);
for(i = 0 ; i < wrkrInfo->currIParam ; ++i) {
iparamCurr = wrkrInfo->iparams + i;
for(j = 0 ; j < CONF_OMOD_NUMSTRINGS_MAXSIZE ; ++j) {
/* TODO: we can save time by not freeing everything,
* but that's left for a later optimization.
*/
free(iparamCurr->staticActStrings[j]);
iparamCurr->staticActStrings[j] = NULL;
iparamCurr->staticLenStrings[j] = 0;
}
wrkrInfo->iparamRoot = wrkrInfo->iparamLast = NULL;
}
wrkrInfo->currIParam = 0; /* reset to beginning */
releaseDoActionParams(pThis, pWti);
}
@ -1118,11 +1112,11 @@ actionCommitAllDirect(wti_t *pWti)
action_t *pAction;
for(i = 0 ; i < iActionNbr ; ++i) {
dbgprintf("DDDD: actionCommitAll: action %d, state %u, root %p\n",
i, getActionStateByNbr(pWti, i), pWti->actWrkrInfo[i].iparamRoot);
dbgprintf("DDDD: actionCommitAll: action %d, state %u, nbr to commit %d\n",
i, getActionStateByNbr(pWti, i), pWti->actWrkrInfo->currIParam);
pAction = pWti->actWrkrInfo[i].pAction;
if(pAction != NULL && pAction->pQueue->qType == QUEUETYPE_DIRECT)
actionCommit(pWti->actWrkrInfo[i].pAction, pWti);
actionCommit(pAction, pWti);
}
}

View File

@ -49,6 +49,7 @@
#define CONF_PROGNAME_BUFSIZE 16
#define CONF_HOSTNAME_BUFSIZE 32
#define CONF_PROP_BUFSIZE 16 /* should be close to sizeof(ptr) or lighly above it */
#define CONF_IPARAMS_BUFSIZE 16 /* initial size of iparams array in wti (is automatically extended) */
#define CONF_MIN_SIZE_FOR_COMPRESS 60 /* config param: minimum message size to try compression. The smaller
* the message, the less likely is any compression gain. We check for
* gain before we submit the message. But to do so we still need to

View File

@ -44,7 +44,6 @@
* as well. -- gerhards, 2013-11-04
*/
typedef struct actWrkrIParams {
struct actWrkrIParams *next;
int msgFlags;
/* following are caches to save allocs if not absolutely necessary */
uchar *staticActStrings[CONF_OMOD_NUMSTRINGS_MAXSIZE]; /**< for strings */
@ -62,8 +61,9 @@ typedef struct actWrkrInfo {
struct {
unsigned actState : 3;
} flags;
actWrkrIParams_t *iparamRoot;
actWrkrIParams_t *iparamLast;
actWrkrIParams_t *iparams;
int currIParam;
int maxIParams; /* current max */
void *staticActParams[CONF_OMOD_NUMSTRINGS_MAXSIZE]; /* for non-strings */
} actWrkrInfo_t;
@ -164,18 +164,23 @@ wtiNewIParam(wti_t *pWti, action_t *pAction, actWrkrIParams_t **piparams)
{
actWrkrInfo_t *wrkrInfo;
actWrkrIParams_t *iparams;
int newMax;
DEFiRet;
wrkrInfo = &(pWti->actWrkrInfo[pAction->iActionNbr]);
dbgprintf("DDDD: adding param for action %d\n", pAction->iActionNbr);
CHKmalloc(iparams = calloc(1, sizeof(actWrkrIParams_t)));
if(wrkrInfo->iparamLast == NULL) {
wrkrInfo->iparamLast = wrkrInfo->iparamRoot = iparams;
} else {
wrkrInfo->iparamLast->next = iparams;
wrkrInfo->iparamLast = iparams;
if(wrkrInfo->currIParam == wrkrInfo->maxIParams) {
/* we need to extend */
dbgprintf("DDDD: extending iparams, max %d\n", wrkrInfo->maxIParams);
newMax = (wrkrInfo->maxIParams == 0) ? CONF_IPARAMS_BUFSIZE : 2 * wrkrInfo->maxIParams;
CHKmalloc(iparams = realloc(wrkrInfo->iparams, sizeof(actWrkrIParams_t) * newMax));
wrkrInfo->iparams = iparams;
wrkrInfo->maxIParams = newMax;
}
dbgprintf("DDDD: adding param %d for action %d\n", wrkrInfo->currIParam, pAction->iActionNbr);
iparams = wrkrInfo->iparams + wrkrInfo->currIParam;
memset(iparams, 0, sizeof(actWrkrIParams_t));
*piparams = iparams;
++wrkrInfo->currIParam;
finalize_it:
RETiRet;