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; } } } } }
void assert_new_preferences (void) { instantiation *inst, *next_inst; preference *pref, *next_pref; preference *o_rejects; o_rejects = NIL; /* REW: begin 09.15.96 */ if ((current_agent(operand2_mode) == TRUE) && (current_agent(soar_verbose_flag) == TRUE)) printf("\n in assert_new_preferences:"); /* REW: end 09.15.96 */ for (inst=current_agent(newly_created_instantiations); inst!=NIL; inst=next_inst) { next_inst = inst->next; if (inst->in_ms) insert_at_head_of_dll (inst->prod->instantiations, inst, next, prev); /* REW: begin 09.15.96 */ if (current_agent(operand2_mode) == TRUE) { if (current_agent(soar_verbose_flag) == TRUE) print_with_symbols("\n asserting instantiation: %y\n", inst->prod->name); } /* REW: end 09.15.96 */ for (pref=inst->preferences_generated; pref!=NIL; pref=next_pref) { next_pref = pref->inst_next; if ((pref->type==REJECT_PREFERENCE_TYPE)&&(pref->o_supported)) { /* --- o-reject: just put it in the buffer for later --- */ pref->next = o_rejects; o_rejects = pref; /* REW: begin 09.15.96 */ /* No knowledge retrieval necessary in Operand2 */ /* REW: end 09.15.96 */ } else if (inst->in_ms || pref->o_supported) { /* --- normal case --- */ add_preference_to_tm (pref); /* REW: begin 09.15.96 */ /* No knowledge retrieval necessary in Operand2 */ /* REW: end 09.15.96 */ } else { /* --- inst. is refracted chunk, and pref. is not o-supported: remove the preference --- */ /* --- first splice it out of the clones list--otherwise we might accidentally deallocate some clone that happens to have refcount==0 just because it hasn't been asserted yet --- */ if (pref->next_clone) pref->next_clone->prev_clone = pref->prev_clone; if (pref->prev_clone) pref->prev_clone->next_clone = pref->next_clone; pref->next_clone = pref->prev_clone = NIL; /* --- now add then remove ref--this should result in deallocation */ preference_add_ref (pref); preference_remove_ref (pref); } } } if (o_rejects) process_o_rejects_and_deallocate_them (o_rejects); }