starpu_spinlock.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2014 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2013, 2014 Centre National de la Recherche Scientifique
  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. #ifndef __STARPU_SPINLOCK_H__
  18. #define __STARPU_SPINLOCK_H__
  19. #include <errno.h>
  20. #include <stdint.h>
  21. #include <common/config.h>
  22. #include <starpu.h>
  23. struct _starpu_spinlock
  24. {
  25. #if defined(STARPU_SPINLOCK_CHECK)
  26. starpu_pthread_mutex_t errcheck_lock;
  27. const char *last_taker;
  28. #else
  29. starpu_pthread_spinlock_t lock;
  30. #endif
  31. };
  32. #ifdef STARPU_SPINLOCK_CHECK
  33. #define STARPU_RECORD_LOCK(lock) do { \
  34. (lock)->last_taker = __starpu_func__; \
  35. } while(0)
  36. #else // !STARPU_SPINLOCK_CHECK
  37. #define STARPU_RECORD_LOCK(lock) do {} while(0)
  38. #endif // STARPU_SPINLOCK_CHECK
  39. int _starpu_spin_init(struct _starpu_spinlock *lock);
  40. int _starpu_spin_destroy(struct _starpu_spinlock *lock);
  41. int _starpu_spin_lock(struct _starpu_spinlock *lock);
  42. #define _starpu_spin_lock(lock) ({ \
  43. _STARPU_TRACE_LOCKING_SPINLOCK(); \
  44. _starpu_spin_lock(lock); \
  45. _STARPU_TRACE_SPINLOCK_LOCKED(); \
  46. STARPU_RECORD_LOCK(lock); \
  47. 0; \
  48. })
  49. int _starpu_spin_trylock(struct _starpu_spinlock *lock);
  50. #define _starpu_spin_trylock(lock) ({ \
  51. _STARPU_TRACE_TRYLOCK_SPINLOCK(); \
  52. int err = _starpu_spin_trylock(lock); \
  53. if (!err) { \
  54. STARPU_RECORD_LOCK(lock); \
  55. _STARPU_TRACE_SPINLOCK_LOCKED(); \
  56. } \
  57. err; \
  58. })
  59. int _starpu_spin_checklocked(struct _starpu_spinlock *lock);
  60. int _starpu_spin_unlock(struct _starpu_spinlock *lock);
  61. #define _starpu_spin_unlock(lock) ({ \
  62. _STARPU_TRACE_UNLOCKING_SPINLOCK(); \
  63. _starpu_spin_unlock(lock); \
  64. _STARPU_TRACE_SPINLOCK_UNLOCKED(); \
  65. 0; \
  66. })
  67. #define STARPU_SPIN_MAXTRY 10
  68. #endif // __STARPU_SPINLOCK_H__