From bd169cc2d5522c02ee03b2f0923caa96b3cdbc30 Mon Sep 17 00:00:00 2001 From: "W. Eric Norum" Date: Tue, 7 Mar 2000 20:33:07 +0000 Subject: [PATCH] Clean up threadOnceOsd. Start up interrupt message daemon from threadInit. --- src/libCom/osi/os/RTEMS/osdInterrupt.c | 9 +++++---- src/libCom/osi/os/RTEMS/osdInterrupt.h | 5 ++++- src/libCom/osi/os/RTEMS/osdThread.c | 26 +++++++++++++++----------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/libCom/osi/os/RTEMS/osdInterrupt.c b/src/libCom/osi/os/RTEMS/osdInterrupt.c index 831084ff6..1de9c6722 100644 --- a/src/libCom/osi/os/RTEMS/osdInterrupt.c +++ b/src/libCom/osi/os/RTEMS/osdInterrupt.c @@ -11,6 +11,7 @@ #include #include "errlog.h" #include "osiInterrupt.h" +#include "osiThread.h" #define INTERRUPT_CONTEXT_MESSAGE_QUEUE_COUNT 100 @@ -54,8 +55,8 @@ interruptContextMessage (const char *message) /* * Daemon to process interrupt context messages */ -rtems_task -InterruptContextMessageDaemon (rtems_task_argument arg) +void +InterruptContextMessageDaemon (void *unused) { const char *message; rtems_unsigned32 size; @@ -68,7 +69,7 @@ InterruptContextMessageDaemon (rtems_task_argument arg) &interruptContextMessageQueue); if (sc != RTEMS_SUCCESSFUL) { errlogPrintf ("Can't create interrupt context message queue: %s\n", rtems_status_text (sc)); - rtems_task_suspend (RTEMS_SELF); + threadSuspendSelf (); } for (;;) { sc = rtems_message_queue_receive (interruptContextMessageQueue, @@ -78,7 +79,7 @@ InterruptContextMessageDaemon (rtems_task_argument arg) RTEMS_NO_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) { errlogPrintf ("Can't receive message from interrupt context: %s\n", rtems_status_text (sc)); - rtems_task_suspend (RTEMS_SELF); + threadSuspendSelf (); } if (size == sizeof message) syslog (LOG_ERR, "%s", message); diff --git a/src/libCom/osi/os/RTEMS/osdInterrupt.h b/src/libCom/osi/os/RTEMS/osdInterrupt.h index ced492e18..d385f7aca 100644 --- a/src/libCom/osi/os/RTEMS/osdInterrupt.h +++ b/src/libCom/osi/os/RTEMS/osdInterrupt.h @@ -1 +1,4 @@ -/* osdInterrupt.h not needed */ +/* + * Daemon to soak up and report messages from interrupt contexts + */ +extern void InterruptContextMessageDaemon (void *); diff --git a/src/libCom/osi/os/RTEMS/osdThread.c b/src/libCom/osi/os/RTEMS/osdThread.c index 70e0e6660..fa5499712 100644 --- a/src/libCom/osi/os/RTEMS/osdThread.c +++ b/src/libCom/osi/os/RTEMS/osdThread.c @@ -6,6 +6,10 @@ * (306) 966-6055 */ +/* + * We want to print out some task information which is + * normally hidden from application programs. + */ #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1 #include @@ -20,8 +24,8 @@ #include #include "errlog.h" -#include "ellLib.h" #include "osiThread.h" +#include "osiInterrupt.h" #include "cantProceed.h" /* @@ -38,6 +42,7 @@ struct taskVar { void **threadVariables; int threadVariablesAdded; }; +static semMutexId onceMutex; static semMutexId taskVarMutex; static struct taskVar *taskVarHead; #define RTEMS_NOTEPAD_TASKVAR 11 @@ -113,7 +118,7 @@ threadWrapper (rtems_task_argument arg) * OS-dependent initialization * No need to worry about making this thread-safe since * it must be called before threadCreate creates - * any threads. + * any new threads. */ void threadInit (void) @@ -122,11 +127,19 @@ threadInit (void) if (!initialized) { initialized = 1; + onceMutex = semMutexCreate(); + if (!onceMutex) { + syslog (LOG_CRIT, "Can't create `once' mutex"); + rtems_task_suspend (RTEMS_SELF); + } taskVarMutex = semMutexCreate (); if (!taskVarMutex) { syslog (LOG_CRIT, "Can't create task variable mutex"); rtems_task_suspend (RTEMS_SELF); } + threadCreate ("ImsgDaemon", 99, + threadGetStackSize (threadStackSmall), + InterruptContextMessageDaemon, NULL); } } @@ -340,15 +353,6 @@ threadId threadGetId (const char *name) */ void threadOnceOsd(threadOnceId *id, void(*func)(void *), void *arg) { - rtems_mode mode; - static semMutexId onceMutex; - - if (!onceMutex) { - rtems_task_mode(RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &mode); - if(!onceMutex) - onceMutex = semMutexMustCreate(); - rtems_task_mode(mode, RTEMS_PREEMPT_MASK, &mode); - } semMutexMustTake(onceMutex); if (*id == 0) { *id = -1;