#include "cyclegraph.h"
#include "action.h"
#include "common.h"
+#include "promise.h"
+#include "model.h"
/** Initializes a CycleGraph object. */
CycleGraph::CycleGraph() :
}
#if SUPPORT_MOD_ORDER_DUMP
-void CycleGraph::dumpGraphToFile(const char *filename) {
- char buffer[200];
- sprintf(buffer, "%s.dot",filename);
- FILE *file=fopen(buffer, "w");
- fprintf(file, "digraph %s {\n",filename);
+void CycleGraph::dumpNodes(FILE *file) {
for(unsigned int i=0;i<nodeList.size();i++) {
CycleNode *cn=nodeList[i];
std::vector<CycleNode *> * edges=cn->getEdges();
fprintf(file, "N%u -> N%u;\n", action->get_seq_number(), dstaction->get_seq_number());
}
}
+}
+
+void CycleGraph::dumpGraphToFile(const char *filename) {
+ char buffer[200];
+ sprintf(buffer, "%s.dot",filename);
+ FILE *file=fopen(buffer, "w");
+ fprintf(file, "digraph %s {\n",filename);
+ dumpNodes(file);
fprintf(file,"}\n");
fclose(file);
}
* @return True, @a from can reach @a to; otherwise, false
*/
bool CycleGraph::checkReachable(CycleNode *from, CycleNode *to) {
- std::vector<CycleNode *, MyAlloc<CycleNode *> > queue;
- HashTable<CycleNode *, CycleNode *, uintptr_t, 4, MYMALLOC, MYCALLOC, MYFREE> discovered;
+ std::vector<CycleNode *, ModelAlloc<CycleNode *> > queue;
+ HashTable<CycleNode *, CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> discovered(64);
queue.push_back(from);
discovered.put(from, from);
return false;
}
+bool CycleGraph::checkPromise(const ModelAction *fromact, Promise *promise) {
+ std::vector<CycleNode *, ModelAlloc<CycleNode *> > queue;
+ HashTable<CycleNode *, CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> discovered(64);
+ CycleNode *from = actionToNode.get(fromact);
+
+
+ queue.push_back(from);
+ discovered.put(from, from);
+ while(!queue.empty()) {
+ CycleNode * node=queue.back();
+ queue.pop_back();
+
+ if (promise->increment_threads(node->getAction()->get_tid())) {
+ return true;
+ }
+
+ for(unsigned int i=0;i<node->getEdges()->size();i++) {
+ CycleNode *next=(*node->getEdges())[i];
+ if (!discovered.contains(next)) {
+ discovered.put(next,next);
+ queue.push_back(next);
+ }
+ }
+ }
+ return false;
+}
+
void CycleGraph::startChanges() {
ASSERT(rollbackvector.size()==0);
ASSERT(rmwrollbackvector.size()==0);