From d507a0730dc51ccd03dff1d0d7909bf997d43fad Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Wed, 5 May 2021 07:48:24 -0400 Subject: [PATCH] refactor: module database --- runtime/include/module_database.h | 31 +------------------------------ runtime/src/module_database.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/runtime/include/module_database.h b/runtime/include/module_database.h index e973399..7b61345 100644 --- a/runtime/include/module_database.h +++ b/runtime/include/module_database.h @@ -1,36 +1,7 @@ #pragma once -#include - -#include "panic.h" #include "module.h" +int module_database_add(struct module *module); struct module *module_database_find_by_name(char *name); struct module *module_database_find_by_socket_descriptor(int socket_descriptor); - -extern struct module *module_database[]; -extern size_t module_database_count; - -/** - * Adds a module to the in-memory module DB - * @param module module to add - * @return 0 on success. -ENOSPC when full - */ -static inline int -module_database_add(struct module *module) -{ - assert(module_database_count <= MODULE_MAX_MODULE_COUNT); - - int rc; - - if (module_database_count == MODULE_MAX_MODULE_COUNT) goto err_no_space; - module_database[module_database_count++] = module; - - rc = 0; -done: - return rc; -err_no_space: - panic("Cannot add module. Database is full.\n"); - rc = -ENOSPC; - goto done; -} diff --git a/runtime/src/module_database.c b/runtime/src/module_database.c index fc78d6f..d3daa00 100644 --- a/runtime/src/module_database.c +++ b/runtime/src/module_database.c @@ -1,4 +1,7 @@ +#include + #include "module_database.h" +#include "panic.h" /******************* * Module Database * @@ -7,6 +10,31 @@ struct module *module_database[MODULE_MAX_MODULE_COUNT] = { NULL }; size_t module_database_count = 0; +/** + * Adds a module to the in-memory module DB + * @param module module to add + * @return 0 on success. -ENOSPC when full + */ +int +module_database_add(struct module *module) +{ + assert(module_database_count <= MODULE_MAX_MODULE_COUNT); + + int rc; + + if (module_database_count == MODULE_MAX_MODULE_COUNT) goto err_no_space; + module_database[module_database_count++] = module; + + rc = 0; +done: + return rc; +err_no_space: + panic("Cannot add module. Database is full.\n"); + rc = -ENOSPC; + goto done; +} + + /** * Given a name, find the associated module * @param name