starpu_spinlock.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2013 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2013 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 <starpu_thread.h>
  22. #include <common/config.h>
  23. #include <common/thread.h>
  24. struct _starpu_spinlock
  25. {
  26. #ifdef STARPU_SIMGRID
  27. int taken;
  28. #elif defined(STARPU_SPINLOCK_CHECK)
  29. starpu_pthread_mutexattr_t errcheck_attr;
  30. starpu_pthread_mutex_t errcheck_lock;
  31. #elif defined(HAVE_PTHREAD_SPIN_LOCK)
  32. _starpu_pthread_spinlock_t lock;
  33. #else
  34. /* we only have a trivial implementation yet ! */
  35. uint32_t taken __attribute__ ((aligned(16)));
  36. #endif
  37. #ifdef STARPU_SPINLOCK_CHECK
  38. const char *last_taker;
  39. #endif
  40. };
  41. int _starpu_spin_init(struct _starpu_spinlock *lock);
  42. int _starpu_spin_destroy(struct _starpu_spinlock *lock);
  43. int _starpu_spin_lock(struct _starpu_spinlock *lock);
  44. #if defined(STARPU_SPINLOCK_CHECK)
  45. #define _starpu_spin_lock(lock) ({ \
  46. _starpu_spin_lock(lock); \
  47. (lock)->last_taker = __starpu_func__; \
  48. 0; \
  49. })
  50. #endif
  51. int _starpu_spin_trylock(struct _starpu_spinlock *lock);
  52. #if defined(STARPU_SPINLOCK_CHECK)
  53. #define _starpu_spin_trylock(lock) ({ \
  54. int err = _starpu_spin_trylock(lock); \
  55. if (!err) \
  56. (lock)->last_taker = __starpu_func__; \
  57. err; \
  58. })
  59. #endif
  60. int _starpu_spin_checklocked(struct _starpu_spinlock *lock);
  61. int _starpu_spin_unlock(struct _starpu_spinlock *lock);
  62. #endif // __STARPU_SPINLOCK_H__