utils.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef __COMMON_UTILS_H__
  17. #define __COMMON_UTILS_H__
  18. #include <starpu.h>
  19. #include <common/config.h>
  20. #include <sys/stat.h>
  21. #include <string.h>
  22. #include <pthread.h>
  23. int _starpu_mkpath(const char *s, mode_t mode);
  24. int _starpu_check_mutex_deadlock(pthread_mutex_t *mutex);
  25. #define PTHREAD_MUTEX_INIT(mutex, attr) { int ret = pthread_mutex_init((mutex), (attr)); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_mutex_init: %s\n", strerror(ret)); STARPU_ABORT(); }}
  26. #define PTHREAD_MUTEX_DESTROY(mutex) { int ret = pthread_mutex_destroy(mutex); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_mutex_destroy: %s\n", strerror(ret)); STARPU_ABORT(); }}
  27. #define PTHREAD_MUTEX_LOCK(mutex) { int ret = pthread_mutex_lock(mutex); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_mutex_lock : %s", strerror(ret)); STARPU_ABORT(); }}
  28. #define PTHREAD_MUTEX_UNLOCK(mutex) { int ret = pthread_mutex_unlock(mutex); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_mutex_unlock : %s", strerror(ret)); STARPU_ABORT(); }}
  29. #define PTHREAD_RWLOCK_INIT(rwlock, attr) { int ret = pthread_rwlock_init((rwlock), (attr)); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_rwlock_init : %s", strerror(ret)); }}
  30. #define PTHREAD_RWLOCK_RDLOCK(rwlock) { int ret = pthread_rwlock_rdlock(rwlock); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_rwlock_rdlock : %s", strerror(ret)); }}
  31. #define PTHREAD_RWLOCK_WRLOCK(rwlock) { int ret = pthread_rwlock_wrlock(rwlock); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_rwlock_wrlock : %s", strerror(ret)); }}
  32. #define PTHREAD_RWLOCK_UNLOCK(rwlock) { int ret = pthread_rwlock_unlock(rwlock); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_rwlock_unlock : %s", strerror(ret)); }}
  33. #define PTHREAD_RWLOCK_DESTROY(rwlock) { int ret = pthread_rwlock_destroy(rwlock); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_rwlock_destroy : %s", strerror(ret)); }}
  34. #define PTHREAD_COND_INIT(cond, attr) { int ret = pthread_cond_init((cond), (attr)); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_cond_init : %s", strerror(ret)); STARPU_ABORT(); }}
  35. #define PTHREAD_COND_DESTROY(cond) { int ret = pthread_cond_destroy(cond); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_cond_destroy : %s", strerror(ret)); STARPU_ABORT();}}
  36. #define PTHREAD_COND_SIGNAL(cond) { int ret = pthread_cond_signal(cond); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_cond_signal : %s", strerror(ret)); STARPU_ABORT();}}
  37. #define PTHREAD_COND_BROADCAST(cond) { int ret = pthread_cond_broadcast(cond); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_cond_broadcast : %s", strerror(ret)); STARPU_ABORT();}}
  38. #define PTHREAD_COND_WAIT(cond, mutex) { int ret = pthread_cond_wait((cond), (mutex)); if (STARPU_UNLIKELY(ret)) { fprintf(stderr, "pthread_cond_wait : %s", strerror(ret)); STARPU_ABORT();}}
  39. #endif // __COMMON_UTILS_H__