fix mutex_trylock bug
[c11tester.git] / execution.h
index b78837fc7219bd77dcea34744ff6214fb5fecaa6..31e9810ef40149fdd2003cc6fd78744cf9675b14 100644 (file)
 #include <condition_variable>
 #include "classlist.h"
 
-/** @brief Shorthand for a list of release sequence heads */
-typedef ModelVector<const ModelAction *> rel_heads_list_t;
-typedef SnapList<ModelAction *> action_list_t;
-
 struct PendingFutureValue {
        PendingFutureValue(ModelAction *writer, ModelAction *reader) :
                writer(writer), reader(reader)
@@ -31,29 +27,14 @@ struct PendingFutureValue {
        ModelAction *reader;
 };
 
-/** @brief Records information regarding a single pending release sequence */
-struct release_seq {
-       /** @brief The acquire operation */
-       ModelAction *acquire;
-       /** @brief The read operation that may read from a release sequence;
-        *  may be the same as acquire, or else an earlier action in the same
-        *  thread (i.e., when 'acquire' is a fence-acquire) */
-       const ModelAction *read;
-       /** @brief The head of the RMW chain from which 'read' reads; may be
-        *  equal to 'release' */
-       const ModelAction *rf;
-       /** @brief The head of the potential longest release sequence chain */
-       const ModelAction *release;
-       /** @brief The write(s) that may break the release sequence */
-       SnapVector<const ModelAction *> writes;
-};
+#ifdef COLLECT_STAT
+void print_atomic_accesses();
+#endif
 
 /** @brief The central structure for model-checking */
 class ModelExecution {
 public:
-       ModelExecution(ModelChecker *m,
-                                                                Scheduler *scheduler,
-                                                                NodeStack *node_stack);
+       ModelExecution(ModelChecker *m, Scheduler *scheduler);
        ~ModelExecution();
 
        struct model_params * get_params() const { return params; }
@@ -61,9 +42,10 @@ public:
 
        Thread * take_step(ModelAction *curr);
 
-       void print_summary() const;
+       void print_summary();
+       void print_tail();
 #if SUPPORT_MOD_ORDER_DUMP
-       void dumpGraph(char *filename) const;
+       void dumpGraph(char *filename);
 #endif
 
        void add_thread(Thread *t);
@@ -82,91 +64,108 @@ public:
 
        ClockVector * get_cv(thread_id_t tid) const;
        ModelAction * get_parent_action(thread_id_t tid) const;
-       bool isfeasibleprefix() const;
 
-       action_list_t * get_actions_on_obj(void * obj, thread_id_t tid) const;
        ModelAction * get_last_action(thread_id_t tid) const;
 
        bool check_action_enabled(ModelAction *curr);
 
-       bool assert_bug(const char *msg);
+       void assert_bug(const char *msg);
+
        bool have_bug_reports() const;
+
        SnapVector<bug_message *> * get_bugs() const;
 
        bool has_asserted() const;
        void set_assert();
        bool is_complete_execution() const;
 
-       void print_infeasibility(const char *prefix) const;
-       bool is_infeasible() const;
        bool is_deadlocked() const;
 
        action_list_t * get_action_trace() { return &action_trace; }
        Fuzzer * getFuzzer();
        CycleGraph * const get_mo_graph() { return mo_graph; }
-       HashTable<pthread_cond_t *, cdsc::condition_variable *, uintptr_t, 4> * getCondMap() {return &cond_map;}
-       HashTable<pthread_mutex_t *, cdsc::mutex *, uintptr_t, 4> * getMutexMap() {return &mutex_map;}
+       HashTable<pthread_cond_t *, cdsc::snapcondition_variable *, uintptr_t, 4> * getCondMap() {return &cond_map;}
+       HashTable<pthread_mutex_t *, cdsc::snapmutex *, uintptr_t, 4> * getMutexMap() {return &mutex_map;}
+       ModelAction * check_current_action(ModelAction *curr);
 
+       bool isFinished() {return isfinished;}
+       void setFinished() {isfinished = true;}
+       void restore_last_seq_num();
+       void collectActions();
+       modelclock_t get_curr_seq_num();
+#ifdef TLS
+       pthread_key_t getPthreadKey() {return pthreadkey;}
+#endif
        SNAPSHOTALLOC
 private:
        int get_execution_number() const;
-
-       ModelChecker *model;
-
-       struct model_params * params;
-
-       /** The scheduler to use: tracks the running/ready Threads */
-       Scheduler * const scheduler;
-
-       bool mo_may_allow(const ModelAction *writer, const ModelAction *reader);
-       void set_bad_synchronization();
        bool should_wake_up(const ModelAction *curr, const Thread *thread) const;
        void wake_up_sleeping_actions(ModelAction *curr);
        modelclock_t get_next_seq_num();
-
        bool next_execution();
-       ModelAction * check_current_action(ModelAction *curr);
        bool initialize_curr_action(ModelAction **curr);
-       void process_read(ModelAction *curr, SnapVector<ModelAction *> * rf_set);
+       bool process_read(ModelAction *curr, SnapVector<ModelAction *> * rf_set);
        void process_write(ModelAction *curr);
-       bool process_fence(ModelAction *curr);
+       void process_fence(ModelAction *curr);
        bool process_mutex(ModelAction *curr);
-
-       bool process_thread_action(ModelAction *curr);
-       bool read_from(ModelAction *act, const ModelAction *rf);
+       void process_thread_action(ModelAction *curr);
+       void read_from(ModelAction *act, ModelAction *rf);
        bool synchronize(const ModelAction *first, ModelAction *second);
-
-       void add_action_to_lists(ModelAction *act);
+       void add_action_to_lists(ModelAction *act, bool canprune);
+       void add_normal_write_to_lists(ModelAction *act);
+       void add_write_to_lists(ModelAction *act);
        ModelAction * get_last_fence_release(thread_id_t tid) const;
        ModelAction * get_last_seq_cst_write(ModelAction *curr) const;
        ModelAction * get_last_seq_cst_fence(thread_id_t tid, const ModelAction *before_fence) const;
        ModelAction * get_last_unlock(ModelAction *curr) const;
        SnapVector<ModelAction *> * build_may_read_from(ModelAction *curr);
        ModelAction * process_rmw(ModelAction *curr);
-
-       bool r_modification_order(ModelAction *curr, const ModelAction *rf, SnapVector<const ModelAction *> *priorset);
+       bool r_modification_order(ModelAction *curr, const ModelAction *rf, SnapVector<ModelAction *> *priorset, bool *canprune);
        void w_modification_order(ModelAction *curr);
-       void get_release_seq_heads(ModelAction *acquire, ModelAction *read, rel_heads_list_t *release_heads);
-       bool release_seq_heads(const ModelAction *rf, rel_heads_list_t *release_heads) const;
-       ModelAction * get_uninitialized_action(const ModelAction *curr) const;
+       ClockVector * get_hb_from_write(ModelAction *rf) const;
+       ModelAction * convertNonAtomicStore(void*);
+       ClockVector * computeMinimalCV();
+       void removeAction(ModelAction *act);
+       void fixupLastAct(ModelAction *act);
+
+#ifdef TLS
+       pthread_key_t pthreadkey;
+#endif
+       ModelChecker *model;
+       struct model_params * params;
+
+       /** The scheduler to use: tracks the running/ready Threads */
+       Scheduler * const scheduler;
+
 
-       action_list_t action_trace;
        SnapVector<Thread *> thread_map;
        SnapVector<Thread *> pthread_map;
        uint32_t pthread_counter;
 
+       action_list_t action_trace;
+
+
        /** Per-object list of actions. Maps an object (i.e., memory location)
-        * to a trace of all actions performed on the object. */
-       HashTable<const void *, action_list_t *, uintptr_t, 4> obj_map;
+        * to a trace of all actions performed on the object.
+        * Used only for SC fences, unlocks, & wait.
+        */
+       HashTable<const void *, simple_action_list_t *, uintptr_t, 2> obj_map;
 
        /** Per-object list of actions. Maps an object (i.e., memory location)
         * to a trace of all actions performed on the object. */
-       HashTable<const void *, action_list_t *, uintptr_t, 4> condvar_waiters_map;
+       HashTable<const void *, simple_action_list_t *, uintptr_t, 2> condvar_waiters_map;
 
-       HashTable<void *, SnapVector<action_list_t> *, uintptr_t, 4> obj_thrd_map;
+       /** Per-object list of actions that each thread performed. */
+       HashTable<const void *, SnapVector<action_list_t> *, uintptr_t, 2> obj_thrd_map;
 
-       HashTable<pthread_mutex_t *, cdsc::mutex *, uintptr_t, 4> mutex_map;
-       HashTable<pthread_cond_t *, cdsc::condition_variable *, uintptr_t, 4> cond_map;
+       /** Per-object list of writes that each thread performed. */
+       HashTable<const void *, SnapVector<simple_action_list_t> *, uintptr_t, 2> obj_wr_thrd_map;
+
+       HashTable<const void *, ModelAction *, uintptr_t, 4> obj_last_sc_map;
+
+
+       HashTable<pthread_mutex_t *, cdsc::snapmutex *, uintptr_t, 4> mutex_map;
+       HashTable<pthread_cond_t *, cdsc::snapcondition_variable *, uintptr_t, 4> cond_map;
 
        /**
         * List of pending release sequences. Release sequences might be
@@ -177,7 +176,6 @@ private:
 
        SnapVector<ModelAction *> thrd_last_action;
        SnapVector<ModelAction *> thrd_last_fence_release;
-       NodeStack * const node_stack;
 
        /** A special model-checker Thread; used for associating with
         *  model-checker-related ModelAcitons */
@@ -206,6 +204,8 @@ private:
        Fuzzer * fuzzer;
 
        Thread * action_select_next_thread(const ModelAction *curr) const;
+
+       bool isfinished;
 };
 
 #endif /* __EXECUTION_H__ */