Browse Source

Fix build on systems which do not have pthread barriers, such as Mac OS X

Samuel Thibault 11 years ago
parent
commit
ece2c97b87
4 changed files with 17 additions and 8 deletions
  1. 5 0
      configure.ac
  2. 2 1
      include/starpu_config.h.in
  3. 3 3
      include/starpu_thread.h
  4. 7 4
      src/common/thread.c

+ 5 - 0
configure.ac

@@ -200,6 +200,11 @@ if test x$have_pthread_spin_lock = xyes; then
 	AC_DEFINE(STARPU_HAVE_PTHREAD_SPIN_LOCK,[],[pthread_spin_lock is available])
 fi
 
+AC_CHECK_FUNC([pthread_barrier_init], have_pthread_barrier=yes, have_pthread_barrier=no)
+if test x$have_pthread_barrier = xyes; then
+	AC_DEFINE(STARPU_HAVE_PTHREAD_BARRIER,[],[pthread_barrier is available])
+fi
+
 # yes, that's non portable, but it's still better than sched_setaffinity
 AC_CHECK_FUNCS(pthread_setaffinity_np)
 

+ 2 - 1
include/starpu_config.h.in

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2013  Université de Bordeaux 1
+ * Copyright (C) 2009-2014  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012, 2013  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -123,5 +123,6 @@ struct timespec
 
 #undef STARPU_HAVE_HWLOC
 #undef STARPU_HAVE_PTHREAD_SPIN_LOCK
+#undef STARPU_HAVE_PTHREAD_BARRIER
 
 #endif

+ 3 - 3
include/starpu_thread.h

@@ -198,7 +198,7 @@ int starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock);
  * Encapsulation of the pthread_barrier_* functions.
  */
 
-#ifdef STARPU_SIMGRID
+#if defined(STARPU_SIMGRID) || !defined(STARPU_HAVE_PTHREAD_BARRIER)
 
 typedef struct {
 	starpu_pthread_mutex_t mutex;
@@ -213,7 +213,7 @@ int starpu_pthread_barrier_init(starpu_pthread_barrier_t *barrier, const starpu_
 int starpu_pthread_barrier_destroy(starpu_pthread_barrier_t *barrier);
 int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier);
 
-#elif !defined(_MSC_VER) /* STARPU_SIMGRID */
+#elif !defined(_MSC_VER) /* STARPU_SIMGRID, !STARPU_HAVE_PTHREAD_BARRIER */
 
 typedef pthread_barrier_t starpu_pthread_barrier_t;
 typedef pthread_barrierattr_t starpu_pthread_barrierattr_t;
@@ -224,7 +224,7 @@ typedef pthread_barrierattr_t starpu_pthread_barrierattr_t;
 int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier);
 #define STARPU_PTHREAD_BARRIER_SERIAL_THREAD PTHREAD_BARRIER_SERIAL_THREAD
 
-#endif /* STARPU_SIMGRID, _MSC_VER */
+#endif /* STARPU_SIMGRID, !STARPU_HAVE_PTHREAD_BARRIER, _MSC_VER */
 
 /*
  * Encapsulation of the pthread_spin_* functions.

+ 7 - 4
src/common/thread.c

@@ -287,7 +287,9 @@ int starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock)
 
 	return p_ret;
 }
+#endif /* STARPU_SIMGRID */
 
+#if defined(STARPU_SIMGRID) || !defined(STARPU_HAVE_PTHREAD_BARRIER)
 int starpu_pthread_barrier_init(starpu_pthread_barrier_t *restrict barrier, const starpu_pthread_barrierattr_t *restrict attr, unsigned count)
 {
 	int ret = starpu_pthread_mutex_init(&barrier->mutex, NULL);
@@ -328,9 +330,9 @@ int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier)
 
 	return ret;
 }
+#endif /* defined(STARPU_SIMGRID) || !defined(STARPU_HAVE_PTHREAD_BARRIER) */
 
-#elif !defined(_MSC_VER) /* !STARPU_SIMGRID */
-
+#if !defined(STARPU_SIMGRID) && !defined(_MSC_VER) /* !STARPU_SIMGRID */
 int starpu_pthread_mutex_lock(starpu_pthread_mutex_t *mutex)
 {
 	_STARPU_TRACE_LOCKING_MUTEX();
@@ -445,7 +447,9 @@ int starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock)
 
 	return p_ret;
 }
+#endif
 
+#if !defined(STARPU_SIMGRID) && !defined(_MSC_VER) && defined(STARPU_HAVE_PTHREAD_BARRIER)
 int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier)
 {
 	int ret;
@@ -457,8 +461,7 @@ int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier)
 
 	return ret;
 }
-
-#endif /* STARPU_SIMGRID, _MSC_VER */
+#endif /* STARPU_SIMGRID, _MSC_VER, STARPU_HAVE_PTHREAD_BARRIER */
 
 #if defined(STARPU_SIMGRID) || !defined(HAVE_PTHREAD_SPIN_LOCK)