From 664c03b8e6fd0c98a3aa41143b7093bcc4656ed9 Mon Sep 17 00:00:00 2001 From: "W. Eric Norum" Date: Wed, 1 Mar 2000 15:09:05 +0000 Subject: [PATCH] Add RTEMS implementations of threadGetId and threadOnceOsd. --- src/libCom/osi/os/RTEMS/osdThread.c | 58 ++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/libCom/osi/os/RTEMS/osdThread.c b/src/libCom/osi/os/RTEMS/osdThread.c index 95c671bff..fb6f0052d 100644 --- a/src/libCom/osi/os/RTEMS/osdThread.c +++ b/src/libCom/osi/os/RTEMS/osdThread.c @@ -306,7 +306,7 @@ const char *threadGetNameSelf(void) return v->name; } -void threadGetName(threadId id, char *name,size_t size) +void threadGetName (threadId id, char *name, size_t size) { rtems_id tid = (rtems_id)id; rtems_status_code sc; @@ -326,6 +326,62 @@ void threadGetName(threadId id, char *name,size_t size) taskVarUnlock (); } +threadId threadGetId (const char *name) +{ + struct taskVar *v; + rtems_id tid = 0; + + /* + * Linear search is good enough since this routine + * is invoked only by command-line calls. + */ + taskVarLock (); + for (v = taskVarHead ; v != NULL ; v = v->forw) { + if (strcmp (name, v->name) == 0) { + tid = v->id; + break; + } + } + taskVarUnlock (); + return (threadId)tid; +} + +/* + * Ensure func() is run only once. + */ +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); + switch (id->state) { + case 0: + id->state = -1; + id->sem = semMutexMustCreate(); + semMutexMustTake(id->sem); + semMutexGive(onceMutex); + func(arg); + id->state = 1; + semBinaryGive(id->sem); + break; + case -1: + semMutexGive(onceMutex); + semBinaryMustTake(id->sem); + semBinaryGive(id->sem); + break; + default: + semMutexGive(onceMutex); + break; + } +} + /* * Thread private storage implementation based on the vxWorks * implementation by Andrew Johnson APS/ASD.