xyarray.h 960 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LIBPERF_INTERNAL_XYARRAY_H
  3. #define __LIBPERF_INTERNAL_XYARRAY_H
  4. #include <linux/compiler.h>
  5. #include <sys/types.h>
  6. struct xyarray {
  7. size_t row_size;
  8. size_t entry_size;
  9. size_t entries;
  10. size_t max_x;
  11. size_t max_y;
  12. char contents[] __aligned(8);
  13. };
  14. struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size);
  15. void xyarray__delete(struct xyarray *xy);
  16. void xyarray__reset(struct xyarray *xy);
  17. static inline void *__xyarray__entry(struct xyarray *xy, int x, int y)
  18. {
  19. return &xy->contents[x * xy->row_size + y * xy->entry_size];
  20. }
  21. static inline void *xyarray__entry(struct xyarray *xy, size_t x, size_t y)
  22. {
  23. if (x >= xy->max_x || y >= xy->max_y)
  24. return NULL;
  25. return __xyarray__entry(xy, x, y);
  26. }
  27. static inline int xyarray__max_y(struct xyarray *xy)
  28. {
  29. return xy->max_y;
  30. }
  31. static inline int xyarray__max_x(struct xyarray *xy)
  32. {
  33. return xy->max_x;
  34. }
  35. #endif /* __LIBPERF_INTERNAL_XYARRAY_H */