static void free_comp_struct(hal_comp_t * comp) { int *prev, next; #ifdef RTAPI hal_funct_t *funct; #endif /* RTAPI */ hal_pin_t *pin; hal_param_t *param; /* can't delete the component until we delete its "stuff" */ /* need to check for functs only if a realtime component */ #ifdef RTAPI /* search the function list for this component's functs */ prev = &(hal_data->funct_list_ptr); next = *prev; while (next != 0) { funct = SHMPTR(next); if (SHMPTR(funct->owner_ptr) == comp) { /* this function belongs to our component, unlink from list */ *prev = funct->next_ptr; /* and delete it */ free_funct_struct(funct); } else { /* no match, try the next one */ prev = &(funct->next_ptr); } next = *prev; } #endif /* RTAPI */ /* search the pin list for this component's pins */ prev = &(hal_data->pin_list_ptr); next = *prev; while (next != 0) { pin = SHMPTR(next); if (SHMPTR(pin->owner_ptr) == comp) { /* this pin belongs to our component, unlink from list */ *prev = pin->next_ptr; /* and delete it */ free_pin_struct(pin); } else { /* no match, try the next one */ prev = &(pin->next_ptr); } next = *prev; } /* search the parameter list for this component's parameters */ prev = &(hal_data->param_list_ptr); next = *prev; while (next != 0) { param = SHMPTR(next); if (SHMPTR(param->owner_ptr) == comp) { /* this param belongs to our component, unlink from list */ *prev = param->next_ptr; /* and delete it */ free_param_struct(param); } else { /* no match, try the next one */ prev = &(param->next_ptr); } next = *prev; } /* now we can delete the component itself */ /* clear contents of struct */ comp->comp_id = -1; comp->type = TYPE_INVALID; comp->state = COMP_INVALID; comp->last_bound = 0; comp->last_unbound = 0; comp->last_update = 0; comp->shmem_base = 0; comp->name[0] = '\0'; /* add it to free list */ comp->next_ptr = hal_data->comp_free_ptr; hal_data->comp_free_ptr = SHMOFF(comp); }
static void free_comp_struct(hal_comp_t * comp) { int *prev, next; #ifdef RTAPI hal_funct_t *funct; #endif /* RTAPI */ hal_pin_t *pin; hal_param_t *param; /* can't delete the component until we delete its "stuff" */ /* need to check for functs only if a realtime component */ #ifdef RTAPI // first unlink and destroy all functs, so an RT thread // cant trample on the comp while it's being destroyed /* search the function list for this component's functs */ prev = &(hal_data->funct_list_ptr); next = *prev; while (next != 0) { funct = SHMPTR(next); hal_comp_t *owner = halpr_find_owning_comp(funct->owner_id); if (owner == comp) { /* this function belongs to our component, unlink from list */ *prev = funct->next_ptr; /* and delete it */ free_funct_struct(funct); } else { /* no match, try the next one */ prev = &(funct->next_ptr); } next = *prev; } // here, technically all the comp's functs are // delf'd and not visible anymore // now that the funct is gone, // exit all the comp's instances next = hal_data->inst_list_ptr; while (next != 0) { hal_inst_t *inst = SHMPTR(next); next = inst->next_ptr; if (inst->comp_id == comp->comp_id) { // this instance is owned by this comp free_inst_struct(inst); } } // here all insts, their pins, params and functs are gone. #endif /* RTAPI */ // now work the legacy pins and params which are // directly owned by the comp. /* search the pin list for this component's pins */ prev = &(hal_data->pin_list_ptr); next = *prev; while (next != 0) { pin = SHMPTR(next); if (pin->owner_id == comp->comp_id) { /* this pin belongs to our component, unlink from list */ *prev = pin->next_ptr; /* and delete it */ free_pin_struct(pin); } else { /* no match, try the next one */ prev = &(pin->next_ptr); } next = *prev; } /* search the parameter list for this component's parameters */ prev = &(hal_data->param_list_ptr); next = *prev; while (next != 0) { param = SHMPTR(next); if (param->owner_id == comp->comp_id) { /* this param belongs to our component, unlink from list */ *prev = param->next_ptr; /* and delete it */ free_param_struct(param); } else { /* no match, try the next one */ prev = &(param->next_ptr); } next = *prev; } /* now we can delete the component itself */ /* clear contents of struct */ comp->comp_id = 0; comp->type = TYPE_INVALID; comp->state = COMP_INVALID; comp->last_bound = 0; comp->last_unbound = 0; comp->last_update = 0; comp->shmem_base = 0; comp->name[0] = '\0'; }
// almost a copy of free_comp_struct(), but based on instance // // unlinks and frees functs exported by this instance // then calls any custom destructor // then unlinks & deletes all pins owned by this instance // then deletes params owned by this instance void free_inst_struct(hal_inst_t * inst) { int *prev, next; #ifdef RTAPI hal_funct_t *funct; #endif /* RTAPI */ hal_pin_t *pin; hal_param_t *param; /* can't delete the instance until we delete its "stuff" */ /* need to check for functs only if a realtime component */ #ifdef RTAPI /* search the function list for this instance's functs */ prev = &(hal_data->funct_list_ptr); next = *prev; while (next != 0) { funct = SHMPTR(next); if (funct->owner_id == inst->inst_id) { /* this function belongs to this instance, unlink from list */ *prev = funct->next_ptr; /* and delete it */ free_funct_struct(funct); } else { /* no match, try the next one */ prev = &(funct->next_ptr); } next = *prev; } // now that the funct is gone, call the dtor for this instance // get owning comp hal_comp_t *comp = halpr_find_owning_comp(inst->comp_id); if (comp->dtor) { //NB - pins, params etc still intact // this instance is owned by this comp, call destructor HALDBG("calling custom destructor(%s,%s)", comp->name, inst->name); comp->dtor(inst->name, SHMPTR(inst->inst_data_ptr), inst->inst_size); } #endif /* RTAPI */ /* search the pin list for this instance's pins */ prev = &(hal_data->pin_list_ptr); next = *prev; while (next != 0) { pin = SHMPTR(next); if (pin->owner_id == inst->inst_id) { /* this pin belongs to our instance, unlink from list */ *prev = pin->next_ptr; /* and delete it */ free_pin_struct(pin); } else { /* no match, try the next one */ prev = &(pin->next_ptr); } next = *prev; } /* search the parameter list for this instance's parameters */ prev = &(hal_data->param_list_ptr); next = *prev; while (next != 0) { param = SHMPTR(next); if (param->owner_id == inst->inst_id) { /* this param belongs to our instance, unlink from list */ *prev = param->next_ptr; /* and delete it */ free_param_struct(param); } else { /* no match, try the next one */ prev = &(param->next_ptr); } next = *prev; } /* now we can delete the instance itself */ // search the instance list and unlink instances owned by this comp hal_inst_t *ip; prev = &(hal_data->inst_list_ptr); next = *prev; while (next != 0) { ip = SHMPTR(next); if (ip == inst) { // this instance is owned by this comp *prev = ip->next_ptr; // zap the instance structure ip->comp_id = 0; ip->inst_id = 0; ip->inst_data_ptr = 0; // NB - loosing HAL memory here ip->inst_size = 0; ip->name[0] = '\0'; // add it to free list ip->next_ptr = hal_data->inst_free_ptr; hal_data->inst_free_ptr = SHMOFF(ip); } else { prev = &(ip->next_ptr); } next = *prev; } }