summaryrefslogtreecommitdiff
path: root/src/context
diff options
context:
space:
mode:
authorMorgan Deters <mdeters@gmail.com>2010-07-08 04:33:10 +0000
committerMorgan Deters <mdeters@gmail.com>2010-07-08 04:33:10 +0000
commit8a0dcb9cb4bbf83f03b31343eaa6437ae829f1c9 (patch)
treebd25ae92f252eaaea317f543e515ccdbbfc57f05 /src/context
parent586c8f2d51d790942fd82598a2bf532f2b5ebc9a (diff)
context work to support cdmaps with elements allocated in context memory
Diffstat (limited to 'src/context')
-rw-r--r--src/context/cdlist.h25
-rw-r--r--src/context/cdmap.h47
-rw-r--r--src/context/context.h17
3 files changed, 74 insertions, 15 deletions
diff --git a/src/context/cdlist.h b/src/context/cdlist.h
index e3bf4d56b..7e382697c 100644
--- a/src/context/cdlist.h
+++ b/src/context/cdlist.h
@@ -130,13 +130,24 @@ public:
/**
* Main constructor: d_list starts as NULL, size is 0
*/
- CDList(Context* context, bool callDestructor = true) :
- ContextObj(context),
- d_list(NULL),
- d_callDestructor(callDestructor),
- d_size(0),
- d_sizeAlloc(0) {
- }
+ CDList(Context* context, bool callDestructor = true) :
+ ContextObj(context),
+ d_list(NULL),
+ d_callDestructor(callDestructor),
+ d_size(0),
+ d_sizeAlloc(0) {
+ }
+
+ /**
+ * Main constructor: d_list starts as NULL, size is 0
+ */
+ CDList(bool allocatedInCMM, Context* context, bool callDestructor = true) :
+ ContextObj(allocatedInCMM, context),
+ d_list(NULL),
+ d_callDestructor(callDestructor),
+ d_size(0),
+ d_sizeAlloc(0) {
+ }
/**
* Destructor: delete the list
diff --git a/src/context/cdmap.h b/src/context/cdmap.h
index 5e5a07f2f..66f897818 100644
--- a/src/context/cdmap.h
+++ b/src/context/cdmap.h
@@ -114,6 +114,9 @@ class CDOmap : public ContextObj {
Data d_data;
CDMap<Key, Data, HashFcn>* d_map;
+ /** never put this cdmap element on the trash */
+ bool d_noTrash;
+
// Doubly-linked list for keeping track of elements in order of insertion
CDOmap* d_prev;
CDOmap* d_next;
@@ -147,9 +150,13 @@ class CDOmap : public ContextObj {
}
d_next->d_prev = d_prev;
d_prev->d_next = d_next;
- Debug("gc") << "CDMap<> trash push_back " << this << std::endl;
- //this->deleteSelf();
- d_map->d_trash.push_back(this);
+ if(d_noTrash) {
+ Debug("gc") << "CDMap<> no-trash " << this << std::endl;
+ } else {
+ Debug("gc") << "CDMap<> trash push_back " << this << std::endl;
+ //this->deleteSelf();
+ d_map->d_trash.push_back(this);
+ }
} else {
d_data = p->d_data;
}
@@ -172,10 +179,15 @@ public:
CDMap<Key, Data, HashFcn>* map,
const Key& key,
const Data& data,
- bool atLevelZero = false) :
- ContextObj(context),
+ bool atLevelZero = false,
+ bool allocatedInCMM = false) :
+ ContextObj(allocatedInCMM, context),
d_key(key),
- d_map(NULL) {
+ d_map(NULL),
+ d_noTrash(allocatedInCMM) {
+
+ // untested, probably unsafe.
+ Assert(!(atLevelZero && allocatedInCMM));
if(atLevelZero) {
// "Initializing" map insertion: this entry will never be
@@ -189,6 +201,14 @@ public:
// initialize d_map in the constructor init list above, because
// we want the restore of d_map to NULL to signal us to remove
// the element from the map.
+
+ if(allocatedInCMM) {
+ // Force a save/restore point, even though the object is
+ // allocated here. This is so that we can detect when the
+ // object falls out of the map (otherwise we wouldn't get it).
+ makeSaveRestorePoint();
+ }
+
set(data);
}
d_map = map;
@@ -378,6 +398,21 @@ public:
}
}
+ // Use this for pointer data d allocated in context memory at this
+ // level. THIS IS HIGHLY EXPERIMENTAL. It seems to work if ALL
+ // your data objects are allocated from context memory.
+ void insertDataFromContextMemory(const Key& k, const Data& d) {
+ emptyTrash();
+
+ AlwaysAssert(d_map.find(k) == d_map.end());
+
+ Element* obj = new(d_context->getCMM()) Element(d_context, this, k, d,
+ false /* atLevelZero */,
+ true /* allocatedInCMM */);
+
+ d_map[k] = obj;
+ }
+
/**
* Version of insert() for CDMap<> that inserts data value d at
* context level zero. This is a special escape hatch for inserting
diff --git a/src/context/context.h b/src/context/context.h
index 1aa5fe44d..20e84d7e5 100644
--- a/src/context/context.h
+++ b/src/context/context.h
@@ -380,6 +380,15 @@ protected:
inline void makeCurrent() throw(AssertionException);
/**
+ * Just calls update(), but given a different name for the derived
+ * class-facing interface. This is a "forced" makeCurrent(), useful
+ * for ContextObjs allocated in CMM that need a special "bottom"
+ * case when they disappear out of existence (kind of a destructor).
+ * See CDOmap (in cdmap.h) for an example.
+ */
+ inline void makeSaveRestorePoint() throw(AssertionException);
+
+ /**
* Should be called from sub-class destructor: calls restore until restored
* to initial version (version at context level 0). Also removes object from
* all Scope lists. Note that this doesn't actually free the memory
@@ -438,6 +447,8 @@ protected:
return d_pScope->isCurrent();
}
+public:
+
/**
* operator new using ContextMemoryManager (common case used by
* subclasses during save()). No delete is required for memory
@@ -459,8 +470,6 @@ protected:
*/
static void operator delete(void* pMem, ContextMemoryManager* pCMM) {}
-public:
-
/**
* Create a new ContextObj. The initial scope is set to the bottom
* scope of the Context. Note that in the common case, the copy
@@ -592,6 +601,10 @@ inline void ContextObj::makeCurrent() throw(AssertionException) {
}
}
+inline void ContextObj::makeSaveRestorePoint() throw(AssertionException) {
+ update();
+}
+
inline Scope::~Scope() throw(AssertionException) {
// Call restore() method on each ContextObj object in the list.
// Note that it is the responsibility of restore() to return the
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback