starpu_spinlock.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 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 <pthread.h>
  22. #include <common/utils.h>
  23. #include <common/config.h>
  24. struct _starpu_spinlock
  25. {
  26. #ifdef STARPU_SPINLOCK_CHECK
  27. pthread_mutexattr_t errcheck_attr;
  28. pthread_mutex_t errcheck_lock;
  29. #else
  30. #ifdef HAVE_PTHREAD_SPIN_LOCK
  31. pthread_spinlock_t lock;
  32. #else
  33. /* we only have a trivial implementation yet ! */
  34. uint32_t taken __attribute__ ((aligned(16)));
  35. #endif
  36. #endif
  37. };
  38. int _starpu_spin_init(struct _starpu_spinlock *lock);
  39. int _starpu_spin_destroy(struct _starpu_spinlock *lock);
  40. int _starpu_spin_lock(struct _starpu_spinlock *lock);
  41. int _starpu_spin_trylock(struct _starpu_spinlock *lock);
  42. int _starpu_spin_checklocked(struct _starpu_spinlock *lock);
  43. int _starpu_spin_unlock(struct _starpu_spinlock *lock);
  44. #endif // __STARPU_SPINLOCK_H__