Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Typedefs | Functions
prefmem.h File Reference
#include "gdatastructs.h"

Go to the source code of this file.

Typedefs

typedef struct agent_struct agent
typedef char Bool
typedef unsigned char byte
typedef std::list< preference
*, soar_module::soar_memory_pool_allocator
< preference * > > 
pref_buffer_list
typedef struct preference_struct preference
typedef union symbol_union Symbol

Functions

bool add_preference_to_tm (agent *thisAgent, preference *pref)
void deallocate_preference (agent *thisAgent, preference *pref)
preferencemake_preference (agent *thisAgent, byte type, Symbol *id, Symbol *attr, Symbol *value, Symbol *referent)
Bool possibly_deallocate_preference_and_clones (agent *thisAgent, preference *pref)
void preference_add_ref (preference *p)
void preference_remove_ref (agent *thisAgent, preference *p)
void process_o_rejects_and_deallocate_them (agent *thisAgent, preference *o_rejects, pref_buffer_list &bufdeallo)
void remove_preference_from_tm (agent *thisAgent, preference *pref)

Typedef Documentation

typedef struct agent_struct agent

Definition at line 49 of file prefmem.h.

typedef char Bool

Definition at line 47 of file prefmem.h.

typedef unsigned char byte

Definition at line 48 of file prefmem.h.

Definition at line 54 of file prefmem.h.

typedef struct preference_struct preference

Definition at line 50 of file prefmem.h.

typedef union symbol_union Symbol

Definition at line 51 of file prefmem.h.

Function Documentation

bool add_preference_to_tm ( agent thisAgent,
preference pref 
)

Definition at line 213 of file prefmem.cpp.

References ACCEPTABLE_PREFERENCE_TYPE, preference_struct::all_of_slot_next, slot_struct::all_preferences, preference_struct::attr, slot_struct::changed, preference_struct::id, IDENTIFIER_SYMBOL_TYPE, preference_struct::in_tm, insert_at_head_of_dll, preference_struct::inst, slot_struct::isa_context_slot, make_slot(), mark_context_slot_as_acceptable_preference_changed(), mark_slot_as_changed(), instantiation_struct::match_goal, instantiation_struct::match_goal_level, production_struct::next, wme_struct::next, preference_struct::next, NIL, preference_struct::o_supported, post_link_addition(), preference_add_ref(), preference_is_binary(), slot_struct::preferences, production_struct::prev, preference_struct::prev, print(), print_preference(), preference_struct::referent, REQUIRE_PREFERENCE_TYPE, preference_struct::slot, agent_struct::top_state, TRUE, preference_struct::type, wme_struct::value, preference_struct::value, wma_enabled(), agent_struct::wma_slot_refs_pool, slot_struct::wma_val_references, and slot_struct::wmes.

Referenced by _epmem_process_buffered_wme_list(), _smem_process_buffered_wme_list(), and assert_new_preferences().

{
#ifdef DEBUG_PREFS
print (thisAgent, "\nAdd preference at 0x%8x: ",reinterpret_cast<uintptr_t>(pref));
print_preference (thisAgent, pref);
#endif
slot *s = make_slot( thisAgent, pref->id, pref->attr );
if ( !s->isa_context_slot && pref->o_supported && ( pref->type == ACCEPTABLE_PREFERENCE_TYPE ) && ( pref->inst->match_goal == thisAgent->top_state ) )
{
bool already_top_o_supported = false;
for ( p2=s->all_preferences; ( p2 && !already_top_o_supported ); p2=p2->all_of_slot_next )
{
if ( ( p2->value == pref->value ) && p2->o_supported && ( p2->inst->match_goal == thisAgent->top_state ) )
{
already_top_o_supported = true;
}
}
if ( already_top_o_supported )
{
// NLD: if it is suspected that this code is causing an issue, simply comment out the following line to debug.
return false;
}
}
pref->slot = s;
all_of_slot_next, all_of_slot_prev);
/* --- add preference to the list (in the right place, according to match
goal level of the instantiations) for the slot --- */
if (!s->preferences[pref->type])
{
/* --- this is the only pref. of its type, just put it at the head --- */
insert_at_head_of_dll (s->preferences[pref->type], pref, next, prev);
}
else if (s->preferences[pref->type]->inst->match_goal_level >= pref->inst->match_goal_level)
{
/* --- it belongs at the head of the list, so put it there --- */
insert_at_head_of_dll (s->preferences[pref->type], pref, next, prev);
}
else
{
/* --- scan through the pref. list, find the one to insert after --- */
for (p2 = s->preferences[pref->type]; p2->next != NIL; p2 = p2->next)
{
break;
}
/* --- insert pref after p2 --- */
pref->next = p2->next;
pref->prev = p2;
p2->next = pref;
if (pref->next)
pref->next->prev = pref;
}
/* --- other miscellaneous stuff --- */
pref->in_tm = TRUE;
// if it's the case that the slot is unchanged, but has
// some references laying around, clear them
// this doesn't cause immediate memory deallocate/allocate
// but once the WMEs are resolved, this should free the
// memory, as opposed to lead to a "leak"
if ( wma_enabled( thisAgent ) && !s->isa_context_slot )
{
if ( !s->changed )
{
if ( s->wma_val_references != NIL )
{
s->wma_val_references->clear();
}
}
}
mark_slot_as_changed (thisAgent, s);
if ( wma_enabled( thisAgent ) && !s->isa_context_slot )
{
bool exists = false;
wme* w = pref->slot->wmes;
while ( !exists && w )
{
if ( w->value == pref->value )
{
exists = true;
}
w = w->next;
}
// if wme exists, it should already have been updated
// during assertion of new preferences
if ( !exists )
{
if ( s->wma_val_references == NIL )
{
allocate_with_pool( thisAgent, &( thisAgent->wma_slot_refs_pool ), &( s->wma_val_references ) );
#ifdef USE_MEM_POOL_ALLOCATORS
#else
#endif
}
(*s->wma_val_references)[ pref->value ]++;
}
}
/* --- update identifier levels --- */
if (pref->value->common.symbol_type == IDENTIFIER_SYMBOL_TYPE)
{
post_link_addition (thisAgent, pref->id, pref->value);
}
{
if (pref->referent->common.symbol_type == IDENTIFIER_SYMBOL_TYPE)
post_link_addition (thisAgent, pref->id, pref->referent);
}
/* --- if acceptable/require pref for context slot, we may need to add a
wme later --- */
if ((s->isa_context_slot) &&
{
}
return true;
}
void deallocate_preference ( agent thisAgent,
preference pref 
)

Definition at line 105 of file prefmem.cpp.

References abort_with_fatal_error(), preference_struct::attr, BUFFER_MSG_SIZE, preference_struct::id, symbol_union::id, preference_struct::inst, instantiation_struct::match_goal, preference_struct::on_goal_list, possibly_deallocate_instantiation(), preference_is_binary(), agent_struct::preference_pool, identifier_struct::preferences_from_goal, instantiation_struct::preferences_generated, print(), print_preference(), preference_struct::reference_count, preference_struct::referent, remove_from_dll, symbol_remove_ref(), preference_struct::type, preference_struct::value, preference_struct::wma_o_set, and wma_remove_pref_o_set().

Referenced by deallocate_instantiation(), possibly_deallocate_preference_and_clones(), and remove_preference_from_clones().

{
#ifdef DEBUG_PREFS
print (thisAgent, "\nDeallocating preference at 0x%8x: ",reinterpret_cast<uintptr_t>(pref));
print_preference (thisAgent, pref);
if (pref->reference_count != 0) { /* --- sanity check --- */
char msg[BUFFER_MSG_SIZE];
strncpy (msg, "prefmem.c: Internal Error: Deallocating preference with ref. count != 0\n", BUFFER_MSG_SIZE);
msg[BUFFER_MSG_SIZE - 1] = 0; /* ensure null termination */
abort_with_fatal_error(thisAgent, msg);
}
#endif
/* --- remove it from the list of pref's for its match goal --- */
if (pref->on_goal_list)
pref, all_of_goal_next, all_of_goal_prev);
/* --- remove it from the list of pref's from that instantiation --- */
inst_next, inst_prev);
/* --- dereference component symbols --- */
symbol_remove_ref (thisAgent, pref->id);
symbol_remove_ref (thisAgent, pref->attr);
symbol_remove_ref (thisAgent, pref->value);
symbol_remove_ref (thisAgent, pref->referent);
if ( pref->wma_o_set )
{
wma_remove_pref_o_set( thisAgent, pref );
}
/* --- free the memory --- */
free_with_pool (&thisAgent->preference_pool, pref);
}
preference* make_preference ( agent thisAgent,
byte  type,
Symbol id,
Symbol attr,
Symbol value,
Symbol referent 
)
Bool possibly_deallocate_preference_and_clones ( agent thisAgent,
preference pref 
)

Definition at line 151 of file prefmem.cpp.

References deallocate_preference(), FALSE, production_struct::next, preference_struct::next_clone, NIL, preference_struct::prev_clone, preference_struct::reference_count, and TRUE.

Referenced by preference_remove_ref(), and remove_preference_from_clones().

{
preference *clone, *next;
if (pref->reference_count) return FALSE;
for (clone=pref->next_clone; clone!=NIL; clone=clone->next_clone)
if (clone->reference_count) return FALSE;
for (clone=pref->prev_clone; clone!=NIL; clone=clone->prev_clone)
if (clone->reference_count) return FALSE;
/* --- deallocate all the clones --- */
clone = pref->next_clone;
while (clone) {
next = clone->next_clone;
deallocate_preference (thisAgent, clone);
clone = next;
}
clone = pref->prev_clone;
while (clone) {
next = clone->prev_clone;
deallocate_preference (thisAgent, clone);
clone = next;
}
/* --- deallocate pref --- */
deallocate_preference (thisAgent, pref);
return TRUE;
}
void preference_add_ref ( preference p)
inline
void preference_remove_ref ( agent thisAgent,
preference p 
)
inline
void process_o_rejects_and_deallocate_them ( agent thisAgent,
preference o_rejects,
pref_buffer_list bufdeallo 
)

Definition at line 407 of file prefmem.cpp.

References preference_struct::all_of_slot_next, slot_struct::all_preferences, preference_struct::attr, find_slot(), preference_struct::id, preference_struct::next, NIL, preference_add_ref(), preference_remove_ref(), print(), print_preference(), remove_preference_from_tm(), and preference_struct::value.

Referenced by assert_new_preferences().

{
preference *pref, *next_pref, *p, *next_p;
slot *s;
for (pref=o_rejects; pref!=NIL; pref=pref->next) {
preference_add_ref (pref); /* prevents it from being deallocated if it's
a clone of some other pref we're about to
remove */
#ifdef DEBUG_PREFS
print (thisAgent, "\nO-reject posted at 0x%8x: ",reinterpret_cast<uintptr_t>(pref));
print_preference (thisAgent, pref);
#endif
}
pref = o_rejects;
while (pref) {
next_pref = pref->next;
s = find_slot (pref->id, pref->attr);
if (s) {
/* --- remove all pref's in the slot that have the same value --- */
while (p) {
next_p = p->all_of_slot_next;
if (p->value==pref->value) {
// Buffer deallocation by adding a reference here and putting it
// on a list. These are deallocated after the inner elaboration
// loop completes.
bufdeallo.push_back(p);
remove_preference_from_tm (thisAgent, p);
}
p = next_p;
}
}
preference_remove_ref (thisAgent, pref);
pref = next_pref;
}
}
void remove_preference_from_tm ( agent thisAgent,
preference pref 
)

Definition at line 359 of file prefmem.cpp.

References ACCEPTABLE_PREFERENCE_TYPE, slot_struct::all_preferences, FALSE, preference_struct::id, IDENTIFIER_SYMBOL_TYPE, preference_struct::in_tm, slot_struct::isa_context_slot, mark_context_slot_as_acceptable_preference_changed(), mark_slot_as_changed(), production_struct::next, NIL, post_link_removal(), preference_is_binary(), preference_remove_ref(), slot_struct::preferences, production_struct::prev, print(), print_preference(), preference_struct::referent, remove_from_dll, REQUIRE_PREFERENCE_TYPE, preference_struct::slot, preference_struct::type, and preference_struct::value.

Referenced by epmem_clear_result(), garbage_collect_id(), process_o_rejects_and_deallocate_them(), remove_existing_context_and_descendents(), retract_instantiation(), smem_clear_result(), and wma_forgetting_forget_wme().

{
slot *s;
s = pref->slot;
#ifdef DEBUG_PREFS
print (thisAgent, "\nRemove preference at 0x%8x: ",reinterpret_cast<uintptr_t>(pref));
print_preference (thisAgent, pref);
#endif
/* --- remove preference from the list for the slot --- */
all_of_slot_next, all_of_slot_prev);
remove_from_dll (s->preferences[pref->type], pref, next, prev);
/* --- other miscellaneous stuff --- */
pref->in_tm = FALSE;
pref->slot = NIL; /* BUG shouldn't we use pref->slot in place of pref->in_tm? */
mark_slot_as_changed (thisAgent, s);
/* --- if acceptable/require pref for context slot, we may need to remove
a wme later --- */
if ((s->isa_context_slot) &&
/* --- update identifier levels --- */
if (pref->value->common.symbol_type==IDENTIFIER_SYMBOL_TYPE)
post_link_removal (thisAgent, pref->id, pref->value);
if (pref->referent->common.symbol_type==IDENTIFIER_SYMBOL_TYPE)
post_link_removal (thisAgent, pref->id, pref->referent);
/* --- deallocate it and clones if possible --- */
preference_remove_ref (thisAgent, pref);
}