qemu-lock.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2003 Fabrice Bellard
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, see <http://www.gnu.org/licenses/>
  16. */
  17. /* configure guarantees us that we have pthreads on any host except
  18. * mingw32, which doesn't support any of the user-only targets.
  19. * So we can simply assume we have pthread mutexes here.
  20. */
  21. #if defined(CONFIG_USER_ONLY)
  22. #include <pthread.h>
  23. #define spin_lock pthread_mutex_lock
  24. #define spin_unlock pthread_mutex_unlock
  25. #define spinlock_t pthread_mutex_t
  26. #define SPIN_LOCK_UNLOCKED PTHREAD_MUTEX_INITIALIZER
  27. #else
  28. /* Empty implementations, on the theory that system mode emulation
  29. * is single-threaded. This means that these functions should only
  30. * be used from code run in the TCG cpu thread, and cannot protect
  31. * data structures which might also be accessed from the IO thread
  32. * or from signal handlers.
  33. */
  34. typedef int spinlock_t;
  35. #define SPIN_LOCK_UNLOCKED 0
  36. static inline void spin_lock(spinlock_t *lock)
  37. {
  38. }
  39. static inline void spin_unlock(spinlock_t *lock)
  40. {
  41. }
  42. #endif