add pthread_detach function
[c11tester.git] / cmodelint.cc
index 9ea1b681c32d20c7adb9f62aff78f9aab21d480d..b1a8eb43d3258add2ff3d8af5f821ab566669105 100644 (file)
@@ -14,29 +14,13 @@ memory_order orders[6] = {
        memory_order_release, memory_order_acq_rel, memory_order_seq_cst
 };
 
-#define ensureModel(action) \
-       if (!modelchecker_started) {                  \
-               if (!model) { \
-                       snapshot_system_init(10000, 1024, 1024, 40000); \
-                       model = new ModelChecker(); \
-               } \
-               model->get_execution()->check_current_action(action); \
-       }else { \
-               model->switch_to_master(action); \
-       }
-
-
-#define ensureModelValue(action, type)          \
-       if (!modelchecker_started) { \
-               if (!model) { \
-                       snapshot_system_init(10000, 1024, 1024, 40000); \
-                       model = new ModelChecker(); \
-               } \
-               model->get_execution()->check_current_action(action); \
-               return (type) thread_current()->get_return_value();   \
-       } else { \
-               return (type) model->switch_to_master(action);        \
+static void ensureModel() {
+       if (!model) {
+               snapshot_system_init(10000, 1024, 1024, 40000);
+               model = new ModelChecker();
+               model->startChecker();
        }
+}
 
 /** Performs a read action.*/
 uint64_t model_read_action(void * obj, memory_order ord) {
@@ -89,85 +73,83 @@ void model_fence_action(memory_order ord) {
 
 /* ---  helper functions --- */
 uint64_t model_rmwrcas_action_helper(void *obj, int atomic_index, uint64_t oldval, int size, const char *position) {
-       ensureModelValue(
-               new ModelAction(ATOMIC_RMWRCAS, position, orders[atomic_index], obj, oldval, size), uint64_t
-               );
+       ensureModel();
+       return model->switch_to_master(new ModelAction(ATOMIC_RMWRCAS, position, orders[atomic_index], obj, oldval, size));
 }
 
 uint64_t model_rmwr_action_helper(void *obj, int atomic_index, const char *position) {
-       ensureModelValue(new ModelAction(ATOMIC_RMWR, position, orders[atomic_index], obj), uint64_t);
+       ensureModel();
+       return model->switch_to_master(new ModelAction(ATOMIC_RMWR, position, orders[atomic_index], obj));
 }
 
 void model_rmw_action_helper(void *obj, uint64_t val, int atomic_index, const char * position) {
-       ensureModel(new ModelAction(ATOMIC_RMW, position, orders[atomic_index], obj, val));
+       ensureModel();
+       model->switch_to_master(new ModelAction(ATOMIC_RMW, position, orders[atomic_index], obj, val));
 }
 
 void model_rmwc_action_helper(void *obj, int atomic_index, const char *position) {
-       ensureModel(new ModelAction(ATOMIC_RMWC, position, orders[atomic_index], obj));
+       ensureModel();
+       model->switch_to_master(new ModelAction(ATOMIC_RMWC, position, orders[atomic_index], obj));
 }
 
 // cds atomic inits
 void cds_atomic_init8(void * obj, uint8_t val, const char * position) {
-       ensureModel(
-               new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val)
-               );
+       ensureModel();
+       model->switch_to_master(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(
-               new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val)
-               );
+       ensureModel();
+       model->switch_to_master(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(
-               new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val)
-               );
+       ensureModel();
+       model->switch_to_master(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(
-               new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, val)
-               );
+       ensureModel();
+       model->switch_to_master(new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, val));
 }
 
 
 // cds atomic loads
 uint8_t cds_atomic_load8(void * obj, int atomic_index, const char * position) {
-       ensureModelValue(
-               new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj), uint8_t);
+       ensureModel();
+       return (uint8_t) model->switch_to_master(
+               new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj));
 }
 uint16_t cds_atomic_load16(void * obj, int atomic_index, const char * position) {
-       ensureModelValue(
-               new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj), uint16_t);
+       ensureModel();
+       return (uint16_t) model->switch_to_master(
+               new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj));
 }
 uint32_t cds_atomic_load32(void * obj, int atomic_index, const char * position) {
-       ensureModelValue(
-               new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj), uint32_t
+       ensureModel();
+       return (uint32_t) model->switch_to_master(
+               new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj)
                );
 }
 uint64_t cds_atomic_load64(void * obj, int atomic_index, const char * position) {
-       ensureModelValue(
-               new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj), uint64_t);
+       ensureModel();
+       return model->switch_to_master(
+               new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj));
 }
 
 // cds atomic stores
 void cds_atomic_store8(void * obj, uint8_t val, int atomic_index, const char * position) {
-       ensureModel(
-               new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val)
-               );
+       ensureModel();
+       model->switch_to_master(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(
-               new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val)
-               );
+       ensureModel();
+       model->switch_to_master(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(
-               new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val)
-               );
+       ensureModel();
+       model->switch_to_master(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(
-               new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, val)
-               );
+       ensureModel();
+       model->switch_to_master(new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val));
 }
 
 #define _ATOMIC_RMW_(__op__, size, addr, val, atomic_index, position)            \