From 12a8d45646eb044bbab105628f7ccf71e5ae76a3 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 21 Apr 2022 22:07:32 +0100 Subject: [PATCH] [Project] Move runtime cache part to a separate unit --- src/libserver/symcache/symcache_impl.cxx | 1 + src/libserver/symcache/symcache_internal.hxx | 27 -------- src/libserver/symcache/symcache_runtime.hxx | 66 ++++++++++++++++++++ 3 files changed, 67 insertions(+), 27 deletions(-) create mode 100644 src/libserver/symcache/symcache_runtime.hxx diff --git a/src/libserver/symcache/symcache_impl.cxx b/src/libserver/symcache/symcache_impl.cxx index 1b7baef43..48646de33 100644 --- a/src/libserver/symcache/symcache_impl.cxx +++ b/src/libserver/symcache/symcache_impl.cxx @@ -16,6 +16,7 @@ #include "symcache_internal.hxx" #include "symcache_item.hxx" +#include "symcache_runtime.hxx" #include "unix-std.h" #include "libutil/cxx/locked_file.hxx" #include "fmt/core.h" diff --git a/src/libserver/symcache/symcache_internal.hxx b/src/libserver/symcache/symcache_internal.hxx index 974c34e75..e094330fd 100644 --- a/src/libserver/symcache/symcache_internal.hxx +++ b/src/libserver/symcache/symcache_internal.hxx @@ -336,34 +336,7 @@ public: } }; -/* - * These items are saved within task structure and are used to track - * symbols execution - */ -struct cache_dynamic_item { - std::uint16_t start_msec; /* Relative to task time */ - unsigned started: 1; - unsigned finished: 1; - /* unsigned pad:14; */ - std::uint32_t async_events; -}; - -struct cache_savepoint { - unsigned order_gen; - unsigned items_inflight; - bool profile; - bool has_slow; - double profile_start; - double lim; - - struct rspamd_scan_result *rs; - - struct cache_item *cur_item; - order_generation_ptr order; - /* Dynamically expanded as needed */ - struct cache_dynamic_item dynamic_items[]; -}; } // namespace rspamd #endif //RSPAMD_SYMCACHE_INTERNAL_HXX diff --git a/src/libserver/symcache/symcache_runtime.hxx b/src/libserver/symcache/symcache_runtime.hxx new file mode 100644 index 000000000..bf3049ffe --- /dev/null +++ b/src/libserver/symcache/symcache_runtime.hxx @@ -0,0 +1,66 @@ +/*- + * Copyright 2022 Vsevolod Stakhov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * Symcache runtime is produced for each task and it consists of symbols + * being executed, being dynamically disabled/enabled and it also captures + * the current order of the symbols (produced by resort periodic) + */ + +#ifndef RSPAMD_SYMCACHE_RUNTIME_HXX +#define RSPAMD_SYMCACHE_RUNTIME_HXX +#pragma once + +#include "symcache_internal.hxx" + +namespace rspamd::symcache { +/** + * These items are saved within task structure and are used to track + * symbols execution. + * Each symcache item occupies a single dynamic item, that currently has 8 bytes + * length + */ +struct cache_dynamic_item { + std::uint16_t start_msec; /* Relative to task time */ + bool started; + bool finished; + std::uint32_t async_events; +}; + +static_assert(sizeof(cache_dynamic_item) == sizeof(std::uint64_t)); +static_assert(std::is_trivial_v); + +struct cache_savepoint { + unsigned order_gen; + unsigned items_inflight; + bool profile; + bool has_slow; + + double profile_start; + double lim; + + struct rspamd_scan_result *rs; + + struct cache_item *cur_item; + order_generation_ptr order; + /* Dynamically expanded as needed */ + struct cache_dynamic_item dynamic_items[]; +}; + +} + +#endif //RSPAMD_SYMCACHE_RUNTIME_HXX -- 2.39.5