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

Go to the source code of this file.

Data Structures

struct  wme_struct

Typedefs

typedef struct agent_struct agent
typedef char Bool
typedef uint64_t epmem_hash_id
typedef int64_t epmem_node_id
typedef uint64_t epmem_time_id
typedef union symbol_union Symbol
typedef uint64_t tc_number
typedef struct
wma_decay_element_struct 
wma_decay_element
typedef struct wme_struct wme

Functions

void add_wme_to_wm (agent *thisAgent, wme *w)
void deallocate_wme (agent *thisAgent, wme *w)
void do_buffered_wm_changes (agent *thisAgent)
Symbolfind_name_of_object (agent *thisAgent, Symbol *id)
wmemake_wme (agent *thisAgent, Symbol *id, Symbol *attr, Symbol *value, Bool acceptable)
void remove_wme_from_wm (agent *thisAgent, wme *w)
void remove_wme_list_from_wm (agent *thisAgent, wme *w, bool updateWmeMap=false)
void reset_wme_timetags (agent *thisAgent)
void wme_add_ref (wme *w)
void wme_remove_ref (agent *thisAgent, wme *w)

Typedef Documentation

typedef struct agent_struct agent

Definition at line 47 of file wmem.h.

typedef char Bool

Definition at line 44 of file wmem.h.

typedef uint64_t epmem_hash_id

Definition at line 53 of file wmem.h.

typedef int64_t epmem_node_id

Definition at line 52 of file wmem.h.

typedef uint64_t epmem_time_id

Definition at line 54 of file wmem.h.

typedef union symbol_union Symbol

Definition at line 48 of file wmem.h.

typedef uint64_t tc_number

Definition at line 45 of file wmem.h.

Definition at line 50 of file wmem.h.

typedef struct wme_struct wme

Definition at line 46 of file wmem.h.

Function Documentation

void add_wme_to_wm ( agent thisAgent,
wme w 
)
void deallocate_wme ( agent thisAgent,
wme w 
)

Definition at line 299 of file wmem.cpp.

References wme_struct::attr, wme_struct::id, agent_struct::num_existing_wmes, print_with_symbols(), print_wme(), symbol_remove_ref(), wme_struct::value, wma_enabled(), wma_remove_decay_element(), and agent_struct::wme_pool.

Referenced by create_instantiation(), and wme_remove_ref().

{
#ifdef DEBUG_WMES
print_with_symbols (thisAgent, "\nDeallocate wme: ");
print_wme (thisAgent, w);
#endif
if ( wma_enabled( thisAgent ) )
{
wma_remove_decay_element( thisAgent, w );
}
symbol_remove_ref (thisAgent, w->id);
symbol_remove_ref (thisAgent, w->attr);
symbol_remove_ref (thisAgent, w->value);
free_with_pool (&thisAgent->wme_pool, w);
thisAgent->num_existing_wmes--;
}
void do_buffered_wm_changes ( agent thisAgent)

Definition at line 200 of file wmem.cpp.

References add_wme_to_rete(), agent_struct::current_phase, filtered_print_wme_add(), filtered_print_wme_remove(), cons_struct::first, free_cons(), inform_output_module_of_wm_changes(), NIL, print(), print_wme(), remove_wme_from_rete(), cons_struct::rest, soar_invoke_callbacks(), agent_struct::sysparams, TIMERS_ENABLED, TRACE_WM_CHANGES_SYSPARAM, WM_CHANGES_CALLBACK, wme_add_ref(), agent_struct::wme_addition_count, agent_struct::wme_removal_count, wme_remove_ref(), agent_struct::wmes_to_add, agent_struct::wmes_to_remove, xml_att_val(), xml_begin_tag(), and xml_end_tag().

Referenced by do_buffered_wm_and_ownership_changes().

{
cons *c, *next_c, *cr;
wme *w;
/*
void filtered_print_wme_add(wme *w), filtered_print_wme_remove(wme *w);
*/
#ifndef NO_TIMING_STUFF
#ifdef DETAILED_TIMING_STATS
soar_process_timer local_timer;
local_timer.set_enabled( &( thisAgent->sysparams[ TIMERS_ENABLED ] ) );
#endif
#endif
/* --- if no wme changes are buffered, do nothing --- */
if (!thisAgent->wmes_to_add && !thisAgent->wmes_to_remove) return;
/* --- call output module in case any changes are output link changes --- */
thisAgent->wmes_to_remove);
/* --- invoke callback routine. wmes_to_add and wmes_to_remove can --- */
/* --- be fetched from the agent structure. --- */
/* --- stuff wme changes through the rete net --- */
#ifndef NO_TIMING_STUFF
#ifdef DETAILED_TIMING_STATS
local_timer.start();
#endif
#endif
for (c=thisAgent->wmes_to_add; c!=NIL; c=c->rest)
{
add_wme_to_rete (thisAgent, static_cast<wme_struct *>(c->first));
}
for (c=thisAgent->wmes_to_remove; c!=NIL; c=c->rest)
{
remove_wme_from_rete (thisAgent, static_cast<wme_struct *>(c->first));
}
#ifndef NO_TIMING_STUFF
#ifdef DETAILED_TIMING_STATS
local_timer.stop();
thisAgent->timers_match_cpu_time[thisAgent->current_phase].update(local_timer);
#endif
#endif
/* --- warn if watching wmes and same wme was added and removed -- */
for (c=thisAgent->wmes_to_add; c!=NIL; c=next_c) {
next_c = c->rest;
w = static_cast<wme_struct *>(c->first);
for (cr=thisAgent->wmes_to_remove; cr!=NIL; cr=next_c) {
next_c = cr->rest;
if (w == cr->first) {
const char * const kWarningMessage = "WARNING: WME added and removed in same phase : ";
print (thisAgent, const_cast< char* >( kWarningMessage) );
xml_begin_tag( thisAgent, kTagWarning );
xml_att_val( thisAgent, kTypeString, kWarningMessage );
print_wme(thisAgent, w);
xml_end_tag( thisAgent, kTagWarning );
}
}
}
}
/* --- do tracing and cleanup stuff --- */
for (c=thisAgent->wmes_to_add; c!=NIL; c=next_c) {
next_c = c->rest;
w = static_cast<wme_struct *>(c->first);
/* print ("=>WM: ");
* print_wme (w);
*/
filtered_print_wme_add(thisAgent, w); /* kjh(CUSP-B2) begin */
}
free_cons (thisAgent, c);
thisAgent->wme_addition_count++;
}
for (c=thisAgent->wmes_to_remove; c!=NIL; c=next_c) {
next_c = c->rest;
w = static_cast<wme_struct *>(c->first);
/* print ("<=WM: ");
* print_wme (thisAgent, w);
*/
filtered_print_wme_remove (thisAgent, w); /* kjh(CUSP-B2) begin */
}
wme_remove_ref (thisAgent, w);
free_cons (thisAgent, c);
thisAgent->wme_removal_count++;
}
thisAgent->wmes_to_add = NIL;
thisAgent->wmes_to_remove = NIL;
}
Symbol* find_name_of_object ( agent thisAgent,
Symbol id 
)

Definition at line 317 of file wmem.cpp.

References find_slot(), IDENTIFIER_SYMBOL_TYPE, agent_struct::name_symbol, NIL, wme_struct::value, and slot_struct::wmes.

Referenced by object_to_trace_string(), and print_stack_trace_xml().

{
slot *s;
if (object->common.symbol_type != IDENTIFIER_SYMBOL_TYPE) return NIL;
s = find_slot (object, thisAgent->name_symbol);
if (! s) return NIL;
if (! s->wmes) return NIL;
return s->wmes->value;
}
wme* make_wme ( agent thisAgent,
Symbol id,
Symbol attr,
Symbol value,
Bool  acceptable 
)

Definition at line 85 of file wmem.cpp.

References wme_struct::acceptable, wme_struct::attr, agent_struct::current_wme_timetag, wme_struct::epmem_id, EPMEM_NODEID_BAD, wme_struct::epmem_valid, wme_struct::gds, wme_struct::gds_next, wme_struct::gds_prev, wme_struct::grounds_tc, wme_struct::id, wme_struct::locals_tc, wme_struct::next, NIL, agent_struct::num_existing_wmes, wme_struct::output_link, wme_struct::potentials_tc, wme_struct::preference, wme_struct::prev, wme_struct::reference_count, wme_struct::rete_next, wme_struct::rete_prev, symbol_add_ref(), wme_struct::timetag, wme_struct::value, wme_struct::wma_decay_el, wme_struct::wma_tc_value, and agent_struct::wme_pool.

{
wme *w;
thisAgent->num_existing_wmes++;
allocate_with_pool (thisAgent, &thisAgent->wme_pool, &w);
w->id = id;
w->attr = attr;
w->value = value;
symbol_add_ref (value);
w->acceptable = acceptable;
w->timetag = thisAgent->current_wme_timetag++;
w->grounds_tc = 0;
w->potentials_tc = 0;
w->locals_tc = 0;
w->next = NIL;
w->prev = NIL;
w->rete_next = NIL;
w->rete_prev = NIL;
/* REW: begin 09.15.96 */
/* When we first create a WME, it had no gds value.
Do this for ALL wmes, regardless of the operand mode, so that no undefined pointers
are floating around. */
w->gds = NIL;
w->gds_prev = NIL;
w->gds_next = NIL;
/* REW: end 09.15.96 */
w->wma_tc_value = 0;
return w;
}
void remove_wme_from_wm ( agent thisAgent,
wme w 
)

Definition at line 148 of file wmem.cpp.

References wme_struct::attr, fast_remove_from_dll, wme_struct::gds, identifier_struct::gds, agent_struct::gds_pool, gds_struct::goal, wme_struct::id, symbol_union::id, IDENTIFIER_SYMBOL_TYPE, identifier_struct::isa_operator, NIL, agent_struct::operator_symbol, post_link_removal(), push(), wme_struct::value, gds_struct::wmes_in_gds, and agent_struct::wmes_to_remove.

Referenced by decide_non_context_slot(), do_acceptable_preference_wme_changes_for_slot(), remove_input_wme(), soar_module::remove_module_wme(), remove_wme_list_from_wm(), remove_wmes_for_context_slot(), and update_impasse_items().

{
push (thisAgent, w, thisAgent->wmes_to_remove);
if (w->value->common.symbol_type == IDENTIFIER_SYMBOL_TYPE)
{
post_link_removal (thisAgent, w->id, w->value);
if (w->attr==thisAgent->operator_symbol)
{
/* Do this afterward so that gSKI can know that this is an operator */
}
}
/* REW: begin 09.15.96 */
/* When we remove a WME, we always have to determine if it's on a GDS, and, if
so, after removing the WME, if there are no longer any WMEs on the GDS,
then we can free the GDS memory */
if (w->gds)
{
fast_remove_from_dll(w->gds->wmes_in_gds, w, wme, gds_next, gds_prev);
/* printf("\nRemoving WME on some GDS"); */
if (!w->gds->wmes_in_gds)
{
if (w->gds->goal) w->gds->goal->id.gds = NIL;
free_with_pool( &( thisAgent->gds_pool ), w->gds );
/* printf("REMOVING GDS FROM MEMORY. \n"); */
}
}
/* REW: end 09.15.96 */
}
void remove_wme_list_from_wm ( agent thisAgent,
wme w,
bool  updateWmeMap = false 
)

Definition at line 181 of file wmem.cpp.

References INPUT_WME_GARBAGE_COLLECTED_CALLBACK, wme_struct::next, remove_wme_from_wm(), and soar_invoke_callbacks().

Referenced by decide_non_context_slot(), garbage_collect_id(), remove_existing_attribute_impasse_for_slot(), and remove_existing_context_and_descendents().

{
wme *next_w;
while (w)
{
next_w = w->next;
if (updateWmeMap)
{
soar_invoke_callbacks( thisAgent, INPUT_WME_GARBAGE_COLLECTED_CALLBACK, static_cast< soar_call_data >( w ) );
//remove_wme_from_wmeMap (thisAgent, w);
}
remove_wme_from_wm (thisAgent, w);
w = next_w;
}
}
void reset_wme_timetags ( agent thisAgent)

Definition at line 74 of file wmem.cpp.

References agent_struct::current_wme_timetag, agent_struct::num_existing_wmes, print(), and xml_generate_warning().

Referenced by reinitialize_soar().

{
if (thisAgent->num_existing_wmes != 0) {
print (thisAgent, "Internal warning: wanted to reset wme timetag generator, but\n");
print (thisAgent, "there are still some wmes allocated. (Probably a memory leak.)\n");
print (thisAgent, "(Leaving timetag numbers alone.)\n");
xml_generate_warning(thisAgent, "Internal warning: wanted to reset wme timetag generator, but\nthere are still some wmes allocated. (Probably a memory leak.)\n(Leaving timetag numbers alone.)");
return;
}
thisAgent->current_wme_timetag = 1;
}
void wme_add_ref ( wme w)
inline
void wme_remove_ref ( agent thisAgent,
wme w 
)
inline

Definition at line 176 of file wmem.h.

References deallocate_wme(), and wme_struct::reference_count.

Referenced by deallocate_instantiation(), do_buffered_wm_changes(), do_output_cycle(), remove_output_function(), and wma_remove_pref_o_set().

{
/* There are occaisionally wme's with zero reference counts
created in the system. Make sure this function handles them
correctly. */
if ((w)->reference_count != 0) (w)->reference_count--;
if ((w)->reference_count == 0) deallocate_wme(thisAgent, w);
}