diff options
author | Maria Matejka <mq@ucw.cz> | 2023-04-24 16:10:59 +0200 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2023-04-25 09:52:28 +0200 |
commit | ce7495b49a5192b1cba17fd88cdb2495a40824e2 (patch) | |
tree | 005901ea2c816483fd1e195a066b0685f8c4d7b9 /sysdep | |
parent | 19e79eb8adddb6194248974443b9a906f66984ce (diff) |
Refactoring of domains connected to pools
Diffstat (limited to 'sysdep')
-rw-r--r-- | sysdep/unix/alloc.c | 3 | ||||
-rw-r--r-- | sysdep/unix/domain.c | 17 | ||||
-rw-r--r-- | sysdep/unix/io-loop.c | 7 | ||||
-rw-r--r-- | sysdep/unix/io.c | 19 |
4 files changed, 34 insertions, 12 deletions
diff --git a/sysdep/unix/alloc.c b/sysdep/unix/alloc.c index cafcc8dd..1b951da2 100644 --- a/sysdep/unix/alloc.c +++ b/sysdep/unix/alloc.c @@ -318,7 +318,8 @@ resource_sys_init(void) /* We assume that page size has only one bit and is between 1K and 256K (incl.). * Otherwise, the assumptions in lib/slab.c (sl_head's num_full range) aren't met. */ - empty_pages_domain = DOMAIN_NEW(resource, "Empty Pages"); + empty_pages_domain = DOMAIN_NEW(resource); + DOMAIN_SETUP(resource, empty_pages_domain, "Empty Pages", NULL); initialized = 1; return; } diff --git a/sysdep/unix/domain.c b/sysdep/unix/domain.c index f4ee595d..c04e91ea 100644 --- a/sysdep/unix/domain.c +++ b/sysdep/unix/domain.c @@ -46,20 +46,21 @@ struct domain_generic { struct domain_generic **prev; struct lock_order *locked_by; const char *name; + pool *pool; }; -#define DOMAIN_INIT(_name, _order) { .mutex = PTHREAD_MUTEX_INITIALIZER, .name = _name, .order = _order } +#define DOMAIN_INIT(_order) { .mutex = PTHREAD_MUTEX_INITIALIZER, .order = _order } -static struct domain_generic the_bird_domain_gen = DOMAIN_INIT("The BIRD", OFFSETOF(struct lock_order, the_bird)); +static struct domain_generic the_bird_domain_gen = DOMAIN_INIT(OFFSETOF(struct lock_order, the_bird)); DOMAIN(the_bird) the_bird_domain = { .the_bird = &the_bird_domain_gen }; struct domain_generic * -domain_new(const char *name, uint order) +domain_new(uint order) { ASSERT_DIE(order < sizeof(struct lock_order)); struct domain_generic *dg = xmalloc(sizeof(struct domain_generic)); - *dg = (struct domain_generic) DOMAIN_INIT(name, order); + *dg = (struct domain_generic) DOMAIN_INIT(order); return dg; } @@ -81,6 +82,14 @@ uint dg_order(struct domain_generic *dg) return dg->order; } +void +domain_setup(struct domain_generic *dg, const char *name, pool *p) +{ + ASSERT_DIE(dg->pool == NULL); + dg->pool = p; + dg->name = name; +} + void do_lock(struct domain_generic *dg, struct domain_generic **lsp) { struct lock_order stack_copy; diff --git a/sysdep/unix/io-loop.c b/sysdep/unix/io-loop.c index daa86560..1a3333ef 100644 --- a/sysdep/unix/io-loop.c +++ b/sysdep/unix/io-loop.c @@ -1029,7 +1029,7 @@ bird_thread_show_finish(void *data) void cmd_show_threads(int show_loops) { - DOMAIN(control) lock = DOMAIN_NEW(control, "Show Threads"); + DOMAIN(control) lock = DOMAIN_NEW(control); LOCK_DOMAIN(control, lock); pool *p = rp_new(&root_pool, lock.control, "Show Threads"); @@ -1084,7 +1084,8 @@ birdloop_init(void) { struct birdloop_pickup_group *group = &pickup_groups[i]; - group->domain = DOMAIN_NEW(resource, "Loop Pickup"); + group->domain = DOMAIN_NEW(resource); + DOMAIN_SETUP(resource, group->domain, "Loop Pickup", NULL); init_list(&group->loops); init_list(&group->threads); } @@ -1217,7 +1218,7 @@ birdloop_run_timer(timer *tm) static struct birdloop * birdloop_vnew_internal(pool *pp, uint order, struct birdloop_pickup_group *group, const char *name, va_list args) { - struct domain_generic *dg = domain_new(name, order); + struct domain_generic *dg = domain_new(order); DG_LOCK(dg); pool *p = rp_vnewf(pp, dg, name, args); diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 40a6f114..b21df057 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -1052,6 +1052,10 @@ sk_passive_connected(sock *s, int type) return 0; } + struct domain_generic *sock_lock = DG_IS_LOCKED(s->pool->domain) ? NULL : s->pool->domain; + if (sock_lock) + DG_LOCK(sock_lock); + sock *t = sk_new(s->pool); t->type = type; t->data = s->data; @@ -1082,13 +1086,20 @@ sk_passive_connected(sock *s, int type) close(t->fd); t->fd = -1; sk_close(t); - return 1; + t = NULL; + } + else + { + birdloop_add_socket(s->loop, t); + sk_alloc_bufs(t); } - birdloop_add_socket(s->loop, t); + if (sock_lock) + DG_UNLOCK(sock_lock); + + if (t) + s->rx_hook(t, 0); - sk_alloc_bufs(t); - s->rx_hook(t, 0); return 1; } |