toss a place for useful information
[model-checker.git] / threads.cc
index 35000dc17d2ad40f73ea3652f0b634dd9f95678b..6a9391f0302467097b415bf4b129eb1b90fffaa5 100644 (file)
@@ -1,5 +1,3 @@
-/* -*- Mode: C; indent-tabs-mode: t -*- */
-
 #include "libthreads.h"
 #include "common.h"
 #include "threads.h"
 
 static void * stack_allocate(size_t size)
 {
-       return userMalloc(size);
+       return malloc(size);
 }
 
 static void stack_free(void *stack)
 {
-       userFree(stack);
+       free(stack);
 }
 
 Thread * thread_current(void)
 {
+       ASSERT(model);
        return model->scheduler->get_current_thread();
 }
 
-/* This method just gets around makecontext not being 64-bit clean */
-
+/**
+ * Provides a startup wrapper for each thread, allowing some initial
+ * model-checking data to be recorded. This method also gets around makecontext
+ * not being 64-bit clean
+ */
 void thread_startup() {
-       Thread * curr_thread=thread_current();
+       Thread * curr_thread = thread_current();
+
+       /* Add dummy "start" action, just to create a first clock vector */
+       model->switch_to_master(new ModelAction(THREAD_START, memory_order_seq_cst, curr_thread));
+
+       /* Call the actual thread function */
        curr_thread->start_routine(curr_thread->arg);
 }
 
@@ -70,19 +77,20 @@ void Thread::complete()
        }
 }
 
-Thread::Thread(thrd_t *t, void (*func)(void *), void *a) {
+Thread::Thread(thrd_t *t, void (*func)(void *), void *a) :
+       start_routine(func),
+       arg(a),
+       user_thread(t),
+       state(THREAD_CREATED),
+       last_action_val(VALUE_NONE)
+{
        int ret;
 
-       user_thread = t;
-       start_routine = func;
-       arg = a;
-
        /* Initialize state */
        ret = create_context();
        if (ret)
                printf("Error in create_context\n");
 
-       state = THREAD_CREATED;
        id = model->get_next_id();
        *user_thread = id;
        parent = thread_current();