atomic_types.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (c) 2018 Richard Braun.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program 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
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. *
  18. * Isolated type definition used to avoid inclusion circular dependencies.
  19. *
  20. * These types are directly used by both the atomic and latomic modules.
  21. */
  22. #ifndef KERN_ATOMIC_TYPES_H
  23. #define KERN_ATOMIC_TYPES_H
  24. /*
  25. * After function selection, type genericity is achieved with transparent
  26. * unions, a GCC extension. Here are a few things to keep in mind :
  27. * - all members must have the same representation
  28. * - calling conventions are inferred from the first member
  29. */
  30. #ifdef __LP64__
  31. union atomic_ptr_32 {
  32. int *i_ptr;
  33. unsigned int *ui_ptr;
  34. } __attribute__((transparent_union));
  35. union atomic_constptr_32 {
  36. const int *i_ptr;
  37. const unsigned int *ui_ptr;
  38. } __attribute__((transparent_union));
  39. union atomic_val_32 {
  40. int i;
  41. unsigned int ui;
  42. } __attribute__((transparent_union));
  43. union atomic_ptr_64 {
  44. void *ptr;
  45. unsigned long long *ull_ptr;
  46. } __attribute__((transparent_union));
  47. union atomic_constptr_64 {
  48. const void *ptr;
  49. const unsigned long long *ull_ptr;
  50. } __attribute__((transparent_union));
  51. union atomic_val_64 {
  52. void *ptr;
  53. long l;
  54. unsigned long ul;
  55. long long ll;
  56. unsigned long long ull;
  57. } __attribute__((transparent_union));
  58. #else /* __LP64__ */
  59. union atomic_ptr_32 {
  60. void *ptr;
  61. unsigned int *ui_ptr;
  62. } __attribute__((transparent_union));
  63. union atomic_constptr_32 {
  64. const void *ptr;
  65. const unsigned int *ui_ptr;
  66. } __attribute__((transparent_union));
  67. union atomic_val_32 {
  68. void *ptr;
  69. int i;
  70. unsigned int ui;
  71. long l;
  72. unsigned long ul;
  73. } __attribute__((transparent_union));
  74. union atomic_ptr_64 {
  75. long long *ll_ptr;
  76. unsigned long long *ull_ptr;
  77. } __attribute__((transparent_union));
  78. union atomic_constptr_64 {
  79. const long long *ll_ptr;
  80. const unsigned long long *ull_ptr;
  81. } __attribute__((transparent_union));
  82. union atomic_val_64 {
  83. long long ll;
  84. unsigned long long ull;
  85. } __attribute__((transparent_union));
  86. #endif /* __LP64__ */
  87. #endif /* KERN_ATOMIC_TYPES_H */