summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2023-04-28 23:48:03 +0200
committerMaria Matejka <mq@ucw.cz>2023-05-03 21:30:29 +0200
commit9f25dd79b8e9fdea9050c9f7e3a10cea8791d745 (patch)
tree3e72b3f665d6e18d65c25ad6baf37a015c8767bf
parent010c26c29602d52e704ea7cb83f2f6acacbddd0d (diff)
Allocation from linpools and slabs requires the appropriate lock to be taken
-rw-r--r--lib/mempool.c5
-rw-r--r--lib/resource.c7
-rw-r--r--lib/resource.h3
-rw-r--r--lib/slab.c2
4 files changed, 10 insertions, 7 deletions
diff --git a/lib/mempool.c b/lib/mempool.c
index 56a4c3db..578750c1 100644
--- a/lib/mempool.c
+++ b/lib/mempool.c
@@ -86,6 +86,7 @@ linpool
void *
lp_alloc(linpool *m, uint size)
{
+ ASSERT_DIE(DG_IS_LOCKED(resource_parent(&m->r)->domain));
byte *a = (byte *) BIRD_ALIGN((unsigned long) m->ptr, CPU_STRUCT_ALIGN);
byte *e = a + size;
@@ -145,6 +146,7 @@ lp_alloc(linpool *m, uint size)
void *
lp_allocu(linpool *m, uint size)
{
+ ASSERT_DIE(DG_IS_LOCKED(resource_parent(&m->r)->domain));
byte *a = m->ptr;
byte *e = a + size;
@@ -183,6 +185,7 @@ lp_allocz(linpool *m, uint size)
void
lp_flush(linpool *m)
{
+ ASSERT_DIE(DG_IS_LOCKED(resource_parent(&m->r)->domain));
struct lp_chunk *c;
/* Move ptr to the first chunk and free all other chunks */
@@ -216,6 +219,7 @@ lp_flush(linpool *m)
void
lp_save(linpool *m, lp_state *p)
{
+ ASSERT_DIE(DG_IS_LOCKED(resource_parent(&m->r)->domain));
p->current = m->current;
p->large = m->first_large;
p->total_large = m->total_large;
@@ -236,6 +240,7 @@ void
lp_restore(linpool *m, lp_state *p)
{
struct lp_chunk *c;
+ ASSERT_DIE(DG_IS_LOCKED(resource_parent(&m->r)->domain));
/* Move ptr to the saved pos and free all newer large chunks */
m->current = c = p->current ?: m->first;
diff --git a/lib/resource.c b/lib/resource.c
index e0aaac0a..611db4d7 100644
--- a/lib/resource.c
+++ b/lib/resource.c
@@ -189,13 +189,6 @@ pool_lookup(resource *P, unsigned long a)
return q;
}
-static pool *
-resource_parent(resource *r)
-{
- return SKIP_BACK(pool, inside, resource_enlisted(r));
-}
-
-
/**
* rmove - move a resource
* @res: resource
diff --git a/lib/resource.h b/lib/resource.h
index 810334c1..06af4289 100644
--- a/lib/resource.h
+++ b/lib/resource.h
@@ -76,6 +76,9 @@ void rp_free(pool *p); /* Free the whole pool */
extern pool root_pool;
+static inline pool *resource_parent(resource *r)
+{ return SKIP_BACK(pool, inside, resource_enlisted(r)); }
+
/* Normal memory blocks */
void *mb_alloc(pool *, unsigned size);
diff --git a/lib/slab.c b/lib/slab.c
index 23316e82..7d2c87e9 100644
--- a/lib/slab.c
+++ b/lib/slab.c
@@ -256,6 +256,7 @@ void *
sl_alloc(slab *s)
{
struct sl_head *h;
+ ASSERT_DIE(DG_IS_LOCKED(resource_parent(&s->r)->domain));
redo:
if (!(h = s->partial_heads.first))
@@ -331,6 +332,7 @@ sl_free(void *oo)
{
struct sl_head *h = SL_GET_HEAD(oo);
struct slab *s = h->slab;
+ ASSERT_DIE(DG_IS_LOCKED(resource_parent(&s->r)->domain));
#ifdef POISON
memset(oo, 0xdb, s->data_size);