Soar Kernel
9.3.2 08-06-12
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
src
wmem.h
Go to the documentation of this file.
1
/*************************************************************************
2
* PLEASE SEE THE FILE "license.txt" (INCLUDED WITH THIS SOFTWARE PACKAGE)
3
* FOR LICENSE AND COPYRIGHT INFORMATION.
4
*************************************************************************/
5
6
/* =======================================================================
7
wmem.h
8
9
Working Memory Management and Utility Routines
10
11
Reset_wme_timetags() resets the wme timetag generator back to 1.
12
This should be called during an init-soar.
13
14
Make_wme() creates and returns a new wme. The caller should add the
15
wme onto the appropriate dll (e.g., my_slot->wmes) and should call
16
add_wme_to_wm() on it.
17
18
Add_wme_to_wm() and remove_wme_from_wm() make changes to WM. Again,
19
the caller is responsible for manipulating the appropriate dll. WM
20
changes don't actually get stuffed down the rete until the end of the
21
phase, when do_buffered_wm_and_ownership_changes() gets be called.
22
23
Remove_wme_list_from_wm() is a utility routine that scans through a
24
list of wmes, linked by their "next" fields, and calls remove_wme_from_wm()
25
on each one.
26
27
Wme_add_ref() and wme_remove_ref() are macros for incrementing and
28
decrementing the reference count on a wme. Deallocate_wme() deallocates
29
a wme; this should only be invoked via the wme_remove_ref() macro.
30
31
Find_name_of_object() is a utility function for finding the value of
32
the ^name attribute on a given object (symbol). It returns the name,
33
or NIL if the object has no name.
34
======================================================================= */
35
36
#ifndef WMEM_H
37
#define WMEM_H
38
39
#ifdef __cplusplus
40
//extern "C"
41
//{
42
#endif
43
44
typedef
char
Bool
;
45
typedef
uint64_t
tc_number
;
46
typedef
struct
wme_struct
wme
;
47
typedef
struct
agent_struct
agent
;
48
typedef
union
symbol_union
Symbol
;
49
50
typedef
struct
wma_decay_element_struct
wma_decay_element
;
51
52
typedef
int64_t
epmem_node_id
;
53
typedef
uint64_t
epmem_hash_id
;
54
typedef
uint64_t
epmem_time_id
;
55
56
extern
void
reset_wme_timetags
(
agent
* thisAgent);
57
extern
wme
*
make_wme
(
agent
* thisAgent,
Symbol
*
id
,
Symbol
*attr,
Symbol
*value,
Bool
acceptable);
58
extern
void
add_wme_to_wm
(
agent
* thisAgent,
wme
*w);
59
extern
void
remove_wme_from_wm
(
agent
* thisAgent,
wme
*w);
60
extern
void
remove_wme_list_from_wm
(
agent
* thisAgent,
wme
*w,
bool
updateWmeMap =
false
);
61
extern
void
do_buffered_wm_changes
(
agent
* thisAgent);
62
63
extern
void
deallocate_wme
(
agent
* thisAgent,
wme
*w);
64
extern
Symbol
*
find_name_of_object
(
agent
* thisAgent,
Symbol
*
id
);
65
66
/* ------------------------------------------------------------------------
67
Working Memory Elements (WMEs)
68
69
Fields in a WME:
70
71
id, attr, value: points to symbols for the wme fields
72
73
acceptable: TRUE iff this is an acceptable pref. wme
74
75
timetag: timetag of the wme
76
77
reference count: (see below)
78
79
rete_next, rete_prev: pointers in the doubly-linked list of all
80
wmes currently known to the rete (header is all_wmes_in_rete)
81
(this equals WM except while WM is being changed)
82
83
right_mems: header of a doubly-linked list of right memory entries
84
(in one or more alpha memories containing the wme). This is used
85
only by the Rete, as part of list-based remove.
86
87
tokens: header of a doubly-linked list of tokens in the Rete.
88
This is used only by the Rete, as part of list-based remove.
89
90
next, prev: pointers in a doubly-linked list of wmes.
91
Depending on the wme type, the header of this DLL is:
92
- slot.wmes (for ordinary wmes)
93
- slot.acceptable_preference_wmes (for acceptable pref. wmes)
94
- id.impasse_wmes (for architecture-created goal/impasse wmes)
95
- id.input_wmes (for Soar I/O wmes)
96
97
preference: points to the preference supporting the wme. For I/O
98
wmes and (most) architecture-created wmes, this is NIL.
99
100
output_link: this is used only for top-state output links.
101
It points to an output_link structure used by the I/O routines.
102
103
grounds_tc, potentials_tc, locals_tc: used by the chunker to indicate
104
whether this wme is in the grounds, potentials, and/or locals sets
105
106
chunker_bt_pref: used by the chunker; set to cond->bt.trace when
107
a wme is added to either the potentials or locals set
108
109
These are the additions to the WME structure that will be used
110
to track dependencies for goals. Each working memory element
111
now includes a pointer to a gds_struct (defined below) and
112
pointers to other WMEs on the same GDS.
113
114
gds: the goal dependency set the wme is in
115
gds_next, gds_prev: used for dll of all wmes in gds
116
117
If a particular working memory element is not dependent for any goal,
118
then the values for these pointers will all be NIL. If a WME is
119
dependent for more than one goal, then it will point to the GDS
120
of the highest goal.
121
122
123
124
125
Reference counts on wmes:
126
+1 if the wme is currently in WM
127
+1 for each instantiation condition that points to it (bt.wme)
128
We deallocate a wme when its reference count goes to 0.
129
------------------------------------------------------------------------ */
130
131
typedef
struct
wme_struct
{
132
/* WARNING: The next three fields (id,attr,value) MUST be consecutive--
133
the rete code relies on this! */
134
Symbol
*
id
;
135
Symbol
*
attr
;
136
Symbol
*
value
;
137
Bool
acceptable
;
138
uint64_t
timetag
;
139
uint64_t
reference_count
;
140
struct
wme_struct
*
rete_next
, *
rete_prev
;
/* used for dll of wmes in rete */
141
struct
right_mem_struct
*
right_mems
;
/* used for dll of rm's it's in */
142
struct
token_struct
*
tokens
;
/* dll of tokens in rete */
143
struct
wme_struct
*
next
, *
prev
;
/* (see above) */
144
struct
preference_struct
*
preference
;
/* pref. supporting it, or NIL */
145
struct
output_link_struct
*
output_link
;
/* for top-state output commands */
146
tc_number
grounds_tc
;
/* for chunker use only */
147
tc_number
potentials_tc
,
locals_tc
;
148
struct
preference_struct
*
chunker_bt_pref
;
149
150
/* REW: begin 09.15.96 */
151
struct
gds_struct
*
gds
;
152
struct
wme_struct
*
gds_next
, *
gds_prev
;
/* used for dll of wmes in gds */
153
/* REW: end 09.15.96 */
154
155
156
epmem_node_id
epmem_id
;
157
uint64_t
epmem_valid
;
158
159
wma_decay_element
*
wma_decay_el
;
160
tc_number
wma_tc_value
;
161
162
}
wme
;
163
164
#ifdef USE_MACROS
165
166
#define wme_add_ref(w) { (w)->reference_count++; }
167
#define wme_remove_ref(thisAgent, w) { \
168
if ((w)->reference_count != 0) (w)->reference_count--; \
169
if ((w)->reference_count == 0) deallocate_wme(thisAgent, w); }
170
171
#else
172
173
inline
void
wme_add_ref
(
wme
* w) {
174
(w)->
reference_count
++;
175
}
176
inline
void
wme_remove_ref
(
agent
* thisAgent,
wme
* w)
177
{
178
/* There are occaisionally wme's with zero reference counts
179
created in the system. Make sure this function handles them
180
correctly. */
181
if
((w)->
reference_count
!= 0) (w)->
reference_count
--;
182
if
((w)->reference_count == 0)
deallocate_wme
(thisAgent, w);
183
}
184
185
#endif
/* USE_MACROS */
186
187
188
#ifdef __cplusplus
189
//}
190
#endif
191
192
#endif
Generated on Mon Aug 6 2012 17:21:02 for Soar Kernel by
1.8.1.2