rename other *.c to *.cc
authorBrian Norris <banorris@uci.edu>
Wed, 14 Mar 2012 22:59:49 +0000 (15:59 -0700)
committerBrian Norris <banorris@uci.edu>
Wed, 14 Mar 2012 22:59:49 +0000 (15:59 -0700)
userprog.c remains for now...

Makefile
libatomic.c [deleted file]
libatomic.cc [new file with mode: 0644]
libthreads.c [deleted file]
libthreads.cc [new file with mode: 0644]

index 84a7b0a10a1e9d9a39c0656978b47d9c322d6922..9e50d84ba53157c49d4a2f97f08fc3d0529bd76c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 CC=g++
 BIN=libthreads
-SOURCE=libthreads.c schedule.cc libatomic.c userprog.c model.cc
+SOURCE=libthreads.cc schedule.cc libatomic.cc userprog.c model.cc
 HEADERS=libthreads.h schedule.h common.h libatomic.h model.h
 FLAGS=-Wall
 
diff --git a/libatomic.c b/libatomic.c
deleted file mode 100644 (file)
index a00838e..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "libatomic.h"
-#include "libthreads.h"
-
-void atomic_store_explicit(struct atomic_object *obj, int value, memory_order order)
-{
-       thread_yield();
-}
-
-int atomic_load_explicit(struct atomic_object *obj, memory_order order)
-{
-       thread_yield();
-       return 0;
-}
diff --git a/libatomic.cc b/libatomic.cc
new file mode 100644 (file)
index 0000000..a00838e
--- /dev/null
@@ -0,0 +1,13 @@
+#include "libatomic.h"
+#include "libthreads.h"
+
+void atomic_store_explicit(struct atomic_object *obj, int value, memory_order order)
+{
+       thread_yield();
+}
+
+int atomic_load_explicit(struct atomic_object *obj, memory_order order)
+{
+       thread_yield();
+       return 0;
+}
diff --git a/libthreads.c b/libthreads.c
deleted file mode 100644 (file)
index 5a4c3a1..0000000
+++ /dev/null
@@ -1,173 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-
-#include "libthreads.h"
-#include "schedule.h"
-#include "common.h"
-
-/* global "model" object */
-#include "model.h"
-
-#define STACK_SIZE (1024 * 1024)
-
-static void *stack_allocate(size_t size)
-{
-       return malloc(size);
-}
-
-static void stack_free(void *stack)
-{
-       free(stack);
-}
-
-static int create_context(struct thread *t)
-{
-       int ret;
-
-       memset(&t->context, 0, sizeof(t->context));
-       ret = getcontext(&t->context);
-       if (ret)
-               return ret;
-
-       /* t->start_routine == NULL means this is our initial context */
-       if (!t->start_routine)
-               return 0;
-
-       /* Initialize new managed context */
-       t->stack = stack_allocate(STACK_SIZE);
-       t->context.uc_stack.ss_sp = t->stack;
-       t->context.uc_stack.ss_size = STACK_SIZE;
-       t->context.uc_stack.ss_flags = 0;
-       t->context.uc_link = &model->system_thread->context;
-       makecontext(&t->context, t->start_routine, 1, t->arg);
-
-       return 0;
-}
-
-static int create_initial_thread(struct thread *t)
-{
-       memset(t, 0, sizeof(*t));
-       model->assign_id(t);
-       return create_context(t);
-}
-
-static int thread_swap(struct thread *t1, struct thread *t2)
-{
-       return swapcontext(&t1->context, &t2->context);
-}
-
-static void thread_dispose(struct thread *t)
-{
-       DEBUG("completed thread %d\n", thread_current()->id);
-       t->state = THREAD_COMPLETED;
-       stack_free(t->stack);
-}
-
-/*
- * Return 1 if found next thread, 0 otherwise
- */
-static int thread_system_next(void)
-{
-       struct thread *curr, *next;
-
-       curr = thread_current();
-       if (curr) {
-               if (curr->state == THREAD_READY)
-                       model->scheduler->add_thread(curr);
-               else if (curr->state == THREAD_RUNNING)
-                       /* Stopped while running; i.e., completed */
-                       thread_dispose(curr);
-               else
-                       DEBUG("ERROR: current thread in unexpected state??\n");
-       }
-       next = model->scheduler->next_thread();
-       if (next)
-               next->state = THREAD_RUNNING;
-       DEBUG("(%d, %d)\n", curr ? curr->id : -1, next ? next->id : -1);
-       if (!next)
-               return 1;
-       return thread_swap(model->system_thread, next);
-}
-
-static void thread_wait_finish(void)
-{
-
-       DBG();
-
-       while (!thread_system_next());
-}
-
-/*
- * User program API functions
- */
-int thread_create(struct thread *t, void (*start_routine)(), void *arg)
-{
-       int ret = 0;
-
-       DBG();
-
-       memset(t, 0, sizeof(*t));
-       model->assign_id(t);
-       DEBUG("create thread %d\n", t->id);
-
-       t->start_routine = start_routine;
-       t->arg = arg;
-
-       /* Initialize state */
-       ret = create_context(t);
-       if (ret)
-               return ret;
-
-       t->state = THREAD_CREATED;
-
-       model->scheduler->add_thread(t);
-       return 0;
-}
-
-void thread_join(struct thread *t)
-{
-       while (t->state != THREAD_COMPLETED)
-               thread_yield();
-}
-
-int thread_yield(void)
-{
-       struct thread *old, *next;
-
-       DBG();
-       old = thread_current();
-       old->state = THREAD_READY;
-       next = model->system_thread;
-       return thread_swap(old, next);
-}
-
-struct thread *thread_current(void)
-{
-       return model->scheduler->get_current_thread();
-}
-
-/*
- * Main system function
- */
-int main()
-{
-       struct thread user_thread;
-       struct thread *main_thread;
-
-       model = new ModelChecker();
-
-       main_thread = (struct thread *)malloc(sizeof(*main_thread));
-       create_initial_thread(main_thread);
-       model->add_system_thread(main_thread);
-
-       /* Start user program */
-       thread_create(&user_thread, &user_main, NULL);
-
-       /* Wait for all threads to complete */
-       thread_wait_finish();
-
-       delete model;
-
-       DEBUG("Exiting\n");
-       return 0;
-}
diff --git a/libthreads.cc b/libthreads.cc
new file mode 100644 (file)
index 0000000..5a4c3a1
--- /dev/null
@@ -0,0 +1,173 @@
+#include <string.h>
+#include <stdlib.h>
+
+#include "libthreads.h"
+#include "schedule.h"
+#include "common.h"
+
+/* global "model" object */
+#include "model.h"
+
+#define STACK_SIZE (1024 * 1024)
+
+static void *stack_allocate(size_t size)
+{
+       return malloc(size);
+}
+
+static void stack_free(void *stack)
+{
+       free(stack);
+}
+
+static int create_context(struct thread *t)
+{
+       int ret;
+
+       memset(&t->context, 0, sizeof(t->context));
+       ret = getcontext(&t->context);
+       if (ret)
+               return ret;
+
+       /* t->start_routine == NULL means this is our initial context */
+       if (!t->start_routine)
+               return 0;
+
+       /* Initialize new managed context */
+       t->stack = stack_allocate(STACK_SIZE);
+       t->context.uc_stack.ss_sp = t->stack;
+       t->context.uc_stack.ss_size = STACK_SIZE;
+       t->context.uc_stack.ss_flags = 0;
+       t->context.uc_link = &model->system_thread->context;
+       makecontext(&t->context, t->start_routine, 1, t->arg);
+
+       return 0;
+}
+
+static int create_initial_thread(struct thread *t)
+{
+       memset(t, 0, sizeof(*t));
+       model->assign_id(t);
+       return create_context(t);
+}
+
+static int thread_swap(struct thread *t1, struct thread *t2)
+{
+       return swapcontext(&t1->context, &t2->context);
+}
+
+static void thread_dispose(struct thread *t)
+{
+       DEBUG("completed thread %d\n", thread_current()->id);
+       t->state = THREAD_COMPLETED;
+       stack_free(t->stack);
+}
+
+/*
+ * Return 1 if found next thread, 0 otherwise
+ */
+static int thread_system_next(void)
+{
+       struct thread *curr, *next;
+
+       curr = thread_current();
+       if (curr) {
+               if (curr->state == THREAD_READY)
+                       model->scheduler->add_thread(curr);
+               else if (curr->state == THREAD_RUNNING)
+                       /* Stopped while running; i.e., completed */
+                       thread_dispose(curr);
+               else
+                       DEBUG("ERROR: current thread in unexpected state??\n");
+       }
+       next = model->scheduler->next_thread();
+       if (next)
+               next->state = THREAD_RUNNING;
+       DEBUG("(%d, %d)\n", curr ? curr->id : -1, next ? next->id : -1);
+       if (!next)
+               return 1;
+       return thread_swap(model->system_thread, next);
+}
+
+static void thread_wait_finish(void)
+{
+
+       DBG();
+
+       while (!thread_system_next());
+}
+
+/*
+ * User program API functions
+ */
+int thread_create(struct thread *t, void (*start_routine)(), void *arg)
+{
+       int ret = 0;
+
+       DBG();
+
+       memset(t, 0, sizeof(*t));
+       model->assign_id(t);
+       DEBUG("create thread %d\n", t->id);
+
+       t->start_routine = start_routine;
+       t->arg = arg;
+
+       /* Initialize state */
+       ret = create_context(t);
+       if (ret)
+               return ret;
+
+       t->state = THREAD_CREATED;
+
+       model->scheduler->add_thread(t);
+       return 0;
+}
+
+void thread_join(struct thread *t)
+{
+       while (t->state != THREAD_COMPLETED)
+               thread_yield();
+}
+
+int thread_yield(void)
+{
+       struct thread *old, *next;
+
+       DBG();
+       old = thread_current();
+       old->state = THREAD_READY;
+       next = model->system_thread;
+       return thread_swap(old, next);
+}
+
+struct thread *thread_current(void)
+{
+       return model->scheduler->get_current_thread();
+}
+
+/*
+ * Main system function
+ */
+int main()
+{
+       struct thread user_thread;
+       struct thread *main_thread;
+
+       model = new ModelChecker();
+
+       main_thread = (struct thread *)malloc(sizeof(*main_thread));
+       create_initial_thread(main_thread);
+       model->add_system_thread(main_thread);
+
+       /* Start user program */
+       thread_create(&user_thread, &user_main, NULL);
+
+       /* Wait for all threads to complete */
+       thread_wait_finish();
+
+       delete model;
+
+       DEBUG("Exiting\n");
+       return 0;
+}