summaryrefslogtreecommitdiff
path: root/lib/resource.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/resource.h')
-rw-r--r--lib/resource.h51
1 files changed, 32 insertions, 19 deletions
diff --git a/lib/resource.h b/lib/resource.h
index 3e589e32..911b990d 100644
--- a/lib/resource.h
+++ b/lib/resource.h
@@ -30,7 +30,7 @@ struct resclass {
char *name; /* Resource class name */
unsigned size; /* Standard size of single resource */
void (*free)(resource *); /* Freeing function */
- void (*dump)(resource *); /* Dump to debug output */
+ void (*dump)(resource *, unsigned indent); /* Dump to debug output */
resource *(*lookup)(resource *, unsigned long); /* Look up address (only for debugging) */
struct resmem (*memsize)(resource *); /* Return size of memory used by the resource, may be NULL */
};
@@ -43,25 +43,21 @@ struct resclass {
typedef struct pool {
resource r;
list inside;
- struct birdloop *loop;
const char *name;
} pool;
-void resource_init(void);
+void resource_init(void);
+pool *rp_new(pool *, const char *); /* Create new pool */
+pool *rp_newf(pool *, const char *, ...); /* Create a new pool with a formatted string as its name */
void rfree(void *); /* Free single resource */
-void rdump(void *); /* Dump to debug output */
+void rdump(void *, unsigned indent); /* Dump to debug output */
struct resmem rmemsize(void *res); /* Return size of memory used by the resource */
void rlookup(unsigned long); /* Look up address (only for debugging) */
void rmove(void *, pool *); /* Move to a different pool */
void *ralloc(pool *, struct resclass *);
-pool *rp_new(pool *, struct birdloop *loop, const char *); /* Create new pool */
-void rp_free(pool *p, pool *parent); /* Free parent pool */
-struct resmem rp_memsize(pool *p); /* Return size of memory used by the pool */
-void rp_dump(pool *p); /* Dump pool to debug output */
-
extern pool root_pool;
/* Normal memory blocks */
@@ -69,7 +65,6 @@ extern pool root_pool;
void *mb_alloc(pool *, unsigned size);
void *mb_allocz(pool *, unsigned size);
void *mb_realloc(void *m, unsigned size);
-void mb_move(void *, pool *);
void mb_free(void *);
/* Memory pools with linear allocation */
@@ -79,9 +74,10 @@ typedef struct linpool linpool;
typedef struct lp_state {
void *current, *large;
byte *ptr;
+ uint total_large;
} lp_state;
-linpool *lp_new(pool *, unsigned blk);
+linpool *lp_new(pool *);
void *lp_alloc(linpool *, unsigned size); /* Aligned */
void *lp_allocu(linpool *, unsigned size); /* Unaligned */
void *lp_allocz(linpool *, unsigned size); /* With clear */
@@ -89,10 +85,23 @@ void lp_flush(linpool *); /* Free everything, but leave linpool */
void lp_save(linpool *m, lp_state *p); /* Save state */
void lp_restore(linpool *m, lp_state *p); /* Restore state */
-extern const int lp_chunk_size;
-#define LP_GAS 1024
-#define LP_GOOD_SIZE(x) (((x + LP_GAS - 1) & (~(LP_GAS - 1))) - lp_chunk_size)
-#define lp_new_default(p) lp_new(p, 0)
+struct tmp_resources {
+ pool *pool, *parent;
+ linpool *lp;
+};
+
+extern _Thread_local struct tmp_resources tmp_res;
+
+#define tmp_linpool tmp_res.lp
+#define tmp_alloc(sz) lp_alloc(tmp_linpool, sz)
+#define tmp_allocu(sz) lp_allocu(tmp_linpool, sz)
+#define tmp_allocz(sz) lp_allocz(tmp_linpool, sz)
+
+void tmp_init(pool *p);
+void tmp_flush(void);
+
+
+#define lp_new_default lp_new
/* Slabs */
@@ -101,7 +110,7 @@ typedef struct slab slab;
slab *sl_new(pool *, unsigned size);
void *sl_alloc(slab *);
void *sl_allocz(slab *);
-void sl_free(slab *, void *);
+void sl_free(void *);
/*
* Low-level memory allocation functions, please don't use
@@ -110,12 +119,16 @@ void sl_free(slab *, void *);
void buffer_realloc(void **buf, unsigned *size, unsigned need, unsigned item_size);
-extern long page_size;
-
/* Allocator of whole pages; for use in slabs and other high-level allocators. */
+#define PAGE_HEAD(x) ((void *) (((uintptr_t) (x)) & ~(page_size-1)))
+extern long page_size;
+extern _Atomic int pages_kept;
+extern _Atomic int pages_kept_locally;
void *alloc_page(void);
void free_page(void *);
-#define PAGE_HEAD(x) ((void *) (((intptr_t) (x)) & ~(page_size-1)))
+void flush_local_pages(void);
+
+void resource_sys_init(void);
#ifdef HAVE_LIBDMALLOC
/*