#include "libatomic.h"
#include "model.h"
-#include "threads_internal.h"
void atomic_store_explicit(struct atomic_object *obj, int value, memory_order order)
{
- thread_current()->switch_to_master(new ModelAction(ATOMIC_WRITE, order, obj, value));
+ model->switch_to_master(new ModelAction(ATOMIC_WRITE, order, obj, value));
}
int atomic_load_explicit(struct atomic_object *obj, memory_order order)
{
- thread_current()->switch_to_master(new ModelAction(ATOMIC_READ, order, obj, VALUE_NONE));
+ model->switch_to_master(new ModelAction(ATOMIC_READ, order, obj, VALUE_NONE));
return 0;
}
Thread *th = model->get_thread(thrd_to_id(t));
while (th->get_state() != THREAD_COMPLETED && !ret)
/* seq_cst is just a 'don't care' parameter */
- ret = thread_current()->switch_to_master(new ModelAction(THREAD_JOIN, memory_order_seq_cst, NULL, VALUE_NONE));
+ ret = model->switch_to_master(new ModelAction(THREAD_JOIN, memory_order_seq_cst, NULL, VALUE_NONE));
return ret;
}
int thrd_yield(void)
{
/* seq_cst is just a 'don't care' parameter */
- return thread_current()->switch_to_master(new ModelAction(THREAD_YIELD, memory_order_seq_cst, NULL, VALUE_NONE));
+ return model->switch_to_master(new ModelAction(THREAD_YIELD, memory_order_seq_cst, NULL, VALUE_NONE));
}
thrd_t thrd_current(void)
return 0;
}
+int ModelChecker::switch_to_master(ModelAction *act)
+{
+ Thread *old, *next;
+
+ DBG();
+ old = thread_current();
+ set_current_action(act);
+ old->set_state(THREAD_READY);
+ next = system_thread;
+ return old->swap(next);
+}
+
ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, int value)
{
Thread *t = thread_current();
Thread *get_thread(thread_id_t tid) { return thread_map[tid]; }
void assign_id(Thread *t);
+
+ int switch_to_master(ModelAction *act);
private:
int used_thread_id;
class ModelAction *current_action;
stack_free(stack);
}
-int Thread::switch_to_master(ModelAction *act)
-{
- Thread *next;
-
- DBG();
- model->set_current_action(act);
- state = THREAD_READY;
- next = model->system_thread;
- return swap(next);
-}
-
Thread::Thread(thrd_t *t, void (*func)(), void *a) {
int ret;
Thread(thrd_t *t);
int swap(Thread *t);
void dispose();
- int switch_to_master(ModelAction *act);
thread_state get_state() { return state; }
void set_state(thread_state s) { state = s; }