From 52712bf7b79436a66b0427c26913cdcc87bb0443 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Mon, 13 Apr 1998 19:14:36 +0000 Subject: [PATCH] fixed task variable problem --- src/ca/access.c | 60 ++++---------------------- src/ca/iocinf.h | 5 ++- src/ca/posix_depen.c | 37 +++++++++++----- src/ca/vms_depen.c | 37 +++++++++++----- src/ca/vxWorks_depen.c | 96 ++++++++++++++++++++++++++++++------------ src/ca/windows_depen.c | 45 +++++++++++++++----- 6 files changed, 168 insertions(+), 112 deletions(-) diff --git a/src/ca/access.c b/src/ca/access.c index c406d27b8..738325931 100644 --- a/src/ca/access.c +++ b/src/ca/access.c @@ -99,6 +99,9 @@ /************************************************************************/ /* * $Log$ + * Revision 1.101 1998/03/12 20:39:05 jhill + * fixed problem where 3.13.beta11 unable to connect to 3.11 with correct native type + * * Revision 1.100 1998/02/05 21:55:49 jhill * detect attempts by user to clear bogus channel * @@ -643,29 +646,6 @@ LOCAL void cac_add_msg (IIU *piiu) sizeof(caHdr) + size); } - - -/* - * CA_TASK_INITIALIZE - */ -int epicsShareAPI ca_task_initialize(void) -{ - int status; - struct CA_STATIC *ca_temp; - - if (!ca_static) { - ca_temp = (struct CA_STATIC *) - calloc(1, sizeof(*ca_temp)); - if (!ca_temp) { - return ECA_ALLOCMEM; - } - status = cac_os_depen_init (ca_temp); - return status; - } - - return ECA_NORMAL; -} - /* * ca_os_independent_init () @@ -684,7 +664,6 @@ int ca_os_independent_init (void) /* record a default user name */ ca_static->ca_pUserName = localUserName(); if(!ca_static->ca_pUserName){ - free(ca_static); return ECA_ALLOCMEM; } @@ -692,7 +671,6 @@ int ca_os_independent_init (void) ca_static->ca_pHostName = localHostName(); if(!ca_static->ca_pHostName){ free(ca_static->ca_pUserName); - free(ca_static); return ECA_ALLOCMEM; } @@ -857,28 +835,6 @@ int epicsShareAPI ca_modify_user_name(const char *pClientName) } - -/* - * CA_TASK_EXIT() - * - * call this routine if you wish to free resources prior to task - * exit- ca_task_exit() is also executed routinely at task exit. - */ -int epicsShareAPI ca_task_exit (void) -{ - if (!ca_static) { - return ECA_NOCACTX; - } - - /* - * This indirectly calls ca_process_exit() below - */ - cac_os_depen_exit(ca_static); - - return ECA_NORMAL; -} - - /* * @@ -891,12 +847,12 @@ int epicsShareAPI ca_task_exit (void) */ void ca_process_exit() { - chid chix; - chid chixNext; - IIU *piiu; - int status; + chid chix; + chid chixNext; + IIU *piiu; + int status; - assert(ca_static); + assert (ca_static); LOCK; diff --git a/src/ca/iocinf.h b/src/ca/iocinf.h index 00960f234..9614ecc0f 100644 --- a/src/ca/iocinf.h +++ b/src/ca/iocinf.h @@ -32,6 +32,9 @@ /************************************************************************/ /* $Log$ + * Revision 1.69 1998/03/12 20:39:10 jhill + * fixed problem where 3.13.beta11 unable to connect to 3.11 with correct native type + * * Revision 1.68 1998/02/20 21:52:21 evans * Added an explicit include of tsDefs.h before cadef.h to avoid the * functions in it being declared as export and also to avoid its @@ -723,8 +726,6 @@ void cac_block_for_sg_completion(CASG *pcasg, struct timeval *pTV); void os_specific_sg_create(CASG *pcasg); void os_specific_sg_delete(CASG *pcasg); void os_specific_sg_io_complete(CASG *pcasg); -int cac_os_depen_init(struct CA_STATIC *pcas); -void cac_os_depen_exit (struct CA_STATIC *pcas); void ca_process_exit(); void ca_spawn_repeater(void); void cac_gettimeval(struct timeval *pt); diff --git a/src/ca/posix_depen.c b/src/ca/posix_depen.c index e34fced26..c79d59ae4 100644 --- a/src/ca/posix_depen.c +++ b/src/ca/posix_depen.c @@ -29,6 +29,9 @@ * Modification Log: * ----------------- * $Log$ + * Revision 1.23 1997/08/04 23:37:14 jhill + * added beacon anomaly flag init/allow ip 255.255.255.255 + * * Revision 1.22 1997/06/13 09:14:23 jhill * connect/search proto changes * @@ -124,32 +127,44 @@ int cac_add_task_variable(struct CA_STATIC *ca_temp) /* - * cac_os_depen_init() + * ca_task_initialize() */ -int cac_os_depen_init(struct CA_STATIC *pcas) +int epicsShareAPI ca_task_initialize(void) { - int status; + int status; - ca_static = pcas; + if (ca_static) { + return ECA_NORMAL; + } + + ca_static = (struct CA_STATIC *) + calloc(1, sizeof(*ca_static)); + if (!ca_static) { + return ECA_ALLOCMEM; + } status = ca_os_independent_init (); - return status; + return status; } /* - * cac_os_depen_exit () + * ca_task_exit () + * + * call this routine if you wish to free resources prior to task + * exit- ca_task_exit() is also executed routinely at task exit. */ -void cac_os_depen_exit (struct CA_STATIC *pcas) +int epicsShareAPI ca_task_exit (void) { - ca_static = pcas; + if (!ca_static) { + return ECA_NOCACTX; + } ca_process_exit(); + free ((char *)ca_static); ca_static = NULL; - - free ((char *)pcas); + return ECA_NORMAL; } - /* * diff --git a/src/ca/vms_depen.c b/src/ca/vms_depen.c index 0904a777a..1966c77ec 100644 --- a/src/ca/vms_depen.c +++ b/src/ca/vms_depen.c @@ -32,6 +32,9 @@ * cjm 20-Nov-95 Add code for gettimeofday * * $Log$ + * Revision 1.23 1998/02/05 22:36:01 jhill + * added starlet.h (SLAC's request) + * * Revision 1.22 1997/06/13 09:14:27 jhill * connect/search proto changes * @@ -169,30 +172,42 @@ void cac_block_for_sg_completion(CASG *pcasg, struct timeval *pTV) /* - * cac_os_depen_init() + * ca_task_initialize() */ -int cac_os_depen_init(struct CA_STATIC *pcas) +int epicsShareAPI ca_task_initialize(void) { - int status; + int status; - ca_static = pcas; + if (ca_static) { + return ECA_NORMAL; + } + + ca_static = (struct CA_STATIC *) + calloc(1, sizeof(*ca_static)); + if (!ca_static) { + return ECA_ALLOCMEM; + } status = ca_os_independent_init (); return status; } - /* - * cac_os_depen_exit () + * ca_task_exit () + * + * call this routine if you wish to free resources prior to task + * exit- ca_task_exit() is also executed routinely at task exit. */ -void cac_os_depen_exit (struct CA_STATIC *pcas) +int epicsShareAPI ca_task_exit (void) { - ca_static = pcas; - ca_process_exit(); + if (!ca_static) { + return ECA_NOCACTX; + } + ca_process_exit(); + free ((char *)ca_static); ca_static = NULL; - - free ((char *)pcas); + return ECA_NORMAL; } diff --git a/src/ca/vxWorks_depen.c b/src/ca/vxWorks_depen.c index 13da51033..c1da45aa4 100644 --- a/src/ca/vxWorks_depen.c +++ b/src/ca/vxWorks_depen.c @@ -29,6 +29,9 @@ * Modification Log: * ----------------- * $Log$ + * Revision 1.34 1998/02/05 22:39:46 jhill + * use inversion safe mutex + * * Revision 1.33 1997/08/04 23:37:19 jhill * added beacon anomaly flag init/allow ip 255.255.255.255 * @@ -309,6 +312,11 @@ LOCAL int cac_add_task_variable (struct CA_STATIC *ca_temp) return ECA_INTERNAL; } + /* + * Care is taken not to set the value of the + * ca static task variable until after it has been installed + * so that we dont change the value for other tasks. + */ ca_static = ca_temp; ellAdd(&ca_temp->ca_taskVarList, &ptviu->node); @@ -369,38 +377,61 @@ LOCAL void ca_task_exit_tcb(WIND_TCB *ptcb) /* - * cac_os_depen_init() + * ca_task_initialize() */ -int cac_os_depen_init(struct CA_STATIC *pcas) +int ca_task_initialize () { - char name[15]; - int status; + struct CA_STATIC *pcas; + char name[15]; + int status; - ellInit(&pcas->ca_local_chidlist); - ellInit(&pcas->ca_lcl_buff_list); - ellInit(&pcas->ca_taskVarList); - ellInit(&pcas->ca_putNotifyQue); + pcas = (struct CA_STATIC *) + taskVarGet (taskIdSelf(), (int *)&ca_static); + if (pcas != (struct CA_STATIC *) ERROR) { + return ECA_NORMAL; + } - freeListInitPvt(&pcas->ca_dbMonixFreeList, - db_sizeof_event_block()+sizeof(struct pending_event),256); + pcas = (struct CA_STATIC *) + calloc(1, sizeof(*pcas)); + if (!pcas) { + return ECA_ALLOCMEM; + } - pcas->ca_tid = taskIdSelf(); - pcas->ca_client_lock = semMCreate(SEM_DELETE_SAFE|SEM_INVERSION_SAFE|SEM_Q_PRIORITY); + ellInit (&pcas->ca_local_chidlist); + ellInit (&pcas->ca_lcl_buff_list); + ellInit (&pcas->ca_taskVarList); + ellInit (&pcas->ca_putNotifyQue); + + freeListInitPvt (&pcas->ca_dbMonixFreeList, + db_sizeof_event_block ()+sizeof(struct pending_event),256); + + pcas->ca_tid = taskIdSelf (); + pcas->ca_client_lock = semMCreate (SEM_DELETE_SAFE|SEM_INVERSION_SAFE|SEM_Q_PRIORITY); assert (pcas->ca_client_lock); - pcas->ca_putNotifyLock = semMCreate(SEM_DELETE_SAFE|SEM_INVERSION_SAFE|SEM_Q_PRIORITY); + pcas->ca_putNotifyLock = semMCreate (SEM_DELETE_SAFE|SEM_INVERSION_SAFE|SEM_Q_PRIORITY); assert (pcas->ca_putNotifyLock); - pcas->ca_io_done_sem = semBCreate(SEM_Q_PRIORITY, SEM_EMPTY); + pcas->ca_io_done_sem = semBCreate (SEM_Q_PRIORITY, SEM_EMPTY); assert (pcas->ca_io_done_sem); - pcas->ca_blockSem = semBCreate(SEM_Q_PRIORITY, SEM_EMPTY); + pcas->ca_blockSem = semBCreate (SEM_Q_PRIORITY, SEM_EMPTY); assert (pcas->ca_blockSem); status = cac_add_task_variable (pcas); if (status != ECA_NORMAL) { + semDelete (pcas->ca_client_lock); + semDelete (pcas->ca_putNotifyLock); + semDelete (pcas->ca_io_done_sem); + semDelete (pcas->ca_blockSem); return status; } status = ca_os_independent_init (); if (status != ECA_NORMAL){ + ca_import_cancel (taskIdSelf()); + freeListCleanup (pcas->ca_dbMonixFreeList); + semDelete (pcas->ca_client_lock); + semDelete (pcas->ca_putNotifyLock); + semDelete (pcas->ca_io_done_sem); + semDelete (pcas->ca_blockSem); return status; } @@ -430,11 +461,19 @@ int cac_os_depen_init(struct CA_STATIC *pcas) /* - * cac_os_depen_exit () + * ca_task_exit () */ -void cac_os_depen_exit (struct CA_STATIC *pcas) +int epicsShareAPI ca_task_exit (void) { - cac_os_depen_exit_tid (pcas, 0); + struct CA_STATIC *pcas; + + pcas = (struct CA_STATIC *) + taskVarGet (taskIdSelf(), (int *)&ca_static); + if (pcas == (struct CA_STATIC *) ERROR) { + return ECA_NOCACTX; + } + + return cac_os_depen_exit_tid (pcas, 0); } @@ -450,10 +489,10 @@ LOCAL int cac_os_depen_exit_tid (struct CA_STATIC *pcas, int tid) CALLBACK *pcb; -# ifdef DEBUG - ca_printf("CAC: entering the exit routine %x %x\n", - tid, pcas); -# endif +# ifdef DEBUG + ca_printf("CAC: entering the exit routine %x %x\n", + tid, pcas); +# endif ca_static = pcas; LOCK; @@ -510,7 +549,7 @@ LOCAL int cac_os_depen_exit_tid (struct CA_STATIC *pcas, int tid) * set ca_static for access.c * (run this before deleting the task variable) */ - ca_process_exit(); + ca_process_exit(); /* * cancel task vars for other tasks so this @@ -698,8 +737,6 @@ int ca_import (int tid) return ECA_ALLOCMEM; } - ca_static = pcas; - status = taskVarAdd (VXTHISTASKID, (int *)&ca_static); if (status == ERROR){ ca_static = NULL; @@ -707,6 +744,13 @@ int ca_import (int tid) return ECA_ALLOCMEM; } + /* + * Care is taken not to set the value of the + * ca static task variable until after it has been installed + * so that we dont change the value for other tasks. + */ + ca_static = pcas; + ptviu->tid = taskIdSelf(); LOCK; ellAdd(&ca_static->ca_taskVarList, &ptviu->node); @@ -914,7 +958,7 @@ void cac_recv_task(int tid) taskwdInsert((int) taskIdCurrent, NULL, NULL); status = ca_import(tid); - SEVCHK(status, NULL); + SEVCHK(status, "cac_recv_task()"); /* * once started, does not exit until diff --git a/src/ca/windows_depen.c b/src/ca/windows_depen.c index f05b1477d..15183fe2a 100644 --- a/src/ca/windows_depen.c +++ b/src/ca/windows_depen.c @@ -32,6 +32,9 @@ * Modification Log: * ----------------- * $Log$ + * Revision 1.35 1998/04/10 23:00:57 jhill + * link with user32 lib under WIN32 + * * Revision 1.34 1998/03/24 20:55:06 jhill * fixed console title/correct repeater spawn/correct winsock II URL * @@ -58,6 +61,9 @@ * * Revision 1.19 1995/11/29 19:15:42 jhill * added $Log$ + * added Revision 1.35 1998/04/10 23:00:57 jhill + * added link with user32 lib under WIN32 + * added * added Revision 1.34 1998/03/24 20:55:06 jhill * added fixed console title/correct repeater spawn/correct winsock II URL * added @@ -169,13 +175,26 @@ void cac_block_for_sg_completion(CASG *pcasg, struct timeval *pTV) /* - * cac_os_depen_init() + * ca_task_initialize() */ -int cac_os_depen_init(struct CA_STATIC *pcas) +int epicsShareAPI ca_task_initialize(void) { - int status; + int status; - ca_static = pcas; + if (ca_static) { + return ECA_NORMAL; + } + + ca_static = (struct CA_STATIC *) + calloc(1, sizeof(*ca_static)); + if (!ca_static) { + return ECA_ALLOCMEM; + } + + status = ca_os_independent_init (); + if (status) { + return status; + } /* DllMain does most OS dependent init & cleanup */ status = ca_os_independent_init (); @@ -194,20 +213,26 @@ int cac_os_depen_init(struct CA_STATIC *pcas) if(!ca_static->ca_piiuCast){ return ECA_NOCAST; } + return ECA_NORMAL; } /* - * cac_os_depen_exit () + * ca_task_exit () + * + * call this routine if you wish to free resources prior to task + * exit- ca_task_exit() is also executed routinely at task exit. */ -void cac_os_depen_exit (struct CA_STATIC *pcas) +int epicsShareAPI ca_task_exit (void) { - ca_static = pcas; - ca_process_exit(); + if (!ca_static) { + return ECA_NOCACTX; + } + ca_process_exit(); + free ((char *)ca_static); ca_static = NULL; - - free ((char *)pcas); + return ECA_NORMAL; }