~ubuntu-branches/ubuntu/lucid/rsyslog/lucid-updates

1.1.2 by Michael Biebl
Import upstream version 3.14.2
1
/* Definition of the worker thread pool (wtp) object.
2
 *
3
 * Copyright 2008 Rainer Gerhards and Adiscon GmbH.
4
 *
1.1.3 by Michael Biebl
Import upstream version 3.16.1
5
 * This file is part of the rsyslog runtime library.
1.1.2 by Michael Biebl
Import upstream version 3.14.2
6
 *
1.1.3 by Michael Biebl
Import upstream version 3.16.1
7
 * The rsyslog runtime library is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Lesser General Public License as published by
1.1.2 by Michael Biebl
Import upstream version 3.14.2
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
1.1.3 by Michael Biebl
Import upstream version 3.16.1
12
 * The rsyslog runtime library is distributed in the hope that it will be useful,
1.1.2 by Michael Biebl
Import upstream version 3.14.2
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1.1.3 by Michael Biebl
Import upstream version 3.16.1
15
 * GNU Lesser General Public License for more details.
1.1.2 by Michael Biebl
Import upstream version 3.14.2
16
 *
1.1.3 by Michael Biebl
Import upstream version 3.16.1
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with the rsyslog runtime library.  If not, see <http://www.gnu.org/licenses/>.
1.1.2 by Michael Biebl
Import upstream version 3.14.2
19
 *
20
 * A copy of the GPL can be found in the file "COPYING" in this distribution.
1.1.3 by Michael Biebl
Import upstream version 3.16.1
21
 * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
1.1.2 by Michael Biebl
Import upstream version 3.14.2
22
 */
23
24
#ifndef WTP_H_INCLUDED
25
#define WTP_H_INCLUDED
26
27
#include <pthread.h>
28
#include "obj.h"
29
30
/* commands and states for worker threads. */
31
typedef enum {
32
	eWRKTHRD_STOPPED = 0,	/* worker thread is not running (either actually never ran or was shut down) */
33
	eWRKTHRD_TERMINATING = 1,/* worker thread has shut down, but some finalzing is still needed */
34
	/* ALL active states MUST be numerically higher than eWRKTHRD_TERMINATED and NONE must be lower! */
35
	eWRKTHRD_RUN_CREATED = 2,/* worker thread has been created, but not yet begun initialization (prob. not yet scheduled) */
36
	eWRKTHRD_RUN_INIT = 3,	/* worker thread is initializing, but not yet fully running */
37
	eWRKTHRD_RUNNING = 4,	/* worker thread is up and running and shall continue to do so */
38
	eWRKTHRD_SHUTDOWN = 5,	/* worker thread is running but shall terminate when wtp is empty */
39
	eWRKTHRD_SHUTDOWN_IMMEDIATE = 6/* worker thread is running but shall terminate even if wtp is full */
40
	/* SHUTDOWN_IMMEDIATE MUST alsways be the numerically highest state! */
41
} qWrkCmd_t;
42
43
44
/* possible states of a worker thread pool */
45
typedef enum {
46
	wtpState_RUNNING = 0,		/* runs in regular mode */
47
	wtpState_SHUTDOWN = 1,		/* worker threads shall shutdown when idle */
48
	wtpState_SHUTDOWN_IMMEDIATE = 2	/* worker threads shall shutdown ASAP, even if not idle */
49
} wtpState_t;
50
51
52
/* the worker thread pool (wtp) object */
53
typedef struct wtp_s {
54
	BEGINobjInstance;
55
	wtpState_t wtpState;
56
	int 	iNumWorkerThreads;/* number of worker threads to use */
57
	int 	iCurNumWrkThrd;/* current number of active worker threads */
58
	struct wti_s **pWrkr;/* array with control structure for the worker thread(s) associated with this wtp */
59
	int	toWrkShutdown;	/* timeout for idle workers in ms, -1 means indefinite (0 is immediate) */
60
	int	bInactivityGuard;/* prevents inactivity due to race condition */
61
	rsRetVal (*pConsumer)(void *); /* user-supplied consumer function for dewtpd messages */
62
	/* synchronization variables */
63
	pthread_mutex_t mut; /* mutex for the wtp's thread management */
64
	pthread_cond_t condThrdTrm;/* signalled when threads terminate */
65
	int bThrdStateChanged;	/* at least one thread state has changed if 1 */
66
	/* end sync variables */
67
	/* user objects */
68
	void *pUsr;		/* pointer to user object */
69
	pthread_mutex_t *pmutUsr;
70
	pthread_cond_t *pcondBusy; /* condition the user will signal "busy again, keep runing" on (awakes worker) */
71
	rsRetVal (*pfChkStopWrkr)(void *pUsr, int);
1.1.5 by Michael Biebl
Import upstream version 3.18.1
72
	rsRetVal (*pfRateLimiter)(void *pUsr);
1.1.2 by Michael Biebl
Import upstream version 3.14.2
73
	rsRetVal (*pfIsIdle)(void *pUsr, int);
74
	rsRetVal (*pfDoWork)(void *pUsr, void *pWti, int);
75
	rsRetVal (*pfOnIdle)(void *pUsr, int);
76
	rsRetVal (*pfOnWorkerCancel)(void *pUsr, void*pWti);
77
	rsRetVal (*pfOnWorkerStartup)(void *pUsr);
78
	rsRetVal (*pfOnWorkerShutdown)(void *pUsr);
79
	/* end user objects */
80
	uchar *pszDbgHdr;	/* header string for debug messages */
81
} wtp_t;
82
83
/* some symbolic constants for easier reference */
84
85
86
/* prototypes */
87
rsRetVal wtpConstruct(wtp_t **ppThis);
88
rsRetVal wtpConstructFinalize(wtp_t *pThis);
89
rsRetVal wtpDestruct(wtp_t **ppThis);
90
rsRetVal wtpAdviseMaxWorkers(wtp_t *pThis, int nMaxWrkr);
91
rsRetVal wtpProcessThrdChanges(wtp_t *pThis);
92
rsRetVal wtpSetInactivityGuard(wtp_t *pThis, int bNewState, int bLockMutex);
93
rsRetVal wtpChkStopWrkr(wtp_t *pThis, int bLockMutex, int bLockUsrMutex);
94
rsRetVal wtpSetState(wtp_t *pThis, wtpState_t iNewState);
95
rsRetVal wtpWakeupWrkr(wtp_t *pThis);
96
rsRetVal wtpWakeupAllWrkr(wtp_t *pThis);
97
rsRetVal wtpCancelAll(wtp_t *pThis);
98
rsRetVal wtpSetDbgHdr(wtp_t *pThis, uchar *pszMsg, size_t lenMsg);
99
rsRetVal wtpSignalWrkrTermination(wtp_t *pWtp);
100
rsRetVal wtpShutdownAll(wtp_t *pThis, wtpState_t tShutdownCmd, struct timespec *ptTimeout);
101
int wtpGetCurNumWrkr(wtp_t *pThis, int bLockMutex);
102
PROTOTYPEObjClassInit(wtp);
103
PROTOTYPEpropSetMethFP(wtp, pfChkStopWrkr, rsRetVal(*pVal)(void*, int));
1.1.5 by Michael Biebl
Import upstream version 3.18.1
104
PROTOTYPEpropSetMethFP(wtp, pfRateLimiter, rsRetVal(*pVal)(void*));
1.1.2 by Michael Biebl
Import upstream version 3.14.2
105
PROTOTYPEpropSetMethFP(wtp, pfIsIdle, rsRetVal(*pVal)(void*, int));
106
PROTOTYPEpropSetMethFP(wtp, pfDoWork, rsRetVal(*pVal)(void*, void*, int));
107
PROTOTYPEpropSetMethFP(wtp, pfOnIdle, rsRetVal(*pVal)(void*, int));
108
PROTOTYPEpropSetMethFP(wtp, pfOnWorkerCancel, rsRetVal(*pVal)(void*,void*));
109
PROTOTYPEpropSetMethFP(wtp, pfOnWorkerStartup, rsRetVal(*pVal)(void*));
110
PROTOTYPEpropSetMethFP(wtp, pfOnWorkerShutdown, rsRetVal(*pVal)(void*));
111
PROTOTYPEpropSetMeth(wtp, toWrkShutdown, long);
112
PROTOTYPEpropSetMeth(wtp, wtpState, wtpState_t);
113
PROTOTYPEpropSetMeth(wtp, iMaxWorkerThreads, int);
114
PROTOTYPEpropSetMeth(wtp, pUsr, void*);
115
PROTOTYPEpropSetMeth(wtp, iNumWorkerThreads, int);
116
PROTOTYPEpropSetMethPTR(wtp, pmutUsr, pthread_mutex_t);
117
PROTOTYPEpropSetMethPTR(wtp, pcondBusy, pthread_cond_t);
118
119
#endif /* #ifndef WTP_H_INCLUDED */