allocate client channel lookup buckets before store

This commit is contained in:
jacob 2025-02-08 10:12:05 -06:00
parent d9ebdc4df2
commit 5f75b765c3
2 changed files with 10 additions and 6 deletions

View File

@ -6,8 +6,6 @@
#define CHANNEL_LOOKUP_BUCKETS 4096 #define CHANNEL_LOOKUP_BUCKETS 4096
/* Offset in bytes from start of store struct to start of clients array (assume adjacently allocated) */ /* Offset in bytes from start of store struct to start of clients array (assume adjacently allocated) */
/* FIXME: Incorrect since buckets are also allocated */
#define STORE_CLIENTS_OFFSET (sizeof(struct sim_client_store) + (sizeof(struct sim_client_store) % alignof(struct sim_client))) #define STORE_CLIENTS_OFFSET (sizeof(struct sim_client_store) + (sizeof(struct sim_client_store) % alignof(struct sim_client)))
@ -22,11 +20,17 @@ READONLY struct sim_client_store _g_sim_client_store_nil = { .valid = false };
struct sim_client_store *client_store_alloc(void) struct sim_client_store *client_store_alloc(void)
{ {
struct arena arena = arena_alloc(GIGABYTE(64)); struct arena arena = arena_alloc(GIGABYTE(64));
u64 num_channel_lookup_buckets = CHANNEL_LOOKUP_BUCKETS;
u64 channel_lookup_buckets = arena_push_array_zero(&arena, struct channel_lookup_bucket, num_channel_lookup_buckets);
struct sim_client_store *store = arena_push_zero(&arena, struct sim_client_store); struct sim_client_store *store = arena_push_zero(&arena, struct sim_client_store);
store->arena = arena;
store->num_channel_lookup_buckets = CHANNEL_LOOKUP_BUCKETS;
store->channel_lookup_buckets = arena_push_array_zero(&arena, struct channel_lookup_bucket, store->num_channel_lookup_buckets);
store->clients = arena_dry_push(&arena, struct sim_client); store->clients = arena_dry_push(&arena, struct sim_client);
ASSERT((u8 *)store->clients - (u8 *)store == STORE_CLIENTS_OFFSET); /* Offset must be correct */
store->arena = arena;
store->num_channel_lookup_buckets = num_channel_lookup_buckets;
store->channel_lookup_buckets = channel_lookup_buckets;
return store; return store;
} }

View File

@ -44,7 +44,7 @@ struct sim_ent_store *sim_ent_store_alloc(void)
store->valid = true; store->valid = true;
store->arena = arena; store->arena = arena;
store->entities = arena_dry_push(&arena, struct sim_ent); store->entities = arena_dry_push(&arena, struct sim_ent);
ASSERT((u64)store->entities - (u64)store == STORE_ENTITIES_OFFSET); /* Offset must be correct */ ASSERT((u8 *)store->entities - (u8 *)store == STORE_ENTITIES_OFFSET); /* Offset must be correct */
store_make_root(store); store_make_root(store);
return store; return store;
} }