|
|
@ -8,6 +8,12 @@ |
|
|
|
#include <functional>
|
|
|
|
#include <any>
|
|
|
|
|
|
|
|
#if defined(__linux__) || defined(__linux)
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief A fast semaphore exclusion handler WITHOUT deadlock detection or yielding |
|
|
@ -67,10 +73,11 @@ using rw_lock_type = fast_semaphore; |
|
|
|
|
|
|
|
class lock_handler_read { |
|
|
|
rw_lock_type& ref; |
|
|
|
|
|
|
|
public: |
|
|
|
explicit lock_handler_read(rw_lock_type& _ref) : ref(_ref) { |
|
|
|
while(ref.try_lock<1>()); |
|
|
|
} |
|
|
|
|
|
|
|
~lock_handler_read() { |
|
|
|
while(ref.try_unlock<1>() != rw_lock_type::tristate::success); |
|
|
|
} |
|
|
@ -78,10 +85,11 @@ class lock_handler_read { |
|
|
|
|
|
|
|
class lock_handler_write { |
|
|
|
rw_lock_type& ref; |
|
|
|
|
|
|
|
public: |
|
|
|
explicit lock_handler_write(rw_lock_type& _ref) : ref(_ref) { |
|
|
|
while(ref.try_lock()); |
|
|
|
} |
|
|
|
|
|
|
|
~lock_handler_write() { |
|
|
|
while(ref.try_unlock() != rw_lock_type::tristate::success); |
|
|
|
} |
|
|
@ -89,32 +97,285 @@ class lock_handler_write { |
|
|
|
|
|
|
|
static fast_semaphore<int32_t, 256, 256> registry_rw_lock; |
|
|
|
|
|
|
|
std::unordered_map<int, registry_slab> registry_map; |
|
|
|
|
|
|
|
struct registry_slab { |
|
|
|
int id; |
|
|
|
std::string name; |
|
|
|
std::function<token_t(size_t)> reserve_write; |
|
|
|
std::function<token_t(size_t)> reserve_write_c_align; |
|
|
|
std::function<void(token_t)> conclude_write; |
|
|
|
std::any disruptor; |
|
|
|
}; |
|
|
|
template<BufferStrategy buff_strat, SinkStrategy sink_strat, OverflowStrategy of_strat, OutputStrategy out_strat> |
|
|
|
void register_log_impl(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
if(buffer_size % page_size != 0) { |
|
|
|
// TODO: more meaningful exception
|
|
|
|
throw disruptor_exception{"Size provided for the disruptor doesn't align with page size"}; |
|
|
|
} |
|
|
|
lock_handler_write lock_me{registry_rw_lock}; |
|
|
|
|
|
|
|
if(registry_map.contains(log_id)) { |
|
|
|
// TODO: more meaningful exception
|
|
|
|
throw disruptor_exception{"Log ID already exists"}; |
|
|
|
} |
|
|
|
|
|
|
|
registry_map.insert(std::pair<int, registry_slab>{log_id, {}}); |
|
|
|
auto& slab = registry_map[log_id]; |
|
|
|
slab.id = log_id; |
|
|
|
slab.name = log_name; |
|
|
|
auto* transient_reference = new disruptor<of_strat>(buff_strat{}, filename, buffer_size); |
|
|
|
slab.disruptor = transient_reference; |
|
|
|
slab.reserve_write = [ptr = transient_reference] (size_t sz) -> token_t{ |
|
|
|
return ptr->reserve_write(sz); |
|
|
|
}; |
|
|
|
slab.reserve_write_c_align = [ptr = transient_reference] (size_t sz) -> token_t{ |
|
|
|
return ptr->reserve_write(sz, force_contiguous_mode); |
|
|
|
}; |
|
|
|
slab.conclude_write = [ptr = transient_reference] (token_t tok) -> void { |
|
|
|
ptr->conclude_write(tok); |
|
|
|
}; |
|
|
|
slab.get_buffer = [self = slab, ptr = transient_reference] (token_t tok) -> write_span { |
|
|
|
return write_span(tok, *ptr); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal used because we need the pointer stability |
|
|
|
* @see sl_transaction |
|
|
|
*/ |
|
|
|
static std::unordered_map<int, registry_slab> registry_map; |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategyTimed>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategyTimed>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySized>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySized>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySimple>(int log_id, std::string_view log_name, std::string_view filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory) { |
|
|
|
register_log_impl<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySimple>(log_id, log_name, filename, buffer_size, out_strategy_parameter, output_directory); |
|
|
|
} |
|
|
|
|
|
|
|
BufferStrategyInternal::buffer_type BufferStrategyInternal::build_buffer(size_t) { |
|
|
|
return {}; |
|
|
|
BufferStrategyInternal::buffer_type BufferStrategyInternal::build_buffer(std::string_view, size_t sz) { |
|
|
|
return n">std::vector<char>(sz, 0); |
|
|
|
} |
|
|
|
|
|
|
|
BufferStrategyShared::buffer_type BufferStrategyShared::build_buffer(size_t) { |
|
|
|
return {}; |
|
|
|
BufferStrategyShared::buffer_type BufferStrategyShared::build_buffer(std::string_view, size_t sz) { |
|
|
|
#if defined(__linux__) || defined(__linux)
|
|
|
|
auto buff = mmap(nullptr, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0); |
|
|
|
if(not buff) throw disruptor_exception{"Could not allocate memory for BufferStrategyShared"}; |
|
|
|
return {(char*)buff, sz}; |
|
|
|
#else
|
|
|
|
static_assert(false, "BufferStrategyShared strategy is unimplemented on your system"); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
BufferStrategyExternal::buffer_type BufferStrategyExternal::build_buffer(size_t) { |
|
|
|
return {}; |
|
|
|
BufferStrategyExternal::buffer_type BufferStrategyExternal::build_buffer(std::string_view filename, size_t sz) { |
|
|
|
#if defined(__linux__) || defined(__linux)
|
|
|
|
auto fd = open(std::string{filename}.c_str(), O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); |
|
|
|
if(fd <= 0) throw disruptor_exception{"Could not open or create file for BufferStrategyExternal"}; |
|
|
|
if(ftruncate(fd, sz) != 0) throw disruptor_exception{"Could not ensure size for the file for BufferStrategyExternal"}; |
|
|
|
auto buff = mmap(nullptr, sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, 0); |
|
|
|
if(not buff) { |
|
|
|
throw disruptor_exception{"Could not allocate memory for BufferStrategyExternal, mapping failed"}; |
|
|
|
} |
|
|
|
return {(char*)buff, sz}; |
|
|
|
#else
|
|
|
|
static_assert(false, "BufferStrategyExternal strategy is unimplemented on your system"); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
void SinkStrategyDirect::write(int fd, std::string_view data) { |
|
|
|