change some data structures
authorweiyu <weiyuluo1232@gmail.com>
Wed, 31 Jul 2019 01:52:56 +0000 (18:52 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Wed, 31 Jul 2019 01:52:56 +0000 (18:52 -0700)
predicate.cc
predicate.h
pthread.cc

index 9f4246e953a94cde78b88d55dc331016a501222f..00eaaa0259642aa0b590b67e999638107dd2f0f8 100644 (file)
@@ -1,26 +1,26 @@
 #include "predicate.h"
 
-inline bool operator==(const predicate_expr& expr_A, const predicate_expr& expr_B)
+Predicate::Predicate(FuncInst * func_inst) :
+       func_inst(func_inst)
+{}
+
+unsigned int pred_expr_hash(struct pred_expr * expr) {
+        return (unsigned int)((uintptr_t)hash);
+}
+
+bool pred_expr_equal(struct pred_expr * p1, struct pred_expr * p2)
 {
-       if (expr_A.token != expr_B.token)
+       if (p1->token != p2->token)
                return false;
-
-       if (expr_A.token == EQUALITY && expr_A.location != expr_B.location)
+       if (p1->token == EQUALITY && p1->location != p2->location)
                return false;
-
-       if (expr_A.value != expr_B.value)
+       if (p1->value != p2->value)
                return false;
-
        return true;
 }
 
-void Predicate::add_predicate(predicate_expr predicate)
+void Predicate::add_predicate(token_t token, void * location, bool value)
 {
-       ModelList<predicate_expr>::iterator it;
-       for (it = predicates.begin(); it != predicates.end(); it++) {
-               if (predicate == *it)
-                       return;
-       }
-
-       predicates.push_back(predicate);
+       struct pred_expr = {token, location, value};
+       predicates.add(&predicate);
 }
index e2412d186705e079e60dabe68762b085af1245b8..42511c609cb5a8907b7bda7d740047c4f3b0387d 100644 (file)
@@ -1,5 +1,12 @@
+#ifndef __PREDICTAE_H__
+#define __PREDICATE_H__
+
 #include "funcinst.h"
 
+unsigned int pred_expr_hash (struct pred_expr *);
+bool pred_expr_equal(struct pred_expr *, struct pred_expr *);
+typedef HashSet<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredicateSet;
+
 typedef enum predicate_token {
        EQUALITY, NULLITY
 } token_t;
@@ -8,24 +15,28 @@ typedef enum predicate_token {
  * this load should read the same value as the last value 
  * read at memory location specified in predicate_expr.
  */
-struct predicate_expr {
+struct pred_expr {
        token_t token;
        void * location;
        bool value;
 };
 
+
 class Predicate {
 public:
-       Predicate();
+       Predicate(FuncInst * func_inst);
        ~Predicate();
 
        FuncInst * get_func_inst() { return func_inst; }
-       ModelList<predicate_expr> * get_predicates() { return &predicates; }
-       void add_predicate(predicate_expr predicate);
+       PredicateSet * get_predicates() { return &predicates; }
+       void add_predicate(token_t token, void * location, bool value);
 
        MEMALLOC
 private:
        FuncInst * func_inst;
        /* may have multiple precicates */
-       ModelList<predicate_expr> predicates;
+       PredicateSet predicates;
+       ModelVector<Predicate *> children;
 };
+
+#endif /* __PREDICATE_H__ */
index bad6beae1d60c761aac5f3c887700028f838c958..c96777488ee8cae08c20dcf88ab98d4c20e5caf3 100644 (file)
@@ -189,7 +189,7 @@ int pthread_cond_timedwait(pthread_cond_t *p_cond,
                pthread_mutex_init(p_mutex, NULL);
 
        cdsc::snapcondition_variable *v = execution->getCondMap()->get(p_cond);
-       cdsc::snapmutex *m = execution->getMutexMap()->get(p_mutex);
+//     cdsc::snapmutex *m = execution->getMutexMap()->get(p_mutex);
 
        model->switch_to_master(new ModelAction(NOOP, std::memory_order_seq_cst, v));
 //     v->wait(*m);
@@ -229,4 +229,5 @@ int pthread_cond_destroy(pthread_cond_t *p_cond) {
                delete v;
                execution->getCondMap()->remove(p_cond);
        }
+       return 0;
 }