Do not report deadlock on relocking a recursive mutex; lock count not implemented yet
[c11tester.git] / threads.cc
index 17b76863a62be4943ef07fc22d5e7df5bf6e83c7..ee0df19ca338bd20e2a3dc0e4bd85b00ab059354 100644 (file)
@@ -59,11 +59,9 @@ Thread * thread_current(void)
        return model->get_current_thread();
 }
 
-#ifdef TLS
 void modelexit() {
        model->switch_to_master(new ModelAction(THREAD_FINISH, std::memory_order_seq_cst, thread_current()));
 }
-#endif
 
 void initMainThread() {
        atexit(modelexit);
@@ -492,6 +490,14 @@ Thread * Thread::waiting_on() const
 bool Thread::is_waiting_on(const Thread *t) const
 {
        Thread *wait;
+
+       // One thread relocks a recursive mutex
+       if (waiting_on() == t && pending->is_lock()) {
+               int mutex_type = pending->get_mutex()->get_state()->type;
+               if (mutex_type == PTHREAD_MUTEX_RECURSIVE)
+                       return false;
+       }
+
        for (wait = waiting_on();wait != NULL;wait = wait->waiting_on())
                if (wait == t)
                        return true;