From 11948e47ac812b6f6673730684400c2bc3d62e63 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 13 Sep 2018 18:02:10 -0700 Subject: [PATCH] ircd: Move m::import to mods::import where it is more appropriate. --- construct/construct.cc | 2 +- include/ircd/m/import.h | 103 ------------------------ include/ircd/m/m.h | 1 - include/ircd/mods/import.h | 94 ++++++++++++++++++++-- include/ircd/mods/mods.h | 1 + ircd/m/event.cc | 10 +-- ircd/m/m.cc | 158 ++++++++++++++++--------------------- ircd/m/room.cc | 2 +- ircd/mods.cc | 9 +++ ircd/resource.cc | 7 ++ modules/console.cc | 74 ++++++++--------- modules/m_room.cc | 2 +- modules/m_room_member.cc | 2 +- modules/s_control.cc | 4 +- modules/vm.cc | 4 +- 15 files changed, 225 insertions(+), 248 deletions(-) delete mode 100644 include/ircd/m/import.h diff --git a/construct/construct.cc b/construct/construct.cc index 22dd2bf5c..680916111 100644 --- a/construct/construct.cc +++ b/construct/construct.cc @@ -358,7 +358,7 @@ try // function does a lot of IO so it requires an ircd::ctx. ircd::context{[] { - ircd::m::import reload_conf + ircd::mods::import reload_conf { "s_conf", "reload_conf" }; diff --git a/include/ircd/m/import.h b/include/ircd/m/import.h deleted file mode 100644 index 36566c5a6..000000000 --- a/include/ircd/m/import.h +++ /dev/null @@ -1,103 +0,0 @@ -// Matrix Construct -// -// Copyright (C) Matrix Construct Developers, Authors & Contributors -// Copyright (C) 2016-2018 Jason Volk -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice is present in all copies. The -// full license for this software is available in the LICENSE file. - -#pragma once -#define HAVE_IRCD_M_IMPORT_H - -namespace ircd::m -{ - template struct import; - struct imports extern imports; -} - -struct ircd::m::imports -:std::map> -{ - void init(); -}; - -template -struct ircd::m::import -:mods::import -{ - std::string modname; - std::string symname; - - void reload(); - - public: - template auto operator()(args&&... a); - prototype *operator->(); - prototype &operator*(); - operator prototype &(); - - import(std::string modname, std::string symname); -}; - -template -ircd::m::import::import(std::string modname, - std::string symname) -:mods::import{} -,modname{std::move(modname)} -,symname{std::move(symname)} -{} - -template -ircd::m::import::operator -prototype &() -{ - return this->operator*(); -} - -template -prototype & -ircd::m::import::operator*() -{ - return *this->operator->(); -} - -template -prototype * -ircd::m::import::operator->() -{ - if(unlikely(!*this)) - reload(); - - return mods::import::operator->(); -} - -template -template -auto -ircd::m::import::operator()(args&&... a) -{ - if(unlikely(!*this)) - reload(); - - return mods::import::operator()(std::forward(a)...); -} - -template -void -ircd::m::import::reload() -try -{ - auto &import(static_cast &>(*this)); - import = { imports.at(modname), symname }; -} -catch(const std::out_of_range &e) -{ - throw m::UNAVAILABLE - { - "Sorry, %s in %s is currently unavailable.", - symname, - modname - }; -} diff --git a/include/ircd/m/m.h b/include/ircd/m/m.h index 1a25da670..c3244d33c 100644 --- a/include/ircd/m/m.h +++ b/include/ircd/m/m.h @@ -30,7 +30,6 @@ namespace ircd::m::vm #include "name.h" #include "error.h" -#include "import.h" #include "self.h" #include "id.h" #include "event.h" diff --git a/include/ircd/mods/import.h b/include/ircd/mods/import.h index 00f19b2ce..9ad8ac564 100644 --- a/include/ircd/mods/import.h +++ b/include/ircd/mods/import.h @@ -14,14 +14,25 @@ namespace ircd::mods { template struct import; + struct imports extern imports; } +struct ircd::mods::imports +:std::map> +{}; + /// Representation of a symbol in a loaded shared library /// template struct ircd::mods::import :sym_ptr { + std::string module_name; + std::string symbol_name; + + void reload(); + + public: template auto operator()(args&&... a) const; template auto operator()(args&&... a); @@ -33,26 +44,67 @@ struct ircd::mods::import T &operator*(); operator T &(); - using sym_ptr::sym_ptr; + explicit import(const mods::module &, std::string symbol_name); + import(std::string module_name, std::string symbol_name); }; template -ircd::mods::import::operator T &() +ircd::mods::import::import(std::string module_name, + std::string symbol_name) +:sym_ptr { - return sym_ptr::operator*(); + // Note sym_ptr is purposely default constructed; this makes the import + // "lazy" and will be loaded via miss on first use. This is useful in + // the general use-case of static construction. +} +,module_name +{ + std::move(module_name) +} +,symbol_name +{ + std::move(symbol_name) +} +{} + +template +ircd::mods::import::import(const mods::module &module, + std::string symbol_name) +:sym_ptr +{ + module, symbol_name +} +,module_name +{ + module.name() +} +,symbol_name +{ + std::move(symbol_name) +} +{} + +template +ircd::mods::import::operator +T &() +{ + return this->operator*(); } template T & ircd::mods::import::operator*() { - return sym_ptr::operator*(); + return *this->operator->(); } template T * ircd::mods::import::operator->() { + if(unlikely(!*this)) + reload(); + return sym_ptr::operator->(); } @@ -61,7 +113,7 @@ ircd::mods::import::operator const T &() const { - return sym_ptr::operator*(); + return this->operator*(); } template @@ -69,7 +121,7 @@ const T & ircd::mods::import::operator*() const { - return sym_ptr::operator*(); + return this->operator->(); } template @@ -85,6 +137,9 @@ template auto ircd::mods::import::operator()(args&&... a) { + if(unlikely(!*this)) + reload(); + return sym_ptr::operator()(std::forward(a)...); } @@ -96,3 +151,30 @@ const { return sym_ptr::operator()(std::forward(a)...); } + +template +void +ircd::mods::import::reload() +try +{ + auto &module + { + imports.at(module_name) + }; + + auto &sp + { + static_cast(*this) + }; + + sp = { module, symbol_name }; +} +catch(const std::out_of_range &e) +{ + throw unavailable + { + "Sorry, %s in %s is currently unavailable.", + symbol_name, + module_name + }; +} diff --git a/include/ircd/mods/mods.h b/include/ircd/mods/mods.h index 7859ac4b0..1a3a6f8e2 100644 --- a/include/ircd/mods/mods.h +++ b/include/ircd/mods/mods.h @@ -21,6 +21,7 @@ namespace ircd::mods IRCD_EXCEPTION(error, invalid_export) IRCD_EXCEPTION(error, expired_symbol) IRCD_EXCEPTION(error, undefined_symbol) + IRCD_EXCEPTION(expired_symbol, unavailable) string_view name(const mod &); string_view path(const mod &); diff --git a/ircd/m/event.cc b/ircd/m/event.cc index c97628aed..f5096261f 100644 --- a/ircd/m/event.cc +++ b/ircd/m/event.cc @@ -24,7 +24,7 @@ ircd::m::pretty(std::ostream &s, const event &e) { using prototype = void (std::ostream &, const event &); - static import pretty + thread_local mods::import pretty { "m_event", "pretty__event" }; @@ -51,7 +51,7 @@ ircd::m::pretty_oneline(std::ostream &s, const bool &content_keys) { using prototype = void (std::ostream &, const event &, const bool &); - static import pretty_oneline + thread_local mods::import pretty_oneline { "m_event", "pretty_oneline__event" }; @@ -76,7 +76,7 @@ ircd::m::pretty_msgline(std::ostream &s, const event &e) { using prototype = void (std::ostream &, const event &); - static import pretty_msgline + thread_local mods::import pretty_msgline { "m_event", "pretty_msgline__event" }; @@ -101,7 +101,7 @@ ircd::m::pretty(std::ostream &s, const event::prev &prev) { using prototype = void (std::ostream &, const event &); - static import pretty + thread_local mods::import pretty { "m_event", "pretty__prev" }; @@ -126,7 +126,7 @@ ircd::m::pretty_oneline(std::ostream &s, const event::prev &prev) { using prototype = void (std::ostream &, const event::prev &); - static import pretty_oneline + thread_local mods::import pretty_oneline { "m_event", "pretty_oneline__prev" }; diff --git a/ircd/m/m.cc b/ircd/m/m.cc index 4379ac478..29c5aae0b 100644 --- a/ircd/m/m.cc +++ b/ircd/m/m.cc @@ -53,8 +53,6 @@ catch(const m::error &e) { log, "%s %s", e.what(), e.content }; - - assert(m::imports.empty()); } catch(const std::exception &e) { @@ -62,8 +60,6 @@ catch(const std::exception &e) { log, "%s", e.what() }; - - assert(m::imports.empty()); } ircd::m::init::~init() @@ -72,7 +68,7 @@ noexcept try if(!std::current_exception()) presence::set(me, "offline", me_offline_status_msg); - m::imports.clear(); + mods::imports.clear(); } catch(const m::error &e) { @@ -87,20 +83,20 @@ catch(const m::error &e) void ircd::m::init::close() { - m::imports.erase("s_listen"s); + mods::imports.erase("s_listen"s); } void ircd::m::init::init_keys() try { - m::imports.emplace("s_keys"s, "s_keys"s); + mods::imports.emplace("s_keys"s, "s_keys"s); const unwind::exceptional uw{[] { - m::imports.erase("s_keys"s); + mods::imports.erase("s_keys"s); }}; - m::import init_my_keys + mods::import init_my_keys { "s_keys", "init_my_keys" }; @@ -132,14 +128,33 @@ try return; } - m::imports.init(); + // Manually load first modules + mods::imports.emplace("vm"s, "vm"s); + mods::imports.emplace("vm_fetch"s, "vm_fetch"s); + + // The order of these prefixes will be the loading order. Order of + // specific modules within a prefix is not determined here. + static const string_view prefixes[] + { + "s_", "m_", "key_", "media_", "client_", "federation_" + }; + + // Load modules by prefix. + for(const auto &prefix : prefixes) + for(const auto &name : mods::available()) + if(startswith(name, prefix)) + mods::imports.emplace(name, name); + + // Manually load last modules + mods::imports.emplace("webroot"s, "webroot"s); + if(db::sequence(*dbs::events) == 0) bootstrap(); } catch(const std::exception &e) { const ctx::exception_handler eh; - m::imports.clear(); + mods::imports.clear(); throw m::error { "M_INIT_ERROR", "%s", e.what() @@ -148,7 +163,7 @@ catch(const std::exception &e) catch(const ctx::terminated &) { const ctx::exception_handler eh; - m::imports.clear(); + mods::imports.clear(); throw ctx::terminated{}; } @@ -370,7 +385,7 @@ ircd::m::feds::state::state(const m::room::id &room_id, const milliseconds &, const std::function &); - static m::import feds__state + thread_local mods::import feds__state { "federation_federation", "feds__state" }; @@ -614,7 +629,7 @@ ircd::m::vm::eval::operator()(const room &room, { using prototype = fault (eval &, const m::room &, json::iov &, const json::iov &); - static import function + thread_local mods::import function { "vm", "eval__commit_room" }; @@ -630,7 +645,7 @@ ircd::m::vm::eval::operator()(json::iov &event, { using prototype = fault (eval &, json::iov &, const json::iov &); - static import function + thread_local mods::import function { "vm", "eval__commit" }; @@ -644,7 +659,7 @@ try { using prototype = fault (eval &, const m::event &); - static import function + thread_local mods::import function { "vm", "eval__event" }; @@ -738,7 +753,7 @@ ircd::m::verify(const m::keys &keys) { using prototype = bool (const m::keys &) noexcept; - static import function + thread_local mods::import function { "s_keys", "verify__keys" }; @@ -764,7 +779,7 @@ ircd::m::keys::get(const string_view &server_name, { using prototype = void (const string_view &, const string_view &, const closure &); - static import function + thread_local mods::import function { "s_keys", "get__keys" }; @@ -779,7 +794,7 @@ ircd::m::keys::query(const string_view &query_server, { using prototype = bool (const string_view &, const queries &, const closure_bool &); - static import function + thread_local mods::import function { "s_keys", "query__keys" }; @@ -816,7 +831,7 @@ ircd::m::visible(const event &event, { using prototype = bool (const m::event &, const string_view &); - static import function + thread_local mods::import function { "m_room_history_visibility", "visible" }; @@ -845,7 +860,7 @@ ircd::m::receipt::read(const id::room &room_id, { using prototype = event::id::buf (const id::room &, const id::user &, const id::event &, const time_t &); - static import function + thread_local mods::import function { "client_rooms", "commit__m_receipt_m_read" }; @@ -876,7 +891,7 @@ ircd::m::receipt::read(const id::room &room_id, { using prototype = bool (const id::room &, const id::user &, const id::event::closure &); - static import function + thread_local mods::import function { "m_receipt", "last_receipt__event_id" }; @@ -894,7 +909,7 @@ ircd::m::typing::set(const m::typing &object) { using prototype = event::id::buf (const m::typing &); - static import function + thread_local mods::import function { "client_rooms", "commit__m_typing" }; @@ -934,7 +949,7 @@ ircd::m::presence::set(const presence &object) { using prototype = event::id::buf (const presence &); - static import function + thread_local mods::import function { "m_presence", "commit__m_presence" }; @@ -998,7 +1013,7 @@ ircd::m::presence::get(std::nothrow_t, { using prototype = bool (std::nothrow_t, const m::user &, const event_closure &); - static import function + thread_local mods::import function { "m_presence", "get__m_presence" }; @@ -1011,7 +1026,7 @@ ircd::m::presence::valid_state(const string_view &state) { using prototype = bool (const string_view &); - static import function + thread_local mods::import function { "m_presence", "presence_valid_state" }; @@ -1047,7 +1062,7 @@ ircd::m::create(const id::node &node_id, { using prototype = node (const id::node &, const json::members &); - static import function + thread_local mods::import function { "s_node", "create_node" }; @@ -1061,7 +1076,7 @@ ircd::m::exists(const node::id &node_id) { using prototype = bool (const node::id &); - static import function + thread_local mods::import function { "s_node", "exists__nodeid" }; @@ -1598,7 +1613,7 @@ ircd::m::create(const id::user &user_id, { using prototype = user (const id::user &, const json::members &); - static import function + thread_local mods::import function { "client_user", "user_create" }; @@ -1677,7 +1692,7 @@ ircd::m::user::activate() { using prototype = event::id::buf (const m::user &); - static import function + thread_local mods::import function { "client_account", "activate__user" }; @@ -1690,7 +1705,7 @@ ircd::m::user::deactivate() { using prototype = event::id::buf (const m::user &); - static import function + thread_local mods::import function { "client_account", "deactivate__user" }; @@ -1704,7 +1719,7 @@ const { using prototype = bool (const m::user &); - static import function + thread_local mods::import function { "client_account", "is_active__user" }; @@ -1718,7 +1733,7 @@ ircd::m::user::filter(const json::object &filter, { using prototype = event::id::buf (const m::user &, const json::object &, const mutable_buffer &); - static import function + thread_local mods::import function { "client_user", "filter_set" }; @@ -1775,7 +1790,7 @@ const { using prototype = bool (std::nothrow_t, const m::user &, const string_view &, const filter_closure &); - static import function + thread_local mods::import function { "client_user", "filter_get" }; @@ -1791,7 +1806,7 @@ ircd::m::user::account_data(const m::room &room, { using prototype = event::id::buf (const m::user &, const m::room &, const m::user &, const string_view &, const json::object &); - static import function + thread_local mods::import function { "client_user", "room_account_data_set" }; @@ -1806,7 +1821,7 @@ ircd::m::user::account_data(const m::user &sender, { using prototype = event::id::buf (const m::user &, const m::user &, const string_view &, const json::object &); - static import function + thread_local mods::import function { "client_user", "account_data_set" }; @@ -1882,7 +1897,7 @@ const { using prototype = void (const m::user &, const m::room &, const string_view &, const account_data_closure &); - static import function + thread_local mods::import function { "client_user", "room_account_data_get" }; @@ -1897,7 +1912,7 @@ const { using prototype = void (const m::user &, const string_view &, const account_data_closure &); - static import function + thread_local mods::import function { "client_user", "account_data_get" }; @@ -1911,7 +1926,7 @@ ircd::m::user::_account_data_type(const mutable_buffer &out, { using prototype = string_view (const mutable_buffer &, const m::room::id &); - static import function + thread_local mods::import function { "client_user", "room_account_data_type" }; @@ -1926,7 +1941,7 @@ ircd::m::user::profile(const m::user &sender, { using prototype = event::id::buf (const m::user &, const m::user &, const string_view &, const string_view &); - static import function + thread_local mods::import function { "client_profile", "profile_set" }; @@ -1970,7 +1985,7 @@ const { using prototype = void (const m::user &, const string_view &, const profile_closure &); - static import function + thread_local mods::import function { "client_profile", "profile_get" }; @@ -1983,7 +1998,7 @@ ircd::m::user::password(const string_view &password) { using prototype = event::id::buf (const m::user::id &, const string_view &) noexcept; - static import function + thread_local mods::import function { "client_account", "set_password" }; @@ -1997,7 +2012,7 @@ const noexcept try { using prototype = bool (const m::user::id &, const string_view &) noexcept; - static import function + thread_local mods::import function { "client_account", "is_password" }; @@ -2473,7 +2488,7 @@ ircd::m::create(const id::room &room_id, { using prototype = room (const id::room &, const id::user &, const string_view &); - static import function + thread_local mods::import function { "client_createroom", "createroom__type" }; @@ -2489,7 +2504,7 @@ ircd::m::create(const id::room &room_id, { using prototype = room (const id::room &, const id::user &, const id::room &, const string_view &); - static import function + thread_local mods::import function { "client_createroom", "createroom__parent_type" }; @@ -2503,7 +2518,7 @@ ircd::m::join(const id::room_alias &room_alias, { using prototype = event::id::buf (const id::room_alias &, const id::user &); - static import function + thread_local mods::import function { "client_rooms", "join__alias_user" }; @@ -2517,7 +2532,7 @@ ircd::m::join(const room &room, { using prototype = event::id::buf (const m::room &, const id::user &); - static import function + thread_local mods::import function { "client_rooms", "join__room_user" }; @@ -2531,7 +2546,7 @@ ircd::m::leave(const room &room, { using prototype = event::id::buf (const m::room &, const id::user &); - static import function + thread_local mods::import function { "client_rooms", "leave__room_user" }; @@ -2546,7 +2561,7 @@ ircd::m::invite(const room &room, { using prototype = event::id::buf (const m::room &, const id::user &, const id::user &); - static import function + thread_local mods::import function { "client_rooms", "invite__room_user" }; @@ -2562,7 +2577,7 @@ ircd::m::redact(const room &room, { using prototype = event::id::buf (const m::room &, const id::user &, const id::event &, const string_view &); - static import function + thread_local mods::import function { "client_rooms", "redact__" }; @@ -2655,7 +2670,7 @@ ircd::m::send(const room &room, { using prototype = event::id::buf (const m::room &, const id::user &, const string_view &, const string_view &, const json::iov &); - static import function + thread_local mods::import function { "client_rooms", "state__iov" }; @@ -2693,7 +2708,7 @@ ircd::m::send(const room &room, { using prototype = event::id::buf (const m::room &, const id::user &, const string_view &, const json::iov &); - static import function + thread_local mods::import function { "client_rooms", "send__iov" }; @@ -2771,7 +2786,7 @@ ircd::m::count_since(const room &r, const event::idx &, const event::idx &); - static m::import _count_since + thread_local mods::import _count_since { "m_room", "count_since" }; @@ -2815,7 +2830,7 @@ ircd::m::room_id(const mutable_buffer &out, { using prototype = id::room (const mutable_buffer &, const id::room_alias &); - static import function + thread_local mods::import function { "client_directory_room", "room_id__room_alias" }; @@ -2829,7 +2844,7 @@ ircd::m::exists(const id::room_alias &room_alias, { using prototype = bool (const id::room_alias, const bool &); - static import function + thread_local mods::import function { "client_directory_room", "room_alias_exists" }; @@ -3540,39 +3555,6 @@ ircd::m::_hook_match(const m::event &matching, return true; } -/////////////////////////////////////////////////////////////////////////////// -// -// m/import.h -// - -decltype(ircd::m::imports) -ircd::m::imports -{}; - -void -ircd::m::imports::init() -{ - // Manually load first modules - this->emplace("vm"s, "vm"s); - this->emplace("vm_fetch"s, "vm_fetch"s); - - // The order of these prefixes will be the loading order. Order of - // specific modules within a prefix is not determined here. - static const string_view prefixes[] - { - "s_", "m_", "key_", "media_", "client_", "federation_" - }; - - // Load modules by prefix. - for(const auto &prefix : prefixes) - for(const auto &name : mods::available()) - if(startswith(name, prefix)) - this->emplace(name, name); - - // Manually load last modules - this->emplace("webroot"s, "webroot"s); -} - /////////////////////////////////////////////////////////////////////////////// // // m/error.h diff --git a/ircd/m/room.cc b/ircd/m/room.cc index 5566aac4d..39dfa537d 100644 --- a/ircd/m/room.cc +++ b/ircd/m/room.cc @@ -1797,7 +1797,7 @@ const const m::room::origins::closure &, const m::room::origins::closure_bool &); - static m::import random_origin + thread_local mods::import random_origin { "m_room", "random_origin" }; diff --git a/ircd/mods.cc b/ircd/mods.cc index ff637c360..2ba2e624c 100644 --- a/ircd/mods.cc +++ b/ircd/mods.cc @@ -197,6 +197,15 @@ ircd::mods::loaded(const string_view &name) return mod::loaded.count(name); } +/////////////////////////////////////////////////////////////////////////////// +// +// mods/import.h +// + +decltype(ircd::mods::imports) +ircd::mods::imports +{}; + /////////////////////////////////////////////////////////////////////////////// // // mods/sym_ptr.h diff --git a/ircd/resource.cc b/ircd/resource.cc index e0b92321b..b74b4d5fe 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -508,6 +508,13 @@ catch(const json::error &e) http::BAD_REQUEST, "M_NOT_JSON", "%s", e.what() }; } +catch(const mods::unavailable &e) +{ + throw m::UNAVAILABLE + { + "%s", e.what() + }; +} catch(const std::out_of_range &e) { throw m::error diff --git a/modules/console.cc b/modules/console.cc index 27a67a9e7..a23218140 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -599,7 +599,7 @@ console_cmd__conf__set(opt &out, const string_view &line) const string_view &key, const string_view &val); - static m::import set_conf_item + thread_local mods::import set_conf_item { "s_conf", "set_conf_item" }; @@ -649,7 +649,7 @@ bool console_cmd__conf__rehash(opt &out, const string_view &line) { using prototype = void (const bool &); - static m::import rehash_conf + thread_local mods::import rehash_conf { "s_conf", "rehash_conf" }; @@ -666,7 +666,7 @@ bool console_cmd__conf__reload(opt &out, const string_view &line) { using prototype = void (); - static m::import reload_conf + thread_local mods::import reload_conf { "s_conf", "reload_conf" }; @@ -683,7 +683,7 @@ bool console_cmd__conf__reset(opt &out, const string_view &line) { using prototype = void (); - static m::import refresh_conf + thread_local mods::import refresh_conf { "s_conf", "refresh_conf" }; @@ -794,7 +794,7 @@ console_cmd__mod__reload(opt &out, const string_view &line) for(auto it(names.begin()); it != names.end(); ++it) { const auto &name{*it}; - if(m::imports.erase(std::string{name})) + if(mods::imports.erase(std::string{name})) out << name << " unloaded." << std::endl; else out << name << " is not loaded." << std::endl; @@ -803,7 +803,7 @@ console_cmd__mod__reload(opt &out, const string_view &line) for(auto it(names.rbegin()); it != names.rend(); ++it) { const auto &name{*it}; - if(m::imports.emplace(std::string{name}, name).second) + if(mods::imports.emplace(std::string{name}, name).second) out << name << " loaded." << std::endl; else out << name << " is already loaded." << std::endl; @@ -818,13 +818,13 @@ console_cmd__mod__load(opt &out, const string_view &line) tokens(line, ' ', [&out] (const string_view &name) { - if(m::imports.find(name) != end(m::imports)) + if(mods::imports.find(name) != end(mods::imports)) { out << name << " is already loaded." << std::endl; return; } - m::imports.emplace(std::string{name}, name); + mods::imports.emplace(std::string{name}, name); out << name << " loaded." << std::endl; }); @@ -837,7 +837,7 @@ console_cmd__mod__unload(opt &out, const string_view &line) tokens(line, ' ', [&out] (const string_view &name) { - if(!m::imports.erase(std::string{name})) + if(!mods::imports.erase(std::string{name})) { out << name << " is not loaded." << std::endl; return; @@ -2745,7 +2745,7 @@ console_cmd__net__listen__list(opt &out, const string_view &line) { using list = std::list; - static m::import listeners + thread_local mods::import listeners { "s_listen", "listeners" }; @@ -2803,7 +2803,7 @@ console_cmd__net__listen__load(opt &out, const string_view &line) { using prototype = bool (const string_view &); - static m::import load_listener + thread_local mods::import load_listener { "s_listen", "load_listener" }; @@ -2826,7 +2826,7 @@ console_cmd__net__listen__unload(opt &out, const string_view &line) { using prototype = bool (const string_view &); - static m::import unload_listener + thread_local mods::import unload_listener { "s_listen", "unload_listener" }; @@ -3007,7 +3007,7 @@ bool console_cmd__key__crt__sign(opt &out, const string_view &line) { using prototype = void (const m::event &); - static m::import create_my_key + thread_local mods::import create_my_key { "s_keys", "create_my_key" }; @@ -3168,7 +3168,7 @@ console_cmd__stage__make_prev(opt &out, const string_view &line) const mutable_buffer &, const size_t &, const bool &); - static m::import make_prev__buf + thread_local mods::import make_prev__buf { "m_room", "make_prev__buf" }; @@ -3216,7 +3216,7 @@ console_cmd__stage__make_auth(opt &out, const string_view &line) const vector_view &, const string_view &); - static m::import make_auth__buf + thread_local mods::import make_auth__buf { "m_room", "make_auth__buf" }; @@ -3993,7 +3993,7 @@ console_cmd__event__fetch(opt &out, const string_view &line) const m::event::id &, const mutable_buffer &); - static m::import acquire + thread_local mods::import acquire { "vm_fetch", "acquire" }; @@ -4523,7 +4523,7 @@ console_cmd__room__head__rebuild(opt &out, const string_view &line) }; using prototype = size_t (const m::room &); - static m::import head__rebuild + thread_local mods::import head__rebuild { "m_room", "head__rebuild" }; @@ -4551,7 +4551,7 @@ console_cmd__room__head__add(opt &out, const string_view &line) }; using prototype = void (const m::event::id &, const db::op &, const bool &); - static m::import head__modify + thread_local mods::import head__modify { "m_room", "head__modify" }; @@ -4575,7 +4575,7 @@ console_cmd__room__head__del(opt &out, const string_view &line) }; using prototype = void (const m::event::id &, const db::op &, const bool &); - static m::import head__modify + thread_local mods::import head__modify { "m_room", "head__modify" }; @@ -4604,7 +4604,7 @@ console_cmd__room__herd(opt &out, const string_view &line) }; using prototype = void (const m::room &, const m::user &, const milliseconds &); - static m::import room_herd + thread_local mods::import room_herd { "m_room", "room_herd" }; @@ -4633,7 +4633,7 @@ console_cmd__room__head__reset(opt &out, const string_view &line) }; using prototype = size_t (const m::room &); - static m::import head__reset + thread_local mods::import head__reset { "m_room", "head__reset" }; @@ -4666,7 +4666,7 @@ console_cmd__room__complete(opt &out, const string_view &line) }; using prototype = std::pair (const m::room &); - static m::import is_complete + thread_local mods::import is_complete { "m_room", "is_complete" }; @@ -5141,7 +5141,7 @@ console_cmd__room__state__force(opt &out, const string_view &line) }; using prototype = bool (const m::event &); - static m::import state__force_present + thread_local mods::import state__force_present { "m_room", "state__force_present" }; @@ -5174,7 +5174,7 @@ console_cmd__room__state__rebuild__present(opt &out, const string_view &line) }; using prototype = size_t (const m::room &); - static m::import state__rebuild_present + thread_local mods::import state__rebuild_present { "m_room", "state__rebuild_present" }; @@ -5207,7 +5207,7 @@ console_cmd__room__state__rebuild__history(opt &out, const string_view &line) }; using prototype = size_t (const m::room &); - static m::import state__rebuild_history + thread_local mods::import state__rebuild_history { "m_room", "state__rebuild_history" }; @@ -5731,7 +5731,7 @@ console_cmd__room__purge(opt &out, const string_view &line) }; using prototype = size_t (const m::room &); - static m::import purge + thread_local mods::import purge { "m_room", "purge" }; @@ -5764,7 +5764,7 @@ console_cmd__room__dagree(opt &out, const string_view &line) }; using prototype = size_t (const m::room &, std::vector &); - static m::import dagree_histogram + thread_local mods::import dagree_histogram { "m_room", "dagree_histogram" }; @@ -5824,7 +5824,7 @@ console_cmd__user__register(opt &out, const string_view &line) const client *const &, const bool &); - static m::import register_user + thread_local mods::import register_user { "client_register", "register_user" }; @@ -6385,7 +6385,7 @@ console_cmd__feds__version(opt &out, const string_view &line) const milliseconds &, const std::function &); - static m::import feds__version + thread_local mods::import feds__version { "federation_federation", "feds__version" }; @@ -6499,7 +6499,7 @@ console_cmd__feds__event(opt &out, const string_view &line) using prototype = void (const m::event::id &, std::ostream &); - static m::import feds__event + thread_local mods::import feds__event { "federation_federation", "feds__event" }; @@ -6535,7 +6535,7 @@ console_cmd__feds__head(opt &out, const string_view &line) const milliseconds &, const std::function &); - static m::import feds__head + thread_local mods::import feds__head { "federation_federation", "feds__head" }; @@ -6596,7 +6596,7 @@ console_cmd__feds__auth(opt &out, const string_view &line) const milliseconds &, const std::function &); - static m::import feds__head + thread_local mods::import feds__head { "federation_federation", "feds__head" }; @@ -6656,7 +6656,7 @@ console_cmd__feds__heads(opt &out, const string_view &line) const milliseconds &, const std::function &); - static m::import feds__head + thread_local mods::import feds__head { "federation_federation", "feds__head" }; @@ -6743,7 +6743,7 @@ console_cmd__feds__perspective(opt &out, const string_view &line) const milliseconds &, const std::function &); - static m::import feds__perspective + thread_local mods::import feds__perspective { "federation_federation", "feds__perspective" }; @@ -6799,7 +6799,7 @@ console_cmd__feds__backfill(opt &out, const string_view &line) const size_t &, std::ostream &); - static m::import feds__backfill + thread_local mods::import feds__backfill { "federation_federation", "feds__backfill" }; @@ -8067,7 +8067,7 @@ console_cmd__file__room(opt &out, const string_view &line) const string_view &server, const string_view &file); - static m::import file_room_id + thread_local mods::import file_room_id { "media_media", "file_room_id" }; @@ -8115,7 +8115,7 @@ console_cmd__file__download(opt &out, const string_view &line) const m::user::id &, const net::hostport &remote); - static m::import download + thread_local mods::import download { "media_media", "download" }; diff --git a/modules/m_room.cc b/modules/m_room.cc index 3d7ee062c..984f58595 100644 --- a/modules/m_room.cc +++ b/modules/m_room.cc @@ -657,7 +657,7 @@ room_herd(const m::room &room, const milliseconds &, const std::function &); - static m::import feds__head + thread_local mods::import feds__head { "federation_federation", "feds__head" }; diff --git a/modules/m_room_member.cc b/modules/m_room_member.cc index 3622697ee..f8a8c8508 100644 --- a/modules/m_room_member.cc +++ b/modules/m_room_member.cc @@ -88,7 +88,7 @@ _join_room_hookfn }; using invite_foreign_proto = m::event::id::buf (const m::event &); -m::import +thread_local mods::import invite__foreign { "client_rooms", "invite__foreign" diff --git a/modules/s_control.cc b/modules/s_control.cc index 3cf1afdf1..18b60af6f 100644 --- a/modules/s_control.cc +++ b/modules/s_control.cc @@ -71,9 +71,9 @@ noexcept try }; using prototype = int (std::ostream &, const string_view &, const string_view &); - const mods::import command + mods::import command { - *console_module, "console_command" + console_module, "console_command"s }; std::ostringstream out; diff --git a/modules/vm.cc b/modules/vm.cc index af996b352..87e80951e 100644 --- a/modules/vm.cc +++ b/modules/vm.cc @@ -148,7 +148,7 @@ ircd::m::vm::eval__commit_room(eval &eval, const mutable_buffer &, const size_t &, const bool &); - static m::import make_prev__buf + thread_local mods::import make_prev__buf { "m_room", "make_prev__buf" }; @@ -181,7 +181,7 @@ ircd::m::vm::eval__commit_room(eval &eval, const vector_view &, const string_view &); - static m::import make_auth__buf + thread_local mods::import make_auth__buf { "m_room", "make_auth__buf" };