pool.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. typedef struct Pool Pool;
  10. struct Pool {
  11. char* name;
  12. uint32_t maxsize;
  13. uint32_t cursize;
  14. uint32_t curfree;
  15. uint32_t curalloc;
  16. uint32_t minarena; /* smallest size of new arena */
  17. uint32_t quantum; /* allocated blocks should be multiple of */
  18. uint32_t minblock; /* smallest newly allocated block */
  19. void* freeroot; /* actually Free* */
  20. void* arenalist; /* actually Arena* */
  21. void* (*alloc)(uint32_t);
  22. int (*merge)(void*, void*);
  23. void (*move)(void* from, void* to);
  24. int flags;
  25. int nfree;
  26. int lastcompact;
  27. void (*lock)(Pool*);
  28. void (*unlock)(Pool*);
  29. void (*print)(Pool*, char*, ...);
  30. void (*panic)(Pool*, char*, ...);
  31. void (*logstack)(Pool*);
  32. void* private;
  33. };
  34. extern void* poolalloc(Pool*, uint32_t);
  35. extern void* poolallocalign(Pool*, uint32_t, uint32_t, int32_t,
  36. uint32_t);
  37. extern void poolfree(Pool*, void*);
  38. extern uint32_t poolmsize(Pool*, void*);
  39. extern void* poolrealloc(Pool*, void*, uint32_t);
  40. extern void poolcheck(Pool*);
  41. extern int poolcompact(Pool*);
  42. extern void poolblockcheck(Pool*, void*);
  43. extern Pool* mainmem;
  44. enum { /* flags */
  45. POOL_ANTAGONISM = 1<<0,
  46. POOL_PARANOIA = 1<<1,
  47. POOL_VERBOSITY = 1<<2,
  48. POOL_DEBUGGING = 1<<3,
  49. POOL_LOGGING = 1<<4,
  50. POOL_TOLERANCE = 1<<5,
  51. POOL_NOREUSE = 1<<6,
  52. };