threads: add per-thread "return" values for 'model-checking/user context' switch
authorBrian Norris <banorris@uci.edu>
Tue, 3 Jul 2012 23:31:45 +0000 (16:31 -0700)
committerBrian Norris <banorris@uci.edu>
Sat, 7 Jul 2012 00:28:03 +0000 (17:28 -0700)
The model-checker needs to return a value to the user context when performing
atomic loads, for instance. I will be implementing this by caching the return
value on a per-thread basis. This is because an atomic_load() might result in a
context switch before actually returning the value.

These functions are not yet used.

threads.cc
threads.h

index 6d290a94f9f2131b5ca9e7d47b8bae457dd02857..b6eaee4ea18cb511b9d4e37edc78814669e152c8 100644 (file)
@@ -69,7 +69,9 @@ void Thread::complete()
        }
 }
 
-Thread::Thread(thrd_t *t, void (*func)(void *), void *a) {
+Thread::Thread(thrd_t *t, void (*func)(void *), void *a) :
+       last_action_val(VALUE_NONE)
+{
        int ret;
 
        user_thread = t;
index a97a04c704449963981fe443a711c64abc716fb3..ed9cbfed118a20561f271aaace5acc67f5b47f6e 100644 (file)
--- a/threads.h
+++ b/threads.h
@@ -41,6 +41,21 @@ public:
        void set_creation(ModelAction *act) { creation = act; }
        ModelAction * get_creation() { return creation; }
 
+       /**
+        * Set a return value for the last action in this thread (e.g., for an
+        * atomic read).
+        * @param value The value to return
+        */
+       void set_return_value(int value) { last_action_val = value; }
+
+       /**
+        * Retrieve a return value for the last action in this thread. Used,
+        * for instance, for an atomic read to return the 'read' value. Should
+        * be called from a user context.
+        * @return The value 'returned' by the action
+        */
+       int get_return_value() { return last_action_val; }
+
        friend void thread_startup();
 
        SNAPSHOTALLOC
@@ -56,6 +71,13 @@ private:
        thrd_t *user_thread;
        thread_id_t id;
        thread_state state;
+
+       /**
+        * The value returned by the last action in this thread
+        * @see Thread::set_return_value()
+        * @see Thread::get_return_value()
+        */
+       int last_action_val;
 };
 
 Thread * thread_current();