X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=blobdiff_plain;f=cyclegraph.h;h=d5c6a92af78715de0ff4f2c323a578b7a43f6ff1;hp=749abf8ca847d9969016356101b153c4d0688a84;hb=7524803854c2de38c0311fe5037e3c17105ccfaa;hpb=62dbff8dbca80ded5959e88ec9c177bef9108546 diff --git a/cyclegraph.h b/cyclegraph.h index 749abf8..d5c6a92 100644 --- a/cyclegraph.h +++ b/cyclegraph.h @@ -9,9 +9,11 @@ #ifndef __CYCLEGRAPH_H__ #define __CYCLEGRAPH_H__ -#include "hashtable.h" -#include +#include "stl_wrappers.h" #include +#include + +#include "hashtable.h" #include "config.h" #include "mymemory.h" @@ -19,7 +21,7 @@ class Promise; class CycleNode; class ModelAction; -typedef std::vector< const Promise *, ModelAlloc > promise_list_t; +typedef model_vector< const Promise * > promise_list_t; /** @brief A graph of Model Actions for tracking cycles. */ class CycleGraph { @@ -28,14 +30,16 @@ class CycleGraph { ~CycleGraph(); template - bool addEdge(const T from, const U to); + bool addEdge(const T *from, const U *to); + + template + void addRMWEdge(const T *from, const ModelAction *rmw); bool checkForCycles() const; - void addRMWEdge(const ModelAction *from, const ModelAction *rmw); bool checkPromise(const ModelAction *from, Promise *p) const; - template - bool checkReachable(const ModelAction *from, const T *to) const; + template + bool checkReachable(const T *from, const U *to) const; void startChanges(); void commitChanges(); @@ -43,32 +47,37 @@ class CycleGraph { #if SUPPORT_MOD_ORDER_DUMP void dumpNodes(FILE *file) const; void dumpGraphToFile(const char *filename) const; + + void dot_print_node(FILE *file, const ModelAction *act); + template + void dot_print_edge(FILE *file, const T *from, const U *to, const char *prop); #endif - bool resolvePromise(ModelAction *reader, ModelAction *writer, - promise_list_t *mustResolve); + bool resolvePromise(const Promise *promise, ModelAction *writer); SNAPSHOTALLOC private: bool addNodeEdge(CycleNode *fromnode, CycleNode *tonode); void putNode(const ModelAction *act, CycleNode *node); + void putNode(const Promise *promise, CycleNode *node); + void erasePromiseNode(const Promise *promise); CycleNode * getNode(const ModelAction *act); CycleNode * getNode(const Promise *promise); CycleNode * getNode_noCreate(const ModelAction *act) const; CycleNode * getNode_noCreate(const Promise *promise) const; - bool mergeNodes(CycleNode *node1, CycleNode *node2, - promise_list_t *mustMerge); + bool mergeNodes(CycleNode *node1, CycleNode *node2); HashTable *discovered; + model_vector< const CycleNode * > * queue; + /** @brief A table for mapping ModelActions to CycleNodes */ HashTable actionToNode; - /** @brief A table for mapping reader ModelActions to Promise - * CycleNodes */ - HashTable readerToPromiseNode; + /** @brief A table for mapping Promises to CycleNodes */ + HashTable promiseToNode; #if SUPPORT_MOD_ORDER_DUMP - std::vector nodeList; + std::vector< CycleNode *, SnapshotAlloc > nodeList; #endif bool checkReachable(const CycleNode *from, const CycleNode *to) const; @@ -102,11 +111,6 @@ class CycleNode { void clearRMW() { hasRMW = NULL; } const ModelAction * getAction() const { return action; } const Promise * getPromise() const { return promise; } - - void popEdge() { - edges.pop_back(); - } - bool is_promise() const { return !action; } void resolvePromise(const ModelAction *writer); @@ -130,47 +134,4 @@ class CycleNode { CycleNode *hasRMW; }; -/* - * @brief Adds an edge between objects - * - * This function will add an edge between any two objects which can be - * associated with a CycleNode. That is, if they have a CycleGraph::getNode - * implementation. - * - * The object to is ordered after the object from. - * - * @param to The edge points to this object, of type T - * @param from The edge comes from this object, of type U - * @return True, if new edge(s) are added; otherwise false - */ -template -bool CycleGraph::addEdge(const T from, const U to) -{ - ASSERT(from); - ASSERT(to); - - CycleNode *fromnode = getNode(from); - CycleNode *tonode = getNode(to); - - return addNodeEdge(fromnode, tonode); -} - -/** - * Checks whether one ModelAction can reach another ModelAction/Promise - * @param from The ModelAction from which to begin exploration - * @param to The ModelAction or Promise to reach - * @return True, @a from can reach @a to; otherwise, false - */ -template -bool CycleGraph::checkReachable(const ModelAction *from, const T *to) const -{ - CycleNode *fromnode = getNode_noCreate(from); - CycleNode *tonode = getNode_noCreate(to); - - if (!fromnode || !tonode) - return false; - - return checkReachable(fromnode, tonode); -} - #endif /* __CYCLEGRAPH_H__ */