Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  1. /* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
  2. #ifndef IARRAY_H
  3. #define IARRAY_H
  4. /* This header defines an indirect array for use with the io_* routines.
  5. * Assumptions:
  6. * - the elements are small (many fit on one page),
  7. * - the platform has an atomic compare-and-swap instruction
  8. * - the compiler supports it via __sync_val_compare_and_swap
  9. */
  10. #include "uint64.h"
  11. #include <stddef.h>
  12. #ifdef __MINGW32__
  13. #include <windows.h>
  14. #else
  15. #include <pthread.h>
  16. #endif
  17. typedef struct _iarray_page {
  18. struct _iarray_page* next;
  19. char data[];
  20. } iarray_page;
  21. typedef struct {
  22. iarray_page* pages[16];
  23. size_t elemsize,elemperpage,bytesperpage,len;
  24. } iarray;
  25. void iarray_init(iarray* ia,size_t elemsize);
  26. void* iarray_get(iarray* ia,size_t pos);
  27. void* iarray_allocate(iarray* ia,size_t pos);
  28. size_t iarray_length(iarray* ia);
  29. /* WARNING: do not use the array during or after iarray_free, make sure
  30. * no threads are potentially doing anything with the iarray while it is
  31. * being freed! */
  32. void iarray_free(iarray* ia);
  33. #endif