From e9e6aaed0177ca95f216a59a284464262c835c3c Mon Sep 17 00:00:00 2001 From: weiyu Date: Tue, 30 Jul 2019 18:52:56 -0700 Subject: [PATCH] change some data structures --- predicate.cc | 30 +++++++++++++++--------------- predicate.h | 21 ++++++++++++++++----- pthread.cc | 3 ++- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/predicate.cc b/predicate.cc index 9f4246e9..00eaaa02 100644 --- a/predicate.cc +++ b/predicate.cc @@ -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::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); } diff --git a/predicate.h b/predicate.h index e2412d18..42511c60 100644 --- a/predicate.h +++ b/predicate.h @@ -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 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 * 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 predicates; + PredicateSet predicates; + ModelVector children; }; + +#endif /* __PREDICATE_H__ */ diff --git a/pthread.cc b/pthread.cc index bad6beae..c9677748 100644 --- a/pthread.cc +++ b/pthread.cc @@ -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; } -- 2.34.1