bool remove_preference_from_clones_and_deallocate(agent* thisAgent, preference* pref) { preference* any_clone = NIL; if (pref->next_clone) { any_clone = pref->next_clone; pref->next_clone->prev_clone = pref->prev_clone; } if (pref->prev_clone) { any_clone = pref->prev_clone; pref->prev_clone->next_clone = pref->next_clone; } pref->next_clone = pref->prev_clone = NIL; if (any_clone) { possibly_deallocate_preference_and_clones(thisAgent, any_clone); } if (!pref->reference_count) { deallocate_preference(thisAgent, pref); return true; } else { return false; } }
void SMem_Manager::install_buffered_triple_list(Symbol* state, wme_set& cue_wmes, symbol_triple_list& my_list, bool meta, bool stripLTILinks) { if (my_list.empty()) { return; } dprint(DT_SMEM_INSTANCE, "install_buffered_triple_list called in state %y. Creating architectural instantiation.\n", state); instantiation* inst = make_architectural_instantiation_for_memory_system(thisAgent, state, &cue_wmes, &my_list, true); for (preference* pref = inst->preferences_generated; pref;) { if (add_preference_to_tm(thisAgent, pref)) { // and add it to the list of preferences to be removed // when the goal is removed dprint(DT_SMEM_INSTANCE, "...adding preference %p to WM\n", pref); insert_at_head_of_dll(state->id->preferences_from_goal, pref, all_of_goal_next, all_of_goal_prev); pref->on_goal_list = true; if (meta) { // if this is a meta wme, then it is completely local // to the state and thus we will manually remove it // (via preference removal) when the time comes state->id->smem_info->smem_wmes->push_back(pref); } } else { dprint(DT_SMEM_INSTANCE, "...could not add preference %p to WM. Deallocating.\n", pref); if (pref->reference_count == 0) { preference* previous = pref; pref = pref->inst_next; possibly_deallocate_preference_and_clones(thisAgent, previous, true); continue; } } if (stripLTILinks) { pref->id->id->LTI_ID = 0; pref->id->update_cached_lti_print_str(); if (pref->value->is_sti()) { pref->value->id->LTI_ID = 0; pref->value->update_cached_lti_print_str(); } } pref = pref->inst_next; } if (!meta) { // Create an architectural instantiation to allow backtracing // for chunks, justifications and the GDS. instantiation* my_justification_list = NIL; dprint(DT_MILESTONES, "Asserting preferences of new architectural instantiation in _smem_process_buffered_wme_list...\n"); // if any justifications are created, assert their preferences manually // (copied mainly from assert_new_preferences with respect to our circumstances) if (my_justification_list != NIL) { preference* just_pref = NIL; instantiation* next_justification = NIL; for (instantiation* my_justification = my_justification_list; my_justification != NIL; my_justification = next_justification) { next_justification = my_justification->next; if (my_justification->in_ms) { insert_at_head_of_dll(my_justification->prod->instantiations, my_justification, next, prev); } for (just_pref = my_justification->preferences_generated; just_pref != NIL;) { if (add_preference_to_tm(thisAgent, just_pref)) { if (wma_enabled(thisAgent)) { wma_activate_wmes_in_pref(thisAgent, just_pref); } } else { if (just_pref->reference_count == 0) { preference* previous = just_pref; just_pref = just_pref->inst_next; possibly_deallocate_preference_and_clones(thisAgent, previous, true); continue; } } just_pref = just_pref->inst_next; } } } } }