From e0a80711f9997c6f7e41cfbf6d4a29f15f313d28 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Sun, 23 Aug 2020 14:29:51 -0400 Subject: [PATCH] chore: Simplify module db add --- runtime/include/module_database.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/runtime/include/module_database.h b/runtime/include/module_database.h index 763f04a..cf12ee4 100644 --- a/runtime/include/module_database.h +++ b/runtime/include/module_database.h @@ -17,19 +17,13 @@ extern int module_database_free_offset; static inline int module_database_add(struct module *module) { - int rc; - - if (module_database_free_offset >= MODULE_MAX_MODULE_COUNT) goto err_no_space; + assert(module_database_free_offset >= 0); + assert(module_database_free_offset <= MODULE_MAX_MODULE_COUNT); - int f = __sync_fetch_and_add(&module_database_free_offset, 1); - if (module_database_free_offset > MODULE_MAX_MODULE_COUNT) { - __sync_fetch_and_sub(&module_database_free_offset, 1); - goto err_no_space; - } + int rc; if (module_database_free_offset == MODULE_MAX_MODULE_COUNT) goto err_no_space; - assert(f < MODULE_MAX_MODULE_COUNT); - module_database[f] = module; + module_database[module_database_free_offset++] = module; rc = 0; done: