Просмотр исходного кода

The _starpu_check_mutex_deadlock provides a quick'n'dirty (not 100% garanteed)
test to detect that a lock is already taken by the current thread.

Cédric Augonnet лет назад: 15
Родитель
Сommit
330ebd2afb
2 измененных файлов с 18 добавлено и 0 удалено
  1. 17 0
      src/common/utils.c
  2. 1 0
      src/common/utils.h

+ 17 - 0
src/common/utils.c

@@ -69,3 +69,20 @@ out:
 	return rv;
 }
 
+int _starpu_check_mutex_deadlock(pthread_mutex_t *mutex)
+{
+	int ret;
+	ret = pthread_mutex_trylock(mutex);
+	if (!ret)
+	{
+		pthread_mutex_unlock(mutex);
+		return 0;
+	}
+
+	if (ret == EBUSY)
+		return 0;
+
+	STARPU_ASSERT (ret != EDEADLK);
+
+	return 1;
+}

+ 1 - 0
src/common/utils.h

@@ -22,5 +22,6 @@
 #include <sys/stat.h>
 
 int _starpu_mkpath(const char *s, mode_t mode);
+int _starpu_check_mutex_deadlock(pthread_mutex_t *mutex);
 
 #endif // __COMMON_UTILS_H__