|
@@ -19,18 +19,11 @@
|
|
|
#include <common/config.h>
|
|
|
#include <common/utils.h>
|
|
|
#include <common/fxt.h>
|
|
|
-#include <starpu_util.h>
|
|
|
-
|
|
|
-#ifdef STARPU_SIMGRID
|
|
|
-#include <msg/msg.h>
|
|
|
-#endif
|
|
|
+#include <common/thread.h>
|
|
|
|
|
|
int _starpu_spin_init(struct _starpu_spinlock *lock)
|
|
|
{
|
|
|
-#ifdef STARPU_SIMGRID
|
|
|
- lock->taken = 0;
|
|
|
- return 0;
|
|
|
-#elif defined(STARPU_SPINLOCK_CHECK)
|
|
|
+#if defined(STARPU_SPINLOCK_CHECK)
|
|
|
// memcpy(&lock->errcheck_lock, PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP, sizeof(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP));
|
|
|
int ret;
|
|
|
ret = pthread_mutexattr_init(&lock->errcheck_attr);
|
|
@@ -41,129 +34,72 @@ int _starpu_spin_init(struct _starpu_spinlock *lock)
|
|
|
|
|
|
ret = pthread_mutex_init(&lock->errcheck_lock, &lock->errcheck_attr);
|
|
|
return ret;
|
|
|
-#elif defined(HAVE_PTHREAD_SPIN_LOCK)
|
|
|
- int ret = pthread_spin_init(&lock->lock, 0);
|
|
|
+#else
|
|
|
+ int ret = starpu_pthread_spin_init(&lock->lock, 0);
|
|
|
STARPU_ASSERT(!ret);
|
|
|
return ret;
|
|
|
-#else
|
|
|
- lock->taken = 0;
|
|
|
- return 0;
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
int _starpu_spin_destroy(struct _starpu_spinlock *lock STARPU_ATTRIBUTE_UNUSED)
|
|
|
{
|
|
|
-#ifdef STARPU_SIMGRID
|
|
|
- /* we don't do anything */
|
|
|
- return 0;
|
|
|
-#elif defined(STARPU_SPINLOCK_CHECK)
|
|
|
+#if defined(STARPU_SPINLOCK_CHECK)
|
|
|
pthread_mutexattr_destroy(&lock->errcheck_attr);
|
|
|
return pthread_mutex_destroy(&lock->errcheck_lock);
|
|
|
-#elif defined(HAVE_PTHREAD_SPIN_LOCK)
|
|
|
- int ret = pthread_spin_destroy(&lock->lock);
|
|
|
- STARPU_ASSERT(!ret);
|
|
|
- return ret;
|
|
|
#else
|
|
|
- /* we don't do anything */
|
|
|
- return 0;
|
|
|
+ return starpu_pthread_spin_destroy(&lock->lock);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
#undef _starpu_spin_lock
|
|
|
int _starpu_spin_lock(struct _starpu_spinlock *lock)
|
|
|
{
|
|
|
-#ifdef STARPU_SIMGRID
|
|
|
- while (1)
|
|
|
- {
|
|
|
- if (!lock->taken)
|
|
|
- {
|
|
|
- lock->taken = 1;
|
|
|
- return 0;
|
|
|
- }
|
|
|
- /* Give hand to another thread, hopefully the one which has the
|
|
|
- * spinlock and probably just has also a short-lived mutex. */
|
|
|
- MSG_process_sleep(0.000001);
|
|
|
- STARPU_UYIELD();
|
|
|
- }
|
|
|
-#elif defined(STARPU_SPINLOCK_CHECK)
|
|
|
+#if defined(STARPU_SPINLOCK_CHECK)
|
|
|
int ret = pthread_mutex_lock(&lock->errcheck_lock);
|
|
|
STARPU_ASSERT(!ret);
|
|
|
return ret;
|
|
|
-#elif defined(HAVE_PTHREAD_SPIN_LOCK)
|
|
|
- int ret = pthread_spin_lock(&lock->lock);
|
|
|
+#else
|
|
|
+ int ret = starpu_pthread_spin_lock(&lock->lock);
|
|
|
STARPU_ASSERT(!ret);
|
|
|
return ret;
|
|
|
-#else
|
|
|
- uint32_t prev;
|
|
|
- do
|
|
|
- {
|
|
|
- prev = STARPU_TEST_AND_SET(&lock->taken, 1);
|
|
|
- if (prev)
|
|
|
- STARPU_UYIELD();
|
|
|
- }
|
|
|
- while (prev);
|
|
|
- return 0;
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
int _starpu_spin_checklocked(struct _starpu_spinlock *lock)
|
|
|
{
|
|
|
-#ifdef STARPU_SIMGRID
|
|
|
- STARPU_ASSERT(lock->taken);
|
|
|
- return !lock->taken;
|
|
|
-#elif defined(STARPU_SPINLOCK_CHECK)
|
|
|
+#if defined(STARPU_SPINLOCK_CHECK)
|
|
|
int ret = starpu_pthread_mutex_trylock(&lock->errcheck_lock);
|
|
|
STARPU_ASSERT(ret != 0);
|
|
|
return ret == 0;
|
|
|
-#elif defined(HAVE_PTHREAD_SPIN_LOCK)
|
|
|
- int ret = pthread_spin_trylock(&lock->lock);
|
|
|
- STARPU_ASSERT(ret != 0);
|
|
|
- return ret == 0;
|
|
|
#else
|
|
|
- STARPU_ASSERT(lock->taken);
|
|
|
- return !lock->taken;
|
|
|
+ return _starpu_pthread_spin_checklocked(&lock->lock);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
#undef _starpu_spin_trylock
|
|
|
int _starpu_spin_trylock(struct _starpu_spinlock *lock)
|
|
|
{
|
|
|
-#ifdef STARPU_SIMGRID
|
|
|
- if (lock->taken)
|
|
|
- return EBUSY;
|
|
|
- lock->taken = 1;
|
|
|
- return 0;
|
|
|
-#elif defined(STARPU_SPINLOCK_CHECK)
|
|
|
+#if defined(STARPU_SPINLOCK_CHECK)
|
|
|
int ret = starpu_pthread_mutex_trylock(&lock->errcheck_lock);
|
|
|
STARPU_ASSERT(!ret || (ret == EBUSY));
|
|
|
return ret;
|
|
|
-#elif defined(HAVE_PTHREAD_SPIN_LOCK)
|
|
|
- int ret = pthread_spin_trylock(&lock->lock);
|
|
|
+#else
|
|
|
+ int ret = starpu_pthread_spin_trylock(&lock->lock);
|
|
|
STARPU_ASSERT(!ret || (ret == EBUSY));
|
|
|
return ret;
|
|
|
-#else
|
|
|
- uint32_t prev;
|
|
|
- prev = STARPU_TEST_AND_SET(&lock->taken, 1);
|
|
|
- return (prev == 0)?0:EBUSY;
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
#undef _starpu_spin_unlock
|
|
|
int _starpu_spin_unlock(struct _starpu_spinlock *lock STARPU_ATTRIBUTE_UNUSED)
|
|
|
{
|
|
|
-#ifdef STARPU_SIMGRID
|
|
|
- lock->taken = 0;
|
|
|
- return 0;
|
|
|
-#elif defined(STARPU_SPINLOCK_CHECK)
|
|
|
+#if defined(STARPU_SPINLOCK_CHECK)
|
|
|
int ret = pthread_mutex_unlock(&lock->errcheck_lock);
|
|
|
STARPU_ASSERT(!ret);
|
|
|
return ret;
|
|
|
-#elif defined(HAVE_PTHREAD_SPIN_LOCK)
|
|
|
- int ret = pthread_spin_unlock(&lock->lock);
|
|
|
+#else
|
|
|
+ int ret = starpu_pthread_spin_unlock(&lock->lock);
|
|
|
STARPU_ASSERT(!ret);
|
|
|
return ret;
|
|
|
-#else
|
|
|
- STARPU_RELEASE(&lock->taken);
|
|
|
- return 0;
|
|
|
#endif
|
|
|
}
|