more changes for threadPrivate
This commit is contained in:
@@ -228,17 +228,17 @@ threadGetIdSelf (void)
|
||||
* Thread private storage implementation based on the vxWorks
|
||||
* implementation by Andrew Johnson APS/ASD.
|
||||
*/
|
||||
threadVarId threadPrivateCreate ()
|
||||
threadPrivateId threadPrivateCreate ()
|
||||
{
|
||||
return (void *)++threadVariableCount;
|
||||
}
|
||||
|
||||
void threadPrivateDelete (threadVarId id)
|
||||
void threadPrivateDelete (threadPrivateId id)
|
||||
{
|
||||
/* empty */
|
||||
}
|
||||
|
||||
void threadPrivateSet (threadVarId id, void *pvt)
|
||||
void threadPrivateSet (threadPrivateId id, void *pvt)
|
||||
{
|
||||
int varIndex = (int)id;
|
||||
rtems_unsigned32 note;
|
||||
@@ -266,7 +266,7 @@ void threadPrivateSet (threadVarId id, void *pvt)
|
||||
v->threadVariables[varIndex] = pvt;
|
||||
}
|
||||
|
||||
void * threadPrivateGet (threadVarId id)
|
||||
void * threadPrivateGet (threadPrivateId id)
|
||||
{
|
||||
assert (taskVars);
|
||||
return ((struct taskVars *)taskVars)->threadVariables[(int)id];
|
||||
|
||||
@@ -337,7 +337,7 @@ epicsShareFunc threadId epicsShareAPI threadGetIdSelf (void)
|
||||
return (threadId) TlsGetValue (tlsIndexWIN32);
|
||||
}
|
||||
|
||||
epicsShareFunc threadVarId epicsShareAPI threadPrivateCreate ()
|
||||
epicsShareFunc threadPrivateId epicsShareAPI threadPrivateCreate ()
|
||||
{
|
||||
osdThreadPrivate *p = (osdThreadPrivate *) malloc (sizeof (*p));
|
||||
if (p) {
|
||||
@@ -347,24 +347,24 @@ epicsShareFunc threadVarId epicsShareAPI threadPrivateCreate ()
|
||||
p = 0;
|
||||
}
|
||||
}
|
||||
return (threadVarId) p;
|
||||
return (threadPrivateId) p;
|
||||
}
|
||||
|
||||
epicsShareFunc void epicsShareAPI threadPrivateDelete (threadVarId id)
|
||||
epicsShareFunc void epicsShareAPI threadPrivateDelete (threadPrivateId id)
|
||||
{
|
||||
osdThreadPrivate *p = (osdThreadPrivate *) id;
|
||||
BOOL stat = TlsFree (p->key);
|
||||
assert (stat);
|
||||
}
|
||||
|
||||
epicsShareFunc void epicsShareAPI threadPrivateSet (threadVarId id, void *pVal)
|
||||
epicsShareFunc void epicsShareAPI threadPrivateSet (threadPrivateId id, void *pVal)
|
||||
{
|
||||
struct osdThreadPrivate *pPvt = (struct osdThreadPrivate *) id;
|
||||
BOOL stat = TlsSetValue (pPvt->key, (void *) pVal );
|
||||
assert (stat);
|
||||
}
|
||||
|
||||
epicsShareFunc void * epicsShareAPI threadPrivateGet (threadVarId id)
|
||||
epicsShareFunc void * epicsShareAPI threadPrivateGet (threadPrivateId id)
|
||||
{
|
||||
struct osdThreadPrivate *pPvt = (struct osdThreadPrivate *) id;
|
||||
return (void *) TlsGetValue (pPvt->key);
|
||||
|
||||
@@ -287,7 +287,7 @@ threadId threadGetIdSelf(void) {
|
||||
return((threadId)pthreadInfo);
|
||||
}
|
||||
|
||||
threadVarId threadPrivateCreate(void)
|
||||
threadPrivateId threadPrivateCreate(void)
|
||||
{
|
||||
pthread_key_t *key;
|
||||
int status;
|
||||
@@ -295,10 +295,10 @@ threadVarId threadPrivateCreate(void)
|
||||
key = callocMustSucceed(1,sizeof(pthread_key_t),"threadPrivateCreate");
|
||||
status = pthread_key_create(key,0);
|
||||
checkStatusQuit(status,"pthread_key_create","threadPrivateCreate");
|
||||
return((threadVarId)key);
|
||||
return((threadPrivateId)key);
|
||||
}
|
||||
|
||||
void threadPrivateDelete(threadVarId id)
|
||||
void threadPrivateDelete(threadPrivateId id)
|
||||
{
|
||||
pthread_key_t *key = (pthread_key_t *)id;
|
||||
int status;
|
||||
@@ -307,7 +307,7 @@ void threadPrivateDelete(threadVarId id)
|
||||
checkStatusQuit(status,"pthread_key_delete","threadPrivateDelete");
|
||||
}
|
||||
|
||||
void threadPrivateSet (threadVarId id, void *value)
|
||||
void threadPrivateSet (threadPrivateId id, void *value)
|
||||
{
|
||||
pthread_key_t *key = (pthread_key_t *)id;
|
||||
int status;
|
||||
@@ -316,7 +316,7 @@ void threadPrivateSet (threadVarId id, void *value)
|
||||
checkStatusQuit(status,"pthread_setspecific","threadPrivateSet");
|
||||
}
|
||||
|
||||
void *threadPrivateGet(threadVarId id)
|
||||
void *threadPrivateGet(threadPrivateId id)
|
||||
{
|
||||
pthread_key_t *key = (pthread_key_t *)id;
|
||||
int status;
|
||||
|
||||
@@ -35,14 +35,9 @@ of this distribution.
|
||||
static const unsigned stackSizeTable[threadStackBig+1] =
|
||||
{4000*ARCH_STACK_FACTOR, 6000*ARCH_STACK_FACTOR, 11000*ARCH_STACK_FACTOR};
|
||||
|
||||
/* definitions for implementation of threadPrivate */
|
||||
typedef struct threadPrivateInfo {
|
||||
int nthreadPrivate;
|
||||
void **papTSD; /*pointer to array of pointers to thread specific data*/
|
||||
}threadPrivateInfo;
|
||||
|
||||
static threadPrivateInfo *pthreadPrivateInfo = 0;
|
||||
static int npthreadPrivate = 0;
|
||||
/* definitions for implementation of threadPrivate */
|
||||
static void **papTSD = 0;
|
||||
static int nthreadPrivate = 0;
|
||||
|
||||
/* Just map osi 0 to 99 into vx 100 to 199 */
|
||||
/* remember that for vxWorks lower number means higher priority */
|
||||
@@ -80,17 +75,10 @@ static void createFunction(THREADFUNC func, void *parm)
|
||||
{
|
||||
int tid = taskIdSelf();
|
||||
|
||||
taskVarAdd(tid,(int *)&pthreadPrivateInfo);
|
||||
pthreadPrivateInfo = callocMustSucceed(
|
||||
1,sizeof(threadPrivateInfo),"threadPrivateSet");
|
||||
pthreadPrivateInfo->nthreadPrivate = 1;
|
||||
pthreadPrivateInfo->papTSD = callocMustSucceed(
|
||||
pthreadPrivateInfo->nthreadPrivate,
|
||||
sizeof(void *),"threadPrivateAlloc");
|
||||
taskVarAdd(tid,(int *)&papTSD);
|
||||
(*func)(parm);
|
||||
taskVarDelete(tid,(int *)&pthreadPrivateInfo);
|
||||
free(pthreadPrivateInfo->papTSD);
|
||||
free(pthreadPrivateInfo);
|
||||
taskVarDelete(tid,(int *)&papTSD);
|
||||
free(papTSD);
|
||||
}
|
||||
|
||||
threadId threadCreate(const char *name,
|
||||
@@ -178,23 +166,25 @@ threadId threadGetIdSelf(void)
|
||||
|
||||
/* The following algorithm was thought of by Andrew Johnson APS/ASD .
|
||||
* The basic idea is to use a single vxWorks task variable.
|
||||
* The task variable is pthreadPrivateInfo.
|
||||
* The variable papTSD is an array of pointers to the TSD.
|
||||
* The array size is equal to the number of threadVarIds created
|
||||
* The task variable is papTSD, which is an array of pointers to the TSD
|
||||
* The array size is equal to the number of threadPrivateIds created + 1
|
||||
* when threadPrivateSet is called.
|
||||
* Until the first call to threadPrivateCreate by a application papTSD=0
|
||||
* After first call papTSD[0] is value of nthreadPrivate when
|
||||
* threadPrivateSet was last called by the thread. This is also
|
||||
* the value of threadPrivateId.
|
||||
* The algorithm allows for threadPrivateCreate being called after
|
||||
* the first call to threadPrivateSet.
|
||||
*/
|
||||
|
||||
|
||||
threadVarId threadPrivateCreate()
|
||||
threadPrivateId threadPrivateCreate()
|
||||
{
|
||||
return((void *)++npthreadPrivate);
|
||||
return((void *)++nthreadPrivate);
|
||||
}
|
||||
|
||||
void threadPrivateDelete(threadVarId id)
|
||||
void threadPrivateDelete(threadPrivateId id)
|
||||
{
|
||||
/*not safe to delete anything*/
|
||||
/*nothing to delete */
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -202,24 +192,30 @@ void threadPrivateDelete(threadVarId id)
|
||||
*note that it is not necessary to have mutex for following
|
||||
*because they must be called by the same thread
|
||||
*/
|
||||
void threadPrivateSet (threadVarId id, void *pvt)
|
||||
void threadPrivateSet (threadPrivateId id, void *pvt)
|
||||
{
|
||||
int indpthreadPrivate = (int)id;
|
||||
|
||||
assert(pthreadPrivateInfo);
|
||||
if(pthreadPrivateInfo->nthreadPrivate <= indpthreadPrivate) {
|
||||
pthreadPrivateInfo->papTSD = realloc(pthreadPrivateInfo->papTSD,
|
||||
(indpthreadPrivate+1)*sizeof(void *));
|
||||
if(!pthreadPrivateInfo->papTSD)
|
||||
cantProceed("threadPrivateSet calloc failed\n");
|
||||
pthreadPrivateInfo->nthreadPrivate = indpthreadPrivate+1;
|
||||
if(!papTSD) {
|
||||
papTSD = callocMustSucceed(indpthreadPrivate + 1,sizeof(void *),
|
||||
"threadPrivateSet");
|
||||
papTSD[0] = (void *)(indpthreadPrivate);
|
||||
} else {
|
||||
int nthreadPrivate = (int)papTSD[0];
|
||||
if(nthreadPrivate < indpthreadPrivate) {
|
||||
void **ptemp;
|
||||
ptemp = realloc(papTSD,(indpthreadPrivate+1)*sizeof(void *));
|
||||
if(!ptemp) cantProceed("threadPrivateSet realloc failed\n");
|
||||
papTSD = ptemp;
|
||||
papTSD[0] = (void *)(indpthreadPrivate);
|
||||
}
|
||||
}
|
||||
pthreadPrivateInfo->papTSD[indpthreadPrivate] = pvt;
|
||||
cantProceed("threadPrivateSet calloc failed\n");
|
||||
papTSD[indpthreadPrivate] = pvt;
|
||||
}
|
||||
|
||||
void *threadPrivateGet(threadVarId id)
|
||||
void *threadPrivateGet(threadPrivateId id)
|
||||
{
|
||||
assert(pthreadPrivateInfo);
|
||||
return(pthreadPrivateInfo->papTSD[(int)id]);
|
||||
assert(papTSD);
|
||||
assert((int)id <= (int)papTSD[0]);
|
||||
return(papTSD[(int)id]);
|
||||
}
|
||||
|
||||
@@ -45,11 +45,11 @@ epicsShareFunc int epicsShareAPI threadIsSuspended(threadId id);
|
||||
epicsShareFunc void epicsShareAPI threadSleep(double seconds);
|
||||
epicsShareFunc threadId epicsShareAPI threadGetIdSelf(void);
|
||||
|
||||
typedef void * threadVarId;
|
||||
epicsShareFunc threadVarId epicsShareAPI threadPrivateCreate (void);
|
||||
epicsShareFunc void epicsShareAPI threadPrivateDelete (threadVarId id);
|
||||
epicsShareFunc void epicsShareAPI threadPrivateSet (threadVarId, void *);
|
||||
epicsShareFunc void * epicsShareAPI threadPrivateGet (threadVarId);
|
||||
typedef void * threadPrivateId;
|
||||
epicsShareFunc threadPrivateId epicsShareAPI threadPrivateCreate (void);
|
||||
epicsShareFunc void epicsShareAPI threadPrivateDelete (threadPrivateId id);
|
||||
epicsShareFunc void epicsShareAPI threadPrivateSet (threadPrivateId, void *);
|
||||
epicsShareFunc void * epicsShareAPI threadPrivateGet (threadPrivateId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
void set (T *);
|
||||
class unableToCreateThreadPrivate {}; // exception
|
||||
private:
|
||||
threadVarId id;
|
||||
threadPrivateId id;
|
||||
};
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
Reference in New Issue
Block a user