cacheline.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright (C) 2009-2015 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson <rth@redhat.com>.
  3. This file is part of the GNU Transactional Memory Library (libitm).
  4. Libitm is free software; you can redistribute it and/or modify it
  5. 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. Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #ifndef LIBITM_CACHELINE_H
  20. #define LIBITM_CACHELINE_H 1
  21. namespace GTM HIDDEN {
  22. // A cacheline is the smallest unit with which locks are associated.
  23. // The current implementation of the _ITM_[RW] barriers assumes that
  24. // all data types can fit (aligned) within a cachline, which means
  25. // in practice sizeof(complex long double) is the smallest cacheline size.
  26. // It ought to be small enough for efficient manipulation of the
  27. // modification mask, below.
  28. #ifndef CACHELINE_SIZE
  29. # define CACHELINE_SIZE 32
  30. #endif
  31. // A gtm_cacheline_mask stores a modified bit for every modified byte
  32. // in the cacheline with which it is associated.
  33. typedef sized_integral<CACHELINE_SIZE / 8>::type gtm_cacheline_mask;
  34. union gtm_cacheline
  35. {
  36. // Byte access to the cacheline.
  37. unsigned char b[CACHELINE_SIZE] __attribute__((aligned(CACHELINE_SIZE)));
  38. // Larger sized access to the cacheline.
  39. uint16_t u16[CACHELINE_SIZE / sizeof(uint16_t)];
  40. uint32_t u32[CACHELINE_SIZE / sizeof(uint32_t)];
  41. uint64_t u64[CACHELINE_SIZE / sizeof(uint64_t)];
  42. gtm_word w[CACHELINE_SIZE / sizeof(gtm_word)];
  43. };
  44. } // namespace GTM
  45. #endif // LIBITM_CACHELINE_H