implement ShellContext

This commit is contained in:
Marty Kraimer
2004-07-09 16:05:53 +00:00
parent 23d4d7f790
commit b97efc9f7d
6 changed files with 90 additions and 0 deletions

View File

@@ -240,4 +240,13 @@ const char *epicsThread::getNameSelf ()
return epicsThreadGetNameSelf ();
}
bool epicsThread::isShellContext () const
{
return static_cast<int>(epicsThreadIsShellContext(this->id));
}
void epicsThread::setShellContext(bool isShell)
{
epicsThreadSetShellContext(this->id,static_cast<int>(isShell));
}

View File

@@ -97,6 +97,10 @@ epicsShareFunc const char * epicsShareAPI epicsThreadGetNameSelf(void);
epicsShareFunc void epicsShareAPI epicsThreadGetName(
epicsThreadId id, char *name, size_t size);
epicsShareFunc int epicsShareAPI epicsThreadIsShellContext(epicsThreadId id);
epicsShareFunc void epicsShareAPI epicsThreadSetShellContext(
epicsThreadId id,int isShell);
epicsShareFunc void epicsShareAPI epicsThreadShowAll(unsigned int level);
epicsShareFunc void epicsShareAPI epicsThreadShow(
epicsThreadId id,unsigned int level);
@@ -151,6 +155,8 @@ public:
static void sleep (double seconds);
/* static epicsThread & getSelf (); */
static const char * getNameSelf ();
bool isShellContext () const;
void setShellContext(bool isShell) ;
class mustBeCalledByManagedThread {}; /* exception */
private:
epicsThreadRunable & runable;

View File

@@ -48,6 +48,7 @@ struct taskVar {
void *parm;
unsigned int threadVariableCapacity;
void **threadVariables;
int isShell;
};
static epicsMutexId taskVarMutex;
static struct taskVar *taskVarHead;
@@ -213,6 +214,7 @@ setThreadInfo (rtems_id tid, const char *name, EPICSTHREADFUNC funptr,void *parm
v->parm = parm;
v->threadVariableCapacity = 0;
v->threadVariables = NULL;
v->isShell = 0;
note = (rtems_unsigned32)v;
rtems_task_set_note (tid, RTEMS_NOTEPAD_TASKVAR, note);
taskVarLock ();
@@ -452,6 +454,28 @@ epicsThreadId epicsThreadGetId (const char *name)
return (epicsThreadId)tid;
}
int epicsThreadIsShellContext (epicsThreadPrivateId id)
{
unsigned int varIndex = (unsigned int)id;
rtems_unsigned32 note;
struct taskVar *v;
rtems_task_get_note (RTEMS_SELF, RTEMS_NOTEPAD_TASKVAR, &note);
v = (struct taskVar *)note;
return v->isShell;
}
void epicsThreadSetShellContext (epicsThreadPrivateId id,int isShell)
{
unsigned int varIndex = (unsigned int)id;
rtems_unsigned32 note;
struct taskVar *v;
rtems_task_get_note (RTEMS_SELF, RTEMS_NOTEPAD_TASKVAR, &note);
v = (struct taskVar *)note;
v->isShell = isShell;
}
/*
* Ensure func() is run only once.
*/

View File

@@ -52,6 +52,7 @@ typedef struct win32ThreadParam {
DWORD id;
unsigned epicsPriority;
char isSuspended;
int isShell;
} win32ThreadParam;
typedef struct epicsThreadPrivateOSD {
@@ -844,6 +845,27 @@ epicsShareFunc void epicsShareAPI epicsThreadGetName (
}
}
/*
* epicsThreadIsShellContext ()
*/
epicsShareFunc int epicsShareAPI epicsThreadIsShellContext ( epicsThreadId id )
{
win32ThreadParam *pParm = ( win32ThreadParam * ) id;
return pParm->isShell;
}
/*
* epicsThreadSetShellContext ()
*/
epicsShareFunc int epicsShareAPI epicsThreadSetShellContext (
epicsThreadId id, int isShell)
{
win32ThreadParam *pParm = ( win32ThreadParam * ) id;
pParm->isShell = isShell;
}
/*
* epics_GetThreadPriorityAsString ()
*/

View File

@@ -55,6 +55,7 @@ typedef struct epicsThreadOSD {
int isSuspended;
unsigned int osiPriority;
char *name;
int isShell;
} epicsThreadOSD;
static pthread_key_t getpthreadInfo;
@@ -582,6 +583,18 @@ const char *epicsThreadGetNameSelf()
return(pthreadInfo->name);
}
int epicsThreadIsShellContext(epicsThreadId pthreadInfo) {
assert(epicsThreadOnceCalled);
assert(pthreadInfo);
return pthreadInfo->isShell;
}
void epicsThreadSetShellContext(epicsThreadId pthreadInfo,int isShell) {
assert(epicsThreadOnceCalled);
assert(pthreadInfo);
pthreadInfo->isShell = isShell;
}
void epicsThreadGetName(epicsThreadId pthreadInfo, char *name, size_t size)
{
assert(epicsThreadOnceCalled);

View File

@@ -40,6 +40,9 @@
static const unsigned stackSizeTable[epicsThreadStackBig+1] =
{4000*ARCH_STACK_FACTOR, 6000*ARCH_STACK_FACTOR, 11000*ARCH_STACK_FACTOR};
/*tasVar for isShell*/
int isShell;
/* definitions for implementation of epicsThreadPrivate */
static void **papTSD = 0;
static int nepicsThreadPrivate = 0;
@@ -125,6 +128,7 @@ static void createFunction(EPICSTHREADFUNC func, void *parm)
(*func)(parm);
free(papTSD);
taskVarDelete(tid,(int *)&papTSD);
taskVarDelete(tid,&isShell);
}
epicsThreadId epicsThreadCreate(const char *name,
@@ -145,6 +149,8 @@ epicsThreadId epicsThreadCreate(const char *name,
errlogPrintf("epicsThreadCreate taskSpawn failure for %s\n",name);
return(0);
}
taskVarAdd(tid,&isShell);
taskVarSet(tid,&isShell,0);
return((epicsThreadId)tid);
}
@@ -270,6 +276,16 @@ void epicsThreadGetName (epicsThreadId id, char *name, size_t size)
name[size-1] = '\0';
}
int epicsThreadIsShellContext(epicsThreadId id)
{
return isShell;
}
void epicsThreadSetShellContext(epicsThreadId id,int yesNo)
{
isShell = yesNo;
}
void epicsThreadShowAll(unsigned int level)
{
taskShow(0,2);