2 * @brief Model Checker Thread class.
10 #include "libthreads.h"
12 typedef int thread_id_t;
14 #define THREAD_ID_T_NONE -1
16 /** @brief Represents the state of a user Thread */
17 typedef enum thread_state {
18 /** Thread was just created and hasn't run yet */
20 /** Thread is running */
23 * Thread has yielded to the model-checker but is ready to run. Used
24 * during an action that caused a context switch to the model-checking
28 /** Thread has completed its execution */
34 /** @brief A Thread is created for each user-space thread */
37 Thread(thrd_t *t, void (*func)(void *), void *a);
41 static int swap(ucontext_t *ctxt, Thread *t);
42 static int swap(Thread *t, ucontext_t *ctxt);
44 thread_state get_state() { return state; }
45 void set_state(thread_state s) { state = s; }
47 thrd_t get_thrd_t() { return *user_thread; }
48 Thread * get_parent() { return parent; }
50 void set_creation(ModelAction *act) { creation = act; }
51 ModelAction * get_creation() { return creation; }
54 * Set a return value for the last action in this thread (e.g., for an
56 * @param value The value to return
58 void set_return_value(int value) { last_action_val = value; }
61 * Retrieve a return value for the last action in this thread. Used,
62 * for instance, for an atomic read to return the 'read' value. Should
63 * be called from a user context.
64 * @return The value 'returned' by the action
66 int get_return_value() { return last_action_val; }
68 friend void thread_startup();
74 ModelAction *creation;
76 void (*start_routine)(void *);
85 * The value returned by the last action in this thread
86 * @see Thread::set_return_value()
87 * @see Thread::get_return_value()
92 Thread * thread_current();
94 static inline thread_id_t thrd_to_id(thrd_t t)
99 static inline thread_id_t int_to_id(int i)
104 static inline int id_to_int(thread_id_t id)
109 #endif /* __THREADS_H__ */