Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
prefmem.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  Preference Management Routines
8 
9  Make_preference() creates a new preference structure of the given type
10  with the given id/attribute/value/referent. (Referent is only used
11  for binary preferences.) The preference is not yet added to preference
12  memory, however.
13 
14  Preference_add_ref() and preference_remove_ref() are macros for
15  incrementing and decrementing the reference count on a preference.
16 
17  Possibly_deallocate_preference_and_clones() checks whether a given
18  preference and all its clones have reference_count 0, and deallocates
19  them all if they do; it returns TRUE if they were actually deallocated,
20  FALSE otherwise. Deallocate_preference() deallocates a given
21  preference. These routines should normally be invoked only via the
22  preference_remove_ref() macro.
23 
24  Add_preference_to_tm() adds a given preference to preference memory (and
25  hence temporary memory). Remove_preference_from_tm() removes a given
26  preference from PM and TM.
27 
28  Process_o_rejects_and_deallocate_them() handles the processing of
29  o-supported reject preferences. This routine is called from the firer
30  and passed a list of all the o-rejects generated in the current
31  preference phase (the list is linked via the "next" fields on the
32  preference structures). This routine removes all preferences for
33  matching values from TM, and deallocates the o-reject preferences when
34  done.
35 --------------------------------------------------------------------- */
36 
37 #ifndef PREFMEM_H
38 #define PREFMEM_H
39 
40 #include "gdatastructs.h"
41 
42 #ifdef __cplusplus
43 //extern "C"
44 //{
45 #endif
46 
47 typedef char Bool;
48 typedef unsigned char byte;
49 typedef struct agent_struct agent;
51 typedef union symbol_union Symbol;
52 
53 #ifdef USE_MEM_POOL_ALLOCATORS
54 typedef std::list< preference*, soar_module::soar_memory_pool_allocator< preference* > > pref_buffer_list;
55 #else
56 typedef std::list< preference* > pref_buffer_list;
57 #endif
58 
59 extern preference *make_preference (agent* thisAgent, byte type, Symbol *id, Symbol *attr,
60  Symbol *value, Symbol *referent);
61 
63 
64 #ifdef USE_MACROS
65 
66 #define preference_add_ref(p) { (p)->reference_count++; }
67 #define preference_remove_ref(thisAgent, p) { \
68  (p)->reference_count--; \
69  if ((p)->reference_count == 0) \
70  possibly_deallocate_preference_and_clones(thisAgent, p); }
71 
72 #else
73 
75 {
76  (p)->reference_count++;
77 }
78 
79 inline void preference_remove_ref(agent* thisAgent, preference * p)
80 {
81  (p)->reference_count--;
82  if ((p)->reference_count == 0)
84 }
85 
86 #endif /* USE_MACROS */
87 
88 extern void deallocate_preference (agent* thisAgent, preference *pref);
89 
90 extern bool add_preference_to_tm (agent* thisAgent, preference *pref);
91 extern void remove_preference_from_tm (agent* thisAgent, preference *pref);
92 extern void process_o_rejects_and_deallocate_them (agent* thisAgent,
93  preference *o_rejects, pref_buffer_list& bufdeallo);
94 
95 #ifdef __cplusplus
96 //}
97 #endif
98 
99 #endif