#include <stdio.h>
#include "model.h"
+#include "execution.h"
#include "action.h"
#include "cmodelint.h"
#include "snapshot-interface.h"
memory_order_release, memory_order_acq_rel, memory_order_seq_cst
};
-static void ensureModel() {
+static void ensureModel(ModelAction * action) {
if (!model) {
- snapshot_system_init(10000, 1024, 1024, 40000);
- model = new ModelChecker();
+ if (!model_init) {
+ snapshot_system_init(10000, 1024, 1024, 40000);
+ model_init = new ModelChecker();
+ }
+ model_init->get_execution()->check_current_action(action);
+ } else {
+ model->switch_to_master(action);
}
}
// cds atomic inits
void cds_atomic_init8(void * obj, uint8_t val, const char * position) {
- ensureModel();
- model->switch_to_master(
+ ensureModel(
new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val)
);
}
void cds_atomic_init16(void * obj, uint16_t val, const char * position) {
- ensureModel();
- model->switch_to_master(
+ ensureModel(
new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val)
);
}
void cds_atomic_init32(void * obj, uint32_t val, const char * position) {
- ensureModel();
- model->switch_to_master(
+ ensureModel(
new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val)
);
}
void cds_atomic_init64(void * obj, uint64_t val, const char * position) {
- ensureModel();
- model->switch_to_master(
+ ensureModel(
new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, val)
);
}
// cds atomic stores
void cds_atomic_store8(void * obj, uint8_t val, int atomic_index, const char * position) {
- ensureModel();
- model->switch_to_master(
+ ensureModel(
new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val)
);
}
void cds_atomic_store16(void * obj, uint16_t val, int atomic_index, const char * position) {
- ensureModel();
- model->switch_to_master(
+ ensureModel(
new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val)
);
}
void cds_atomic_store32(void * obj, uint32_t val, int atomic_index, const char * position) {
- ensureModel();
- model->switch_to_master(
+ ensureModel(
new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val)
);
}
void cds_atomic_store64(void * obj, uint64_t val, int atomic_index, const char * position) {
- ensureModel();
- model->switch_to_master(
+ ensureModel(
new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, val)
);
}
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;}
+ ModelAction * check_current_action(ModelAction *curr);
SNAPSHOTALLOC
private:
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<const ModelAction *> * rf_set);
void process_write(ModelAction *curr);
redirect_output();
//Initialize snapshotting library
- if (!model)
+ if (!model_init)
snapshot_system_init(10000, 1024, 1024, 40000);
struct model_params params;
snapshot_stack_init();
- if (!model)
+ if (!model_init)
model = new ModelChecker();
+ else
+ model = model_init;
+
model->setParams(params);
install_trace_analyses(model->get_execution());
#include "execution.h"
#include "bugmessage.h"
-ModelChecker *model;
+ModelChecker *model = NULL;
+ModelChecker *model_init = NULL;
+
+/** Wrapper to run the user's main function, with appropriate arguments */
+void user_main_wrapper(void *)
+{
+ user_main(model->params.argc, model->params.argv);
+}
/** @brief Constructor */
ModelChecker::ModelChecker() :
inspect_plugin(NULL)
{
memset(&stats,0,sizeof(struct execution_stats));
+ init_thread = new Thread(execution->get_next_id(), (thrd_t *) malloc(sizeof(thrd_t)), &user_main_wrapper, NULL, NULL); // L: user_main_wrapper passes the user program
+ execution->add_thread(init_thread);
+ scheduler->set_current_thread(init_thread);
}
/** @brief Destructor */
Thread *old = thread_current();
scheduler->set_current_thread(NULL);
ASSERT(!old->get_pending());
-/* W: No plugin
- if (inspect_plugin != NULL) {
- inspect_plugin->inspectModelAction(act);
- }*/
+
+ if (inspect_plugin != NULL) {
+ inspect_plugin->inspectModelAction(act);
+ }
+
old->set_pending(act);
if (Thread::swap(old, &system_context) < 0) {
perror("swap threads");
return old->get_return_value();
}
-/** Wrapper to run the user's main function, with appropriate arguments */
-void user_main_wrapper(void *)
-{
- user_main(model->params.argc, model->params.argv);
-}
-
bool ModelChecker::should_terminate_execution()
{
/* Infeasible -> don't take any more steps */
initstate(423121, random_state, sizeof(random_state));
for(int exec = 0;exec < params.maxexecutions;exec++) {
- thrd_t user_thread;
- Thread *t = new Thread(execution->get_next_id(), &user_thread, &user_main_wrapper, NULL, NULL); // L: user_main_wrapper passes the user program
- execution->add_thread(t);
- //Need to seed random number generator, otherwise its state gets reset
+ Thread * t = init_thread;
+
do {
/*
* Stash next pending action(s) for thread(s). There
Scheduler * const scheduler;
NodeStack * const node_stack;
ModelExecution *execution;
+ Thread * init_thread;
int execution_number;
};
extern ModelChecker *model;
+extern ModelChecker *model_init;
#endif /* __MODEL_H__ */
}
int pthread_mutex_init(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *) {
- if (!model) {
- snapshot_system_init(10000, 1024, 1024, 40000);
- model = new ModelChecker();
- }
-
cdsc::mutex *m = new cdsc::mutex();
+ ModelExecution *execution;
- ModelExecution *execution = model->get_execution();
+ if (!model) {
+ if (!model_init) {
+ snapshot_system_init(10000, 1024, 1024, 40000);
+ model_init = new ModelChecker();
+ }
+ execution = model_init->get_execution();
+ } else
+ execution = model->get_execution();
execution->getMutexMap()->put(p_mutex, m);
+
return 0;
}