starpu_spinlock.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2012-2014, 2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2013, 2014 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <common/starpu_spinlock.h>
  18. #include <common/config.h>
  19. #include <common/utils.h>
  20. #include <common/fxt.h>
  21. #include <common/thread.h>
  22. #if defined(STARPU_SPINLOCK_CHECK)
  23. int _starpu_spin_init(struct _starpu_spinlock *lock)
  24. {
  25. starpu_pthread_mutexattr_t errcheck_attr;
  26. // memcpy(&lock->errcheck_lock, PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP, sizeof(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP));
  27. int ret;
  28. ret = starpu_pthread_mutexattr_init(&errcheck_attr);
  29. STARPU_CHECK_RETURN_VALUE(ret, "pthread_mutexattr_init");
  30. ret = starpu_pthread_mutexattr_settype(&errcheck_attr, PTHREAD_MUTEX_ERRORCHECK);
  31. STARPU_ASSERT(!ret);
  32. ret = starpu_pthread_mutex_init(&lock->errcheck_lock, &errcheck_attr);
  33. starpu_pthread_mutexattr_destroy(&errcheck_attr);
  34. return ret;
  35. }
  36. int _starpu_spin_destroy(struct _starpu_spinlock *lock)
  37. {
  38. return starpu_pthread_mutex_destroy(&lock->errcheck_lock);
  39. }
  40. #endif