From: Brian Norris Date: Tue, 9 Oct 2012 19:05:32 +0000 (-0700) Subject: rename threads.h -> threads-model.h X-Git-Tag: pldi2013~68 X-Git-Url: http://demsky.eecs.uci.edu/git/?p=model-checker.git;a=commitdiff_plain;h=e60d8c23d30a0dfe66b8426f7f2ecf576e812028 rename threads.h -> threads-model.h There's a name conflict with the C11 We might as well just avoid the conflict entirely --- diff --git a/action.cc b/action.cc index 3aeb737..5e05081 100644 --- a/action.cc +++ b/action.cc @@ -7,7 +7,7 @@ #include "action.h" #include "clockvector.h" #include "common.h" -#include "threads.h" +#include "threads-model.h" #include "nodestack.h" #define ACTION_INITIAL_CLOCK 0 diff --git a/clockvector.cc b/clockvector.cc index 2b6a4cc..062ac41 100644 --- a/clockvector.cc +++ b/clockvector.cc @@ -6,7 +6,7 @@ #include "action.h" #include "clockvector.h" #include "common.h" -#include "threads.h" +#include "threads-model.h" /** * Constructs a new ClockVector, given a parent ClockVector and a first diff --git a/cmodelint.cc b/cmodelint.cc index 6b20c2c..7e52d10 100644 --- a/cmodelint.cc +++ b/cmodelint.cc @@ -1,6 +1,6 @@ #include "model.h" #include "cmodelint.h" -#include "threads.h" +#include "threads-model.h" /** Performs a read action.*/ uint64_t model_read_action(void * obj, memory_order ord) { diff --git a/datarace.cc b/datarace.cc index 7fe5350..270e523 100644 --- a/datarace.cc +++ b/datarace.cc @@ -1,6 +1,6 @@ #include "datarace.h" #include "model.h" -#include "threads.h" +#include "threads-model.h" #include #include #include "mymemory.h" diff --git a/impatomic.cc b/impatomic.cc index 0a35b4b..65b42fe 100644 --- a/impatomic.cc +++ b/impatomic.cc @@ -1,7 +1,7 @@ #include "impatomic.h" #include "common.h" #include "model.h" -#include "threads.h" +#include "threads-model.h" namespace std { diff --git a/librace.cc b/librace.cc index bdd6093..3c56d96 100644 --- a/librace.cc +++ b/librace.cc @@ -5,7 +5,7 @@ #include "common.h" #include "datarace.h" #include "model.h" -#include "threads.h" +#include "threads-model.h" void store_8(void *addr, uint8_t val) { diff --git a/libthreads.cc b/libthreads.cc index f973176..9e34141 100644 --- a/libthreads.cc +++ b/libthreads.cc @@ -1,6 +1,6 @@ #include "libthreads.h" #include "common.h" -#include "threads.h" +#include "threads-model.h" /* global "model" object */ #include "model.h" diff --git a/main.cc b/main.cc index 2a4119a..bff111f 100644 --- a/main.cc +++ b/main.cc @@ -6,7 +6,7 @@ #include "libthreads.h" #include "common.h" -#include "threads.h" +#include "threads-model.h" #include "datarace.h" diff --git a/model.cc b/model.cc index ee3ce99..5753c5c 100644 --- a/model.cc +++ b/model.cc @@ -12,7 +12,7 @@ #include "promise.h" #include "datarace.h" #include "mutex.h" -#include "threads.h" +#include "threads-model.h" #define INITIAL_THREAD_ID 0 diff --git a/mutex.cc b/mutex.cc index 6ef297a..ce74735 100644 --- a/mutex.cc +++ b/mutex.cc @@ -1,6 +1,6 @@ #include "mutex.h" #include "model.h" -#include "threads.h" +#include "threads-model.h" #include "clockvector.h" namespace std { diff --git a/nodestack.cc b/nodestack.cc index 3db80e8..167d694 100644 --- a/nodestack.cc +++ b/nodestack.cc @@ -4,7 +4,7 @@ #include "action.h" #include "common.h" #include "model.h" -#include "threads.h" +#include "threads-model.h" /** * @brief Node constructor diff --git a/promise.h b/promise.h index 2ce3e29..ce84ede 100644 --- a/promise.h +++ b/promise.h @@ -8,7 +8,7 @@ #define __PROMISE_H__ #include -#include "threads.h" +#include "threads-model.h" #include "model.h" diff --git a/schedule.cc b/schedule.cc index ec49a74..da6d469 100644 --- a/schedule.cc +++ b/schedule.cc @@ -1,7 +1,7 @@ #include #include -#include "threads.h" +#include "threads-model.h" #include "schedule.h" #include "common.h" #include "model.h" diff --git a/threads-model.h b/threads-model.h new file mode 100644 index 0000000..28d237d --- /dev/null +++ b/threads-model.h @@ -0,0 +1,164 @@ +/** @file threads-model.h + * @brief Model Checker Thread class. + */ + +#ifndef __THREADS_MODEL_H__ +#define __THREADS_MODEL_H__ + +#include +#include +#include + +#include "mymemory.h" +#include "libthreads.h" +#include "modeltypes.h" + +/** @brief Represents the state of a user Thread */ +typedef enum thread_state { + /** Thread was just created and hasn't run yet */ + THREAD_CREATED, + /** Thread is running */ + THREAD_RUNNING, + /** Thread is not currently running but is ready to run */ + THREAD_READY, + /** + * Thread is waiting on another action (e.g., thread completion, lock + * release, etc.) + */ + THREAD_BLOCKED, + /** Thread has completed its execution */ + THREAD_COMPLETED +} thread_state; + +class ModelAction; + +/** @brief A Thread is created for each user-space thread */ +class Thread { +public: + Thread(thread_id_t tid); + Thread(thrd_t *t, void (*func)(void *), void *a); + ~Thread(); + void complete(); + + static int swap(ucontext_t *ctxt, Thread *t); + static int swap(Thread *t, ucontext_t *ctxt); + + thread_state get_state() { return state; } + void set_state(thread_state s) { state = s; } + thread_id_t get_id(); + thrd_t get_thrd_t() { return *user_thread; } + Thread * get_parent() { return parent; } + + void set_creation(ModelAction *act) { creation = act; } + ModelAction * get_creation() { return creation; } + + /** + * Set a return value for the last action in this thread (e.g., for an + * atomic read). + * @param value The value to return + */ + void set_return_value(uint64_t value) { last_action_val = value; } + + /** + * Retrieve a return value for the last action in this thread. Used, + * for instance, for an atomic read to return the 'read' value. Should + * be called from a user context. + * @return The value 'returned' by the action + */ + uint64_t get_return_value() { return last_action_val; } + + /** @return True if this thread is finished executing */ + bool is_complete() { return state == THREAD_COMPLETED; } + + /** @return True if this thread is blocked */ + bool is_blocked() { return state == THREAD_BLOCKED; } + + /** @return True if no threads are waiting on this Thread */ + bool wait_list_empty() { return wait_list.empty(); } + + /** + * Add a ModelAction to the waiting list for this thread. + * @param t The ModelAction to add. Must be a JOIN. + */ + void push_wait_list(ModelAction *act) { wait_list.push_back(act); } + + unsigned int num_wait_list() { + return wait_list.size(); + } + + ModelAction * get_waiter(unsigned int i) { + return wait_list[i]; + } + + ModelAction * get_pending() { return pending; } + void set_pending(ModelAction *act) { pending = act; } + /** + * Remove one ModelAction from the waiting list + * @return The ModelAction that was removed from the waiting list + */ + ModelAction * pop_wait_list() { + ModelAction *ret = wait_list.front(); + wait_list.pop_back(); + return ret; + } + + bool is_model_thread() { return model_thread; } + + friend void thread_startup(); + + /** + * Intentionally NOT allocated with MODELALLOC or SNAPSHOTALLOC. + * Threads should be allocated on the user's normal (snapshotting) heap + * to allow their allocation/deallocation to follow the same pattern as + * the rest of the backtracked/replayed program. + */ +private: + int create_context(); + Thread *parent; + ModelAction *creation; + + ModelAction *pending; + void (*start_routine)(void *); + void *arg; + ucontext_t context; + void *stack; + thrd_t *user_thread; + thread_id_t id; + thread_state state; + + /** + * A list of ModelActions waiting on this Thread. Particularly, this + * list is used for thread joins, where another Thread waits for this + * Thread to complete + */ + std::vector< ModelAction *, SnapshotAlloc > wait_list; + + /** + * The value returned by the last action in this thread + * @see Thread::set_return_value() + * @see Thread::get_return_value() + */ + uint64_t last_action_val; + + /** @brief Is this Thread a special model-checker thread? */ + const bool model_thread; +}; + +Thread * thread_current(); + +static inline thread_id_t thrd_to_id(thrd_t t) +{ + return t; +} + +static inline thread_id_t int_to_id(int i) +{ + return i; +} + +static inline int id_to_int(thread_id_t id) +{ + return id; +} + +#endif /* __THREADS_MODEL_H__ */ diff --git a/threads.cc b/threads.cc index 7f51515..2ff058f 100644 --- a/threads.cc +++ b/threads.cc @@ -6,7 +6,7 @@ #include "libthreads.h" #include "common.h" -#include "threads.h" +#include "threads-model.h" /* global "model" object */ #include "model.h" diff --git a/threads.h b/threads.h deleted file mode 100644 index 91db236..0000000 --- a/threads.h +++ /dev/null @@ -1,164 +0,0 @@ -/** @file threads.h - * @brief Model Checker Thread class. - */ - -#ifndef __THREADS_H__ -#define __THREADS_H__ - -#include -#include -#include - -#include "mymemory.h" -#include "libthreads.h" -#include "modeltypes.h" - -/** @brief Represents the state of a user Thread */ -typedef enum thread_state { - /** Thread was just created and hasn't run yet */ - THREAD_CREATED, - /** Thread is running */ - THREAD_RUNNING, - /** Thread is not currently running but is ready to run */ - THREAD_READY, - /** - * Thread is waiting on another action (e.g., thread completion, lock - * release, etc.) - */ - THREAD_BLOCKED, - /** Thread has completed its execution */ - THREAD_COMPLETED -} thread_state; - -class ModelAction; - -/** @brief A Thread is created for each user-space thread */ -class Thread { -public: - Thread(thread_id_t tid); - Thread(thrd_t *t, void (*func)(void *), void *a); - ~Thread(); - void complete(); - - static int swap(ucontext_t *ctxt, Thread *t); - static int swap(Thread *t, ucontext_t *ctxt); - - thread_state get_state() { return state; } - void set_state(thread_state s) { state = s; } - thread_id_t get_id(); - thrd_t get_thrd_t() { return *user_thread; } - Thread * get_parent() { return parent; } - - void set_creation(ModelAction *act) { creation = act; } - ModelAction * get_creation() { return creation; } - - /** - * Set a return value for the last action in this thread (e.g., for an - * atomic read). - * @param value The value to return - */ - void set_return_value(uint64_t value) { last_action_val = value; } - - /** - * Retrieve a return value for the last action in this thread. Used, - * for instance, for an atomic read to return the 'read' value. Should - * be called from a user context. - * @return The value 'returned' by the action - */ - uint64_t get_return_value() { return last_action_val; } - - /** @return True if this thread is finished executing */ - bool is_complete() { return state == THREAD_COMPLETED; } - - /** @return True if this thread is blocked */ - bool is_blocked() { return state == THREAD_BLOCKED; } - - /** @return True if no threads are waiting on this Thread */ - bool wait_list_empty() { return wait_list.empty(); } - - /** - * Add a ModelAction to the waiting list for this thread. - * @param t The ModelAction to add. Must be a JOIN. - */ - void push_wait_list(ModelAction *act) { wait_list.push_back(act); } - - unsigned int num_wait_list() { - return wait_list.size(); - } - - ModelAction * get_waiter(unsigned int i) { - return wait_list[i]; - } - - ModelAction * get_pending() { return pending; } - void set_pending(ModelAction *act) { pending = act; } - /** - * Remove one ModelAction from the waiting list - * @return The ModelAction that was removed from the waiting list - */ - ModelAction * pop_wait_list() { - ModelAction *ret = wait_list.front(); - wait_list.pop_back(); - return ret; - } - - bool is_model_thread() { return model_thread; } - - friend void thread_startup(); - - /** - * Intentionally NOT allocated with MODELALLOC or SNAPSHOTALLOC. - * Threads should be allocated on the user's normal (snapshotting) heap - * to allow their allocation/deallocation to follow the same pattern as - * the rest of the backtracked/replayed program. - */ -private: - int create_context(); - Thread *parent; - ModelAction *creation; - - ModelAction *pending; - void (*start_routine)(void *); - void *arg; - ucontext_t context; - void *stack; - thrd_t *user_thread; - thread_id_t id; - thread_state state; - - /** - * A list of ModelActions waiting on this Thread. Particularly, this - * list is used for thread joins, where another Thread waits for this - * Thread to complete - */ - std::vector< ModelAction *, SnapshotAlloc > wait_list; - - /** - * The value returned by the last action in this thread - * @see Thread::set_return_value() - * @see Thread::get_return_value() - */ - uint64_t last_action_val; - - /** @brief Is this Thread a special model-checker thread? */ - const bool model_thread; -}; - -Thread * thread_current(); - -static inline thread_id_t thrd_to_id(thrd_t t) -{ - return t; -} - -static inline thread_id_t int_to_id(int i) -{ - return i; -} - -static inline int id_to_int(thread_id_t id) -{ - return id; -} - -#endif /* __THREADS_H__ */