qemu-tls.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Abstraction layer for defining and using TLS variables
  3. *
  4. * Copyright (c) 2011 Red Hat, Inc
  5. * Copyright (c) 2011 Linaro Limited
  6. *
  7. * Authors:
  8. * Paolo Bonzini <pbonzini@redhat.com>
  9. * Peter Maydell <peter.maydell@linaro.org>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #ifndef QEMU_TLS_H
  25. #define QEMU_TLS_H
  26. /* Per-thread variables. Note that we only have implementations
  27. * which are really thread-local on Linux; the dummy implementations
  28. * define plain global variables.
  29. *
  30. * This means that for the moment use should be restricted to
  31. * per-VCPU variables, which are OK because:
  32. * - the only -user mode supporting multiple VCPU threads is linux-user
  33. * - TCG system mode is single-threaded regarding VCPUs
  34. * - KVM system mode is multi-threaded but limited to Linux
  35. *
  36. * TODO: proper implementations via Win32 .tls sections and
  37. * POSIX pthread_getspecific.
  38. */
  39. #ifdef __linux__
  40. #define DECLARE_TLS(type, x) extern DEFINE_TLS(type, x)
  41. #define DEFINE_TLS(type, x) __thread __typeof__(type) tls__##x
  42. #define get_tls(x) tls__##x
  43. #else
  44. /* Dummy implementations which define plain global variables */
  45. #define DECLARE_TLS(type, x) extern DEFINE_TLS(type, x)
  46. #define DEFINE_TLS(type, x) __typeof__(type) tls__##x
  47. #define get_tls(x) tls__##x
  48. #endif
  49. #endif