2 * @brief Model Checker Thread class.
12 #include "libthreads.h"
14 typedef int thread_id_t;
16 #define THREAD_ID_T_NONE -1
18 /** @brief Represents the state of a user Thread */
19 typedef enum thread_state {
20 /** Thread was just created and hasn't run yet */
22 /** Thread is running */
25 * Thread has yielded to the model-checker but is ready to run. Used
26 * during an action that caused a context switch to the model-checking
30 /** Thread has completed its execution */
36 /** @brief A Thread is created for each user-space thread */
39 Thread(thrd_t *t, void (*func)(void *), void *a);
43 static int swap(ucontext_t *ctxt, Thread *t);
44 static int swap(Thread *t, ucontext_t *ctxt);
46 thread_state get_state() { return state; }
47 void set_state(thread_state s) { state = s; }
49 thrd_t get_thrd_t() { return *user_thread; }
50 Thread * get_parent() { return parent; }
52 void set_creation(ModelAction *act) { creation = act; }
53 ModelAction * get_creation() { return creation; }
56 * Set a return value for the last action in this thread (e.g., for an
58 * @param value The value to return
60 void set_return_value(uint64_t value) { last_action_val = value; }
63 * Retrieve a return value for the last action in this thread. Used,
64 * for instance, for an atomic read to return the 'read' value. Should
65 * be called from a user context.
66 * @return The value 'returned' by the action
68 uint64_t get_return_value() { return last_action_val; }
70 friend void thread_startup();
76 ModelAction *creation;
78 void (*start_routine)(void *);
87 * The value returned by the last action in this thread
88 * @see Thread::set_return_value()
89 * @see Thread::get_return_value()
91 uint64_t last_action_val;
94 Thread * thread_current();
96 static inline thread_id_t thrd_to_id(thrd_t t)
101 static inline thread_id_t int_to_id(int i)
106 static inline int id_to_int(thread_id_t id)
111 #endif /* __THREADS_H__ */