refactor: Move threads.proto to lib_system
This commit is contained in:
1 parent
245c7deb80
commit
fdfc9fbfaa
10 files changed
+83
-35
No files matched your search
+37
-3
@@ -1,6 +1,7 @@
|
||||
include_guard(DIRECTORY)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/ExportToParent.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/InstallBasic.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/ProtobufGenerateCpp.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/SetFirstDefined.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/safe_dep_glob.cmake)
|
||||
|
||||
@@ -33,18 +34,39 @@ function(init_library)
|
||||
list(REMOVE_ITEM ${_name}_SOURCES ${item})
|
||||
endforeach()
|
||||
|
||||
# Proto sources
|
||||
file(
|
||||
GLOB_RECURSE ${_name}_PROTO_SOURCES
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${_source_dir}/protobufs/*.proto
|
||||
)
|
||||
update_deps_file("${${_name}_PROTO_SOURCES};")
|
||||
protobuf_generate_cpp(
|
||||
CXX_SOURCES ${_name}_CXX_PROTO_SOURCES
|
||||
CXX_HEADERS ${_name}_CXX_PROTO_HEADERS
|
||||
CXX_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}
|
||||
PROTO_INCLUDE_DIRS
|
||||
${EXTERNALS_INCLUDE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PROTO_SOURCES
|
||||
${${_name}_PROTO_SOURCES}
|
||||
)
|
||||
|
||||
export_to_parent(
|
||||
${_name}_SOURCES
|
||||
${_name}_TEST_SOURCES
|
||||
${_name}_PROTO_SOURCES
|
||||
${_name}_CXX_PROTO_SOURCES
|
||||
${_name}_CXX_PROTO_HEADERS
|
||||
)
|
||||
|
||||
# Add main lib
|
||||
if (_ARGS_STATIC)
|
||||
add_library(${_name} STATIC ${${_name}_SOURCES})
|
||||
add_library(${_name} STATIC ${${_name}_SOURCES} ${${_name}_CXX_PROTO_SOURCES})
|
||||
elseif(_ARGS_SHARED)
|
||||
add_library(${_name} SHARED ${${_name}_SOURCES})
|
||||
add_library(${_name} SHARED ${${_name}_SOURCES} ${${_name}_CXX_PROTO_SOURCES})
|
||||
else()
|
||||
add_library(${_name} ${${_name}_SOURCES})
|
||||
add_library(${_name} ${${_name}_SOURCES} ${${_name}_CXX_PROTO_SOURCES})
|
||||
endif()
|
||||
target_include_directories(
|
||||
${_name}
|
||||
@@ -52,6 +74,14 @@ function(init_library)
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
# Include protos (if any)
|
||||
if (${_name}_PROTO_SOURCES)
|
||||
target_include_directories(
|
||||
${_name}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
||||
)
|
||||
endif()
|
||||
target_link_directories(
|
||||
${_name}
|
||||
PUBLIC
|
||||
@@ -59,6 +89,10 @@ function(init_library)
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>
|
||||
)
|
||||
# Install main lib
|
||||
foreach(_hdr ${${_name}_CXX_PROTO_HEADERS})
|
||||
file(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_BINARY_DIR} ${_hdr})
|
||||
install(FILES ${_hdr} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${_relative_path})
|
||||
endforeach()
|
||||
install_basic(
|
||||
NAME ${_name}
|
||||
INCLUDE_DIR ${_include_dir}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/bts_chrono.h"
|
||||
#include "spark/utils/thread_manager.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/config/threads.pb.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
@@ -14,6 +14,8 @@
|
||||
namespace bts {
|
||||
namespace log {
|
||||
|
||||
using bts::system::protobufs::ThreadGroupCfg;
|
||||
|
||||
std::atomic<size_t> thread_idx;
|
||||
|
||||
struct LoggerHub::SinkRec {
|
||||
@@ -38,7 +40,7 @@ struct LoggerHub::PImpl {
|
||||
size_t logger_initial_queue_size;
|
||||
size_t logger_max_queue_growth;
|
||||
std::string logger_name;
|
||||
config::ThreadGroupCfg thread_cfg;
|
||||
ThreadGroupCfg thread_cfg;
|
||||
};
|
||||
|
||||
LoggerHub::LoggerHub(std::string const &logger_name)
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
#include "Common.h"
|
||||
#include "Sink.h"
|
||||
#include "spark/config/protos/threads.pb.h"
|
||||
#include "system/protobufs/config/threads.pb.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
@@ -21,7 +22,7 @@ struct LoggingConfig {
|
||||
std::map<Level, std::string> level_names;
|
||||
std::map<Subsystem, std::string> subsystem_names;
|
||||
std::string deployment_type;
|
||||
config::ThreadGroupCfg thread_cfg;
|
||||
system::protobufs::ThreadGroupCfg thread_cfg;
|
||||
};
|
||||
|
||||
} // namespace log
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/thread_manager.h"
|
||||
#include "system/os.h"
|
||||
#include "system/protobufs/config/threads.pb.h"
|
||||
#ifdef SPARK_ENABLE_CCAPI
|
||||
#include "spark/logging/ccapi_logger.h"
|
||||
#endif
|
||||
@@ -29,6 +30,7 @@ namespace bts {
|
||||
namespace log {
|
||||
|
||||
using bts::config::SystemConfig;
|
||||
using bts::system::protobufs::ThreadGroupCfg;
|
||||
using Path = boost::filesystem::path;
|
||||
|
||||
static LoggerHub _default_logger_hub("logger");
|
||||
@@ -86,11 +88,10 @@ void configure_logging(LoggingConfig const &cfg) {
|
||||
_default_logger_hub.config(cfg);
|
||||
}
|
||||
void configure_logging(bts::config::Logging const &cfg) {
|
||||
configure_logging(cfg, bts::config::ThreadGroupCfg());
|
||||
configure_logging(cfg, ThreadGroupCfg());
|
||||
}
|
||||
void configure_logging(
|
||||
bts::config::Logging const &cfg,
|
||||
bts::config::ThreadGroupCfg const &thread_cfg) {
|
||||
bts::config::Logging const &cfg, const ThreadGroupCfg &thread_cfg) {
|
||||
LoggingConfig real_cfg;
|
||||
real_cfg.deployment_type = config::get<config::DeploymentType>().type();
|
||||
real_cfg.logger_initial_queue_size = cfg.initial_queue_size();
|
||||
@@ -128,8 +129,7 @@ void configure_logging(
|
||||
Path log_cache_file_path() { return log_path() / "log_control"; }
|
||||
|
||||
LoggingConfigPoller::LoggingConfigPoller(
|
||||
bts::config::Logging const &cfg,
|
||||
bts::config::ThreadGroupCfg const &thread_cfg)
|
||||
bts::config::Logging const &cfg, const ThreadGroupCfg &thread_cfg)
|
||||
: _poller(
|
||||
utils::Dispatcher::background(), 1000, [=, this]() { poll_once(); }),
|
||||
_last_ts(std::time(nullptr)), _log_cache_file(log_cache_file_path()),
|
||||
@@ -143,8 +143,7 @@ LoggingConfigPoller::LoggingConfigPoller()
|
||||
}
|
||||
|
||||
void LoggingConfigPoller::init(
|
||||
bts::config::Logging const &cfg,
|
||||
bts::config::ThreadGroupCfg const &thread_cfg) {
|
||||
bts::config::Logging const &cfg, const ThreadGroupCfg &thread_cfg) {
|
||||
auto parent = _log_cache_file.parent_path();
|
||||
if (!boost::filesystem::is_directory(parent))
|
||||
bts_assert(boost::filesystem::create_directories(parent));
|
||||
|
||||
@@ -10,10 +10,13 @@
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <thread>
|
||||
|
||||
namespace bts::system::protobufs {
|
||||
class ThreadGroupCfg;
|
||||
}
|
||||
|
||||
namespace bts {
|
||||
namespace config {
|
||||
class Logging;
|
||||
class ThreadGroupCfg;
|
||||
} // namespace config
|
||||
|
||||
// Please keep this list in sync with Log.cs
|
||||
@@ -77,7 +80,8 @@ inline std::ostream &operator<<(std::ostream &s, CharPtrWrapper const &ptr) {
|
||||
extern thread_local LoggerHandle _thread_logger;
|
||||
void configure_logging(LoggingConfig const &cfg);
|
||||
void configure_logging(
|
||||
bts::config::Logging const &cfg, bts::config::ThreadGroupCfg const &);
|
||||
bts::config::Logging const &cfg,
|
||||
const system::protobufs::ThreadGroupCfg &thread_cfg);
|
||||
void configure_logging(bts::config::Logging const &cfg);
|
||||
void start_default_logging_thread();
|
||||
|
||||
@@ -86,13 +90,13 @@ class LoggingConfigPoller {
|
||||
LoggingConfigPoller();
|
||||
LoggingConfigPoller(
|
||||
bts::config::Logging const &cfg,
|
||||
bts::config::ThreadGroupCfg const &thread_cfg);
|
||||
const system::protobufs::ThreadGroupCfg &thread_cfg);
|
||||
~LoggingConfigPoller();
|
||||
|
||||
private:
|
||||
void init(
|
||||
bts::config::Logging const &cfg,
|
||||
bts::config::ThreadGroupCfg const &thread_cfg);
|
||||
const system::protobufs::ThreadGroupCfg &thread_cfg);
|
||||
void poll_once();
|
||||
utils::DispatcherTimer _poller;
|
||||
std::time_t _last_ts;
|
||||
|
||||
@@ -134,7 +134,7 @@ void QBConnection::recv_msg_header() {
|
||||
asio::async_read(
|
||||
me->socket,
|
||||
asio::buffer(&me->read_buffer_size, sizeof(me->read_buffer_size)),
|
||||
[this, self](system::error_code error, std::size_t) {
|
||||
[this, self](boost::system::error_code error, std::size_t) {
|
||||
if (!error)
|
||||
recv_msg_body();
|
||||
else
|
||||
@@ -148,7 +148,7 @@ void QBConnection::recv_msg_body() {
|
||||
me->read_buffer.resize(me->read_buffer_size);
|
||||
asio::async_read(
|
||||
me->socket, asio::buffer(&me->read_buffer[0], me->read_buffer_size),
|
||||
[this, self](system::error_code error, std::size_t) {
|
||||
[this, self](boost::system::error_code error, std::size_t) {
|
||||
if (!error) {
|
||||
msgs::QBMsg m;
|
||||
auto parse_ok = m.ParseFromArray(
|
||||
@@ -448,7 +448,7 @@ void QBConnection::send(msgs::QBMsg const &msg) {
|
||||
|
||||
asio::async_write(
|
||||
me->socket, to_send,
|
||||
[this, self](system::error_code error, std::size_t) {
|
||||
[this, self](boost::system::error_code error, std::size_t) {
|
||||
if (!error) {
|
||||
me->write_buffer.clear();
|
||||
try_send_pending();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "thread_manager.h"
|
||||
#include "spark/config/config.h"
|
||||
#include "spark/config/protos/threads.pb.h"
|
||||
#include "spark/logging/logging.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "system/protobufs/config/threads.pb.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include <fmt/format.h>
|
||||
@@ -14,8 +14,9 @@
|
||||
namespace bts {
|
||||
namespace threading {
|
||||
|
||||
config::ThreadGroupCfg get_thread_cfg(std::string const &name) {
|
||||
for (auto const &cfg : config::get<config::Threads>().thread_group()) {
|
||||
system::protobufs::ThreadGroupCfg get_thread_cfg(std::string const &name) {
|
||||
for (auto const &cfg :
|
||||
config::get<system::protobufs::Threads>().thread_group()) {
|
||||
boost::regex rx(cfg.name_rx());
|
||||
if (boost::regex_match(name, rx))
|
||||
return cfg;
|
||||
@@ -44,7 +45,9 @@ std::vector<uint32_t> get_affinity(std::string const &name) {
|
||||
|
||||
#ifndef _WIN32
|
||||
void configure_thread(
|
||||
std::string const &name, config::ThreadGroupCfg const &cfg, pthread_t t) {
|
||||
std::string const &name,
|
||||
const system::protobufs::ThreadGroupCfg &cfg,
|
||||
pthread_t t) {
|
||||
if (cfg.core().size()) {
|
||||
cpu_set_t cpuset;
|
||||
CPU_ZERO(&cpuset);
|
||||
@@ -79,7 +82,7 @@ void configure_current_thread(std::string const &name) {
|
||||
}
|
||||
|
||||
void configure_current_thread(
|
||||
std::string const &name, config::ThreadGroupCfg const &cfg) {
|
||||
std::string const &name, const system::protobufs::ThreadGroupCfg &cfg) {
|
||||
#ifndef _WIN32
|
||||
configure_thread(name, cfg, pthread_self());
|
||||
#endif
|
||||
@@ -102,7 +105,7 @@ std::thread make_thread_from_function(
|
||||
std::thread make_thread_from_function(
|
||||
std::string const &name,
|
||||
std::function<void()> const &c,
|
||||
config::ThreadGroupCfg const &cfg) {
|
||||
const system::protobufs::ThreadGroupCfg &cfg) {
|
||||
auto result = std::thread([c, name]() {
|
||||
os::set_thread_name(name);
|
||||
c();
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/config/protos/threads.pb.h"
|
||||
#include "system/protobufs/config/threads.pb.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace bts {
|
||||
namespace config {
|
||||
namespace bts::system::protobufs {
|
||||
class ThreadGroupCfg;
|
||||
}
|
||||
|
||||
namespace bts {
|
||||
namespace threading {
|
||||
|
||||
std::thread make_thread_from_function(
|
||||
std::string const &name,
|
||||
std::function<void()> const &c,
|
||||
config::ThreadGroupCfg const &cfg);
|
||||
system::protobufs::ThreadGroupCfg const &cfg);
|
||||
std::thread make_thread_from_function(
|
||||
std::string const &name, std::function<void()> const &c);
|
||||
|
||||
@@ -25,15 +27,17 @@ std::thread make_thread(std::string const &name, C callable) {
|
||||
|
||||
template <class C>
|
||||
std::thread make_thread(
|
||||
std::string const &name, C callable, config::ThreadGroupCfg const &cfg) {
|
||||
std::string const &name,
|
||||
C callable,
|
||||
system::protobufs::ThreadGroupCfg const &cfg) {
|
||||
return make_thread_from_function(name, std::function<void()>(callable), cfg);
|
||||
}
|
||||
|
||||
void configure_current_thread(std::string const &name);
|
||||
void configure_current_thread(
|
||||
std::string const &name, config::ThreadGroupCfg const &);
|
||||
std::string const &name, system::protobufs::ThreadGroupCfg const &);
|
||||
|
||||
config::ThreadGroupCfg get_thread_cfg(std::string const &);
|
||||
system::protobufs::ThreadGroupCfg get_thread_cfg(std::string const &);
|
||||
|
||||
std::vector<uint32_t> get_affinity(std::string const &name);
|
||||
|
||||
|
||||
@@ -10,4 +10,5 @@ target_link_libraries(
|
||||
debug fmtd
|
||||
optimized fmt
|
||||
boost_filesystem
|
||||
protobuf
|
||||
)
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package bts.config;
|
||||
package bts.system.protobufs;
|
||||
|
||||
message ThreadGroupCfg {
|
||||
string name_rx = 1;
|
||||
Reference in new issue
Block a user