pool.h 1.7 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. uintptr_t maxsize;
  13. uintptr_t cursize;
  14. uintptr_t curfree;
  15. uintptr_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. int flags;
  20. int nfree;
  21. int lastcompact;
  22. void* freeroot; /* actually Free* */
  23. void* arenalist; /* actually Arena* */
  24. void* (*alloc)(uint32_t);
  25. int (*merge)(void*, void*);
  26. void (*move)(void* from, void* to);
  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, uint32_t);
  36. extern void poolfree(Pool*, void*);
  37. extern uint32_t poolmsize(Pool*, void*);
  38. extern void* poolrealloc(Pool*, void*, uint32_t);
  39. extern void poolcheck(Pool*);
  40. extern int poolcompact(Pool*);
  41. extern void poolblockcheck(Pool*, void*);
  42. extern Pool* mainmem;
  43. extern Pool* imagmem;
  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. };