model: change 'struct model_checker' to 'class ModelChecker'
authorBrian Norris <banorris@uci.edu>
Wed, 14 Mar 2012 22:05:54 +0000 (15:05 -0700)
committerBrian Norris <banorris@uci.edu>
Wed, 14 Mar 2012 22:05:54 +0000 (15:05 -0700)
libthreads.c
model.c
model.h
schedule.c
schedule.h

index ca310675f3abe5dd747b3f8426cd7e9307b47bc1..2ffe958ed193909cc2960fabcf28c9ee4d3eae4c 100644 (file)
@@ -5,7 +5,7 @@
 #include "schedule.h"
 #include "common.h"
 
-/* global "model" struct */
+/* global "model" object */
 #include "model.h"
 
 #define STACK_SIZE (1024 * 1024)
@@ -47,7 +47,7 @@ static int create_context(struct thread *t)
 static int create_initial_thread(struct thread *t)
 {
        memset(t, 0, sizeof(*t));
-       model_checker_assign_id(t);
+       model->assign_id(t);
        return create_context(t);
 }
 
@@ -107,7 +107,7 @@ int thread_create(struct thread *t, void (*start_routine)(), void *arg)
        DBG();
 
        memset(t, 0, sizeof(*t));
-       model_checker_assign_id(t);
+       model->assign_id(t);
        DEBUG("create thread %d\n", t->id);
 
        t->start_routine = start_routine;
@@ -154,11 +154,11 @@ int main()
        struct thread user_thread;
        struct thread *main_thread;
 
-       model_checker_init();
+       model = new ModelChecker();
 
        main_thread = (struct thread *)malloc(sizeof(*main_thread));
        create_initial_thread(main_thread);
-       model_checker_add_system_thread(main_thread);
+       model->add_system_thread(main_thread);
 
        /* Start user program */
        thread_create(&user_thread, &user_main, NULL);
diff --git a/model.c b/model.c
index a8a6936bde61d73e33c0138e118d1300bc015c71..858b9198bccc2fea775d3870970c9f4a0e19ef7e 100644 (file)
--- a/model.c
+++ b/model.c
@@ -3,35 +3,31 @@
 #include <stdlib.h>
 #include <string.h>
 
-struct model_checker *model;
+ModelChecker *model;
 
-void model_checker_add_system_thread(struct thread *t)
+ModelChecker::ModelChecker()
 {
-       model->system_thread = t;
-}
-
-void model_checker_init(void)
-{
-       model = (struct model_checker *)malloc(sizeof(*model));
-       memset(model, 0, sizeof(*model));
-
        /* First thread created (system_thread) will have id 1 */
-       model->used_thread_id = 0;
+       this->used_thread_id = 0;
 
-       scheduler_init(model);
+       scheduler_init(this);
 }
 
-void model_checker_exit(void)
+ModelChecker::~ModelChecker()
 {
        struct scheduler *sched = model->scheduler;
 
        if (sched->exit)
                sched->exit();
        free(sched);
-       free(model);
 }
 
-void model_checker_assign_id(struct thread *t)
+void ModelChecker::assign_id(struct thread *t)
 {
-       t->id = ++model->used_thread_id;
+       t->id = ++this->used_thread_id;
+}
+
+void ModelChecker::add_system_thread(struct thread *t)
+{
+       model->system_thread = t;
 }
diff --git a/model.h b/model.h
index 625d2726fe775921f981e5d666426eb85cb32148..31e88fe53a264a8d6c821941383d4cd9695b9884 100644 (file)
--- a/model.h
+++ b/model.h
@@ -1,18 +1,20 @@
 #ifndef __MODEL_H__
 #define __MODEL_H__
 
-struct model_checker {
+class ModelChecker {
+public:
+       ModelChecker();
+       ~ModelChecker();
        struct scheduler *scheduler;
        struct thread *system_thread;
 
-       /* "Private" fields */
+       void add_system_thread(struct thread *t);
+       void assign_id(struct thread *t);
+
+private:
        int used_thread_id;
 };
 
-extern struct model_checker *model;
-
-void model_checker_init(void);
-void model_checker_add_system_thread(struct thread *t);
-void model_checker_assign_id(struct thread *t);
+extern ModelChecker *model;
 
 #endif /* __MODEL_H__ */
index f4f1c13df96232f545423b00fbc968c9c8bd1361..0cb1648c26230d2d4a79803a688b903870fbc4c5 100644 (file)
@@ -73,7 +73,7 @@ static struct thread *default_thread_current(void)
        return current;
 }
 
-void scheduler_init(struct model_checker *mod)
+void scheduler_init(ModelChecker *mod)
 {
        struct scheduler *sched;
 
index bae8c1f8e2ce136206d42325dfbba6954e81c7c5..28f5b8d0fa864794f54f6b5788aec859412b8b8f 100644 (file)
@@ -14,6 +14,6 @@ struct scheduler {
        void *priv;
 };
 
-void scheduler_init(struct model_checker *mod);
+void scheduler_init(ModelChecker *mod);
 
 #endif /* __SCHEDULE_H__ */