summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-12-17 07:46:30 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-12-17 07:46:30 +0000
commitb0ee8aac88dfad1a2d7c47f49670e52b368fa580 (patch)
tree2df769472df4801e45306e1c092eada29066d302
parentc55bb999b214c2dbd7d27b37fb189d2514e7a169 (diff)
downloadrsyslog-b0ee8aac88dfad1a2d7c47f49670e52b368fa580.tar.gz
rsyslog-b0ee8aac88dfad1a2d7c47f49670e52b368fa580.tar.xz
rsyslog-b0ee8aac88dfad1a2d7c47f49670e52b368fa580.zip
created thread-class internal wrapper for calling user supplied thread main
function
-rw-r--r--syslogd.c3
-rw-r--r--threads.c27
-rw-r--r--threads.h3
3 files changed, 27 insertions, 6 deletions
diff --git a/syslogd.c b/syslogd.c
index d762cf3b..e7d09fbc 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -2629,7 +2629,8 @@ static void startWorker(void)
* worker thread. Having more than one worker requires considerable
* additional code review in regard to thread-safety.
*/
-static void *singleWorker()
+static void *
+singleWorker()
{
msgQueue *fifo = pMsgQueue;
msg_t *pMsg;
diff --git a/threads.c b/threads.c
index 139cf835..dfe392fc 100644
--- a/threads.c
+++ b/threads.c
@@ -89,7 +89,7 @@ rsRetVal thrdTerminate(thrdInfo_t *pThis)
{
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) {
pthread_kill(pThis->thrdID, SIGUSR2);
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
* executing threads. It is added at the end of the list.
* rgerhards, 2007-12-14
*/
-rsRetVal thrdCreate(void* (*thrdMain)(void*), eTermSyncType_t eTermSyncType)
+rsRetVal thrdCreate(rsRetVal (*thrdMain)(void), eTermSyncType_t eTermSyncType)
{
DEFiRet;
thrdInfo_t *pThis;
@@ -129,7 +147,8 @@ rsRetVal thrdCreate(void* (*thrdMain)(void*), eTermSyncType_t eTermSyncType)
CHKiRet(thrdConstruct(&pThis));
pThis->eTermTool = eTermSyncType;
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));
finalize_it:
@@ -140,7 +159,7 @@ finalize_it:
/* This is a dummy handler. We user SIGUSR2 to interrupt blocking system calls
* if we are in termination mode 1.
*/
-static void sigusr2Dummy(int sig)
+static void sigusr2Dummy(int __attribute__((unused)) sig)
{
dbgprintf("sigusr2Dummy called!\n");
}
diff --git a/threads.h b/threads.h
index 1075ec7f..9ed6b2b3 100644
--- a/threads.h
+++ b/threads.h
@@ -34,6 +34,7 @@ typedef enum eTermSyncType {
typedef struct thrdInfo {
eTermSyncType_t eTermTool;
int bIsActive; /* Is thread running? */
+ rsRetVal (*pUsrThrdMain)(void); /* user thread main to be called in new thread */
pthread_t thrdID;
} thrdInfo_t;
@@ -53,7 +54,7 @@ rsRetVal thrdExit(void);
rsRetVal thrdInit(void);
rsRetVal thrdTerminate(thrdInfo_t *pThis);
rsRetVal thrdTerminateAll(void);
-rsRetVal thrdCreate(void* (*thrdMain)(void*), eTermSyncType_t eTermSyncType);
+rsRetVal thrdCreate(rsRetVal (*thrdMain)(void), eTermSyncType_t eTermSyncType);
msgQueue *queueInit (void);
void queueDelete (msgQueue *q);
void queueAdd (msgQueue *q, void* in);