mirror of
https://github.com/rsyslog/rsyslog.git
synced 2026-06-18 09:52:57 +02:00
created thread-class internal wrapper for calling user supplied thread main
function
This commit is contained in:
parent
c55bb999b2
commit
b0ee8aac88
@ -2629,7 +2629,8 @@ static void startWorker(void)
|
|||||||
* worker thread. Having more than one worker requires considerable
|
* worker thread. Having more than one worker requires considerable
|
||||||
* additional code review in regard to thread-safety.
|
* additional code review in regard to thread-safety.
|
||||||
*/
|
*/
|
||||||
static void *singleWorker()
|
static void *
|
||||||
|
singleWorker()
|
||||||
{
|
{
|
||||||
msgQueue *fifo = pMsgQueue;
|
msgQueue *fifo = pMsgQueue;
|
||||||
msg_t *pMsg;
|
msg_t *pMsg;
|
||||||
|
|||||||
27
threads.c
27
threads.c
@ -89,7 +89,7 @@ rsRetVal thrdTerminate(thrdInfo_t *pThis)
|
|||||||
{
|
{
|
||||||
assert(pThis != NULL);
|
assert(pThis != NULL);
|
||||||
|
|
||||||
dbgprintf("Terminate thread %d via method %d\n", pThis->thrdID, pThis->eTermTool);
|
dbgprintf("Terminate thread %lx via method %d\n", pThis->thrdID, pThis->eTermTool);
|
||||||
if(pThis->eTermTool == eTermSync_SIGNAL) {
|
if(pThis->eTermTool == eTermSync_SIGNAL) {
|
||||||
pthread_kill(pThis->thrdID, SIGUSR2);
|
pthread_kill(pThis->thrdID, SIGUSR2);
|
||||||
pthread_join(pThis->thrdID, NULL);
|
pthread_join(pThis->thrdID, NULL);
|
||||||
@ -114,11 +114,29 @@ dbgprintf("thrdTerminateAll out\n");
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* This is an internal wrapper around the user thread function. Its
|
||||||
|
* purpose is to handle all the necessary housekeeping stuff so that the
|
||||||
|
* user function needs not to be aware of the threading calls. The user
|
||||||
|
* function call has just "normal", non-threading semantics.
|
||||||
|
* rgerhards, 2007-12-17
|
||||||
|
*/
|
||||||
|
static void* thrdStarter(void *arg)
|
||||||
|
{
|
||||||
|
DEFiRet;
|
||||||
|
thrdInfo_t *pThis = (thrdInfo_t*) arg;
|
||||||
|
|
||||||
|
assert(pThis != NULL);
|
||||||
|
assert(pThis->pUsrThrdMain != NULL);
|
||||||
|
iRet = pThis->pUsrThrdMain();
|
||||||
|
dbgprintf("thrdStarter: usrThrdMain 0x%lx returned with iRet %d.\n", (unsigned long) pThis->thrdID, iRet);
|
||||||
|
pthread_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Start a new thread and add it to the list of currently
|
/* Start a new thread and add it to the list of currently
|
||||||
* executing threads. It is added at the end of the list.
|
* executing threads. It is added at the end of the list.
|
||||||
* rgerhards, 2007-12-14
|
* rgerhards, 2007-12-14
|
||||||
*/
|
*/
|
||||||
rsRetVal thrdCreate(void* (*thrdMain)(void*), eTermSyncType_t eTermSyncType)
|
rsRetVal thrdCreate(rsRetVal (*thrdMain)(void), eTermSyncType_t eTermSyncType)
|
||||||
{
|
{
|
||||||
DEFiRet;
|
DEFiRet;
|
||||||
thrdInfo_t *pThis;
|
thrdInfo_t *pThis;
|
||||||
@ -129,7 +147,8 @@ rsRetVal thrdCreate(void* (*thrdMain)(void*), eTermSyncType_t eTermSyncType)
|
|||||||
CHKiRet(thrdConstruct(&pThis));
|
CHKiRet(thrdConstruct(&pThis));
|
||||||
pThis->eTermTool = eTermSyncType;
|
pThis->eTermTool = eTermSyncType;
|
||||||
pThis->bIsActive = 1;
|
pThis->bIsActive = 1;
|
||||||
i = pthread_create(&pThis->thrdID, NULL, thrdMain, NULL);
|
pThis->pUsrThrdMain = thrdMain;
|
||||||
|
i = pthread_create(&pThis->thrdID, NULL, thrdStarter, pThis);
|
||||||
CHKiRet(llAppend(&llThrds, NULL, pThis));
|
CHKiRet(llAppend(&llThrds, NULL, pThis));
|
||||||
|
|
||||||
finalize_it:
|
finalize_it:
|
||||||
@ -140,7 +159,7 @@ finalize_it:
|
|||||||
/* This is a dummy handler. We user SIGUSR2 to interrupt blocking system calls
|
/* This is a dummy handler. We user SIGUSR2 to interrupt blocking system calls
|
||||||
* if we are in termination mode 1.
|
* if we are in termination mode 1.
|
||||||
*/
|
*/
|
||||||
static void sigusr2Dummy(int sig)
|
static void sigusr2Dummy(int __attribute__((unused)) sig)
|
||||||
{
|
{
|
||||||
dbgprintf("sigusr2Dummy called!\n");
|
dbgprintf("sigusr2Dummy called!\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,6 +34,7 @@ typedef enum eTermSyncType {
|
|||||||
typedef struct thrdInfo {
|
typedef struct thrdInfo {
|
||||||
eTermSyncType_t eTermTool;
|
eTermSyncType_t eTermTool;
|
||||||
int bIsActive; /* Is thread running? */
|
int bIsActive; /* Is thread running? */
|
||||||
|
rsRetVal (*pUsrThrdMain)(void); /* user thread main to be called in new thread */
|
||||||
pthread_t thrdID;
|
pthread_t thrdID;
|
||||||
} thrdInfo_t;
|
} thrdInfo_t;
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ rsRetVal thrdExit(void);
|
|||||||
rsRetVal thrdInit(void);
|
rsRetVal thrdInit(void);
|
||||||
rsRetVal thrdTerminate(thrdInfo_t *pThis);
|
rsRetVal thrdTerminate(thrdInfo_t *pThis);
|
||||||
rsRetVal thrdTerminateAll(void);
|
rsRetVal thrdTerminateAll(void);
|
||||||
rsRetVal thrdCreate(void* (*thrdMain)(void*), eTermSyncType_t eTermSyncType);
|
rsRetVal thrdCreate(rsRetVal (*thrdMain)(void), eTermSyncType_t eTermSyncType);
|
||||||
msgQueue *queueInit (void);
|
msgQueue *queueInit (void);
|
||||||
void queueDelete (msgQueue *q);
|
void queueDelete (msgQueue *q);
|
||||||
void queueAdd (msgQueue *q, void* in);
|
void queueAdd (msgQueue *q, void* in);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user