model: privatize some thread functions
[c11tester.git] / threads.cc
index 762bbff34c2463a3dbaf6179e3af3e1eb977ca8b..00e5c2fbd4a0f1287ac6b68b8be50a1a49b82bd8 100644 (file)
@@ -5,6 +5,7 @@
 #include <string.h>
 
 #include <threads.h>
+#include <mutex>
 #include "common.h"
 #include "threads-model.h"
 #include "action.h"
@@ -179,7 +180,6 @@ Thread::~Thread()
 {
        if (!is_complete())
                complete();
-       model->remove_thread(this);
 }
 
 /** @return The thread_id_t corresponding to this Thread object. */
@@ -197,3 +197,19 @@ void Thread::set_state(thread_state s)
        ASSERT(s == THREAD_COMPLETED || state != THREAD_COMPLETED);
        state = s;
 }
+
+/**
+ * Get the Thread that this Thread is waiting on
+ * @return The thread we are waiting on, if any; otherwise NULL
+ */
+Thread * Thread::waiting_on() const
+{
+       if (!pending)
+               return NULL;
+
+       if (pending->get_type() == THREAD_JOIN)
+               return pending->get_thread_operand();
+       else if (pending->is_lock())
+               return (Thread *)pending->get_mutex()->get_state()->locked;
+       return NULL;
+}