|
#include "registry.h"
|
|
#include "disruptor.h"
|
|
#include "sl/register.h"
|
|
|
|
#include <concepts>
|
|
#include <atomic>
|
|
#include <unordered_map>
|
|
#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
|
|
*/
|
|
template<std::integral T, T default_increment, T maximum_increment>
|
|
class fast_semaphore {
|
|
std::atomic<T> flag; //< This is our counter
|
|
public:
|
|
fast_semaphore() = default;
|
|
fast_semaphore(fast_semaphore&) = delete;
|
|
fast_semaphore(fast_semaphore&&) = delete;
|
|
|
|
/// 3 things may happen when trying to unlock
|
|
enum class tristate {
|
|
success = 1, //< The unlocking was successful
|
|
timing = 0, //< Someone interfered with the unlocking
|
|
error = -1 //< The unlocking would over-unlock the semaphore
|
|
};
|
|
|
|
/// We try locking until we succeed
|
|
template<T increment = default_increment>
|
|
void lock() {
|
|
while(not try_lock<increment>());
|
|
}
|
|
|
|
/// For locking, we try to atomically increment the counter while maintaining it below the set limit
|
|
template<T increment = default_increment>
|
|
[[nodiscard]] bool try_lock() {
|
|
T expect = flag.load(std::memory_order::acquire);
|
|
T target = expect + increment;
|
|
if(target > maximum_increment) return false;
|
|
return flag.compare_exchange_strong(expect,target,std::memory_order::release);
|
|
}
|
|
|
|
/// Similarly to locking, we try unlocking until we succeed (or reach an invalid state)
|
|
template<T increment = default_increment>
|
|
void unlock() {
|
|
tristate v;
|
|
do{ v = try_unlock<increment>(); }
|
|
while(v == tristate::timing);
|
|
if(v != tristate::success) {
|
|
throw std::runtime_error("Over unlocking may have happened: potential double unlocking issue");
|
|
}
|
|
}
|
|
|
|
/// Unlocking is the reverse of locking, we have to ensure to return an error if we try to go below zero
|
|
template<T increment = default_increment>
|
|
[[nodiscard]] tristate try_unlock() {
|
|
T expect = flag.load(std::memory_order::relaxed);
|
|
T target = expect - increment;
|
|
if(target < 0) return tristate::error;
|
|
return flag.compare_exchange_strong(expect,target,std::memory_order::release) ? tristate::success : tristate::timing;
|
|
}
|
|
};
|
|
|
|
using rw_lock_type = fast_semaphore<int32_t, 256, 256>;
|
|
|
|
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);
|
|
}
|
|
};
|
|
|
|
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);
|
|
}
|
|
};
|
|
|
|
static fast_semaphore<int32_t, 256, 256> registry_rw_lock;
|
|
|
|
std::unordered_map<int, registry_slab> registry_map;
|
|
|
|
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);
|
|
};
|
|
}
|
|
|
|
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(std::string_view, size_t sz) {
|
|
return std::vector<char>(sz, 0);
|
|
}
|
|
|
|
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(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) {
|
|
|
|
}
|
|
|
|
void SinkStrategyFastest::write(int fd, std::string_view data) {
|
|
|
|
}
|
|
|
|
void SinkStrategyMmaped::write(int fd, std::string_view data) {
|
|
|
|
}
|
|
|
|
void SinkStrategyExternal::write(int fd, std::string_view data) {
|
|
|
|
}
|
|
|
|
void OverflowStrategyWait::wait() {
|
|
|
|
}
|
|
|
|
void OverflowStrategyContinue::wait() {
|
|
|
|
}
|
|
|
|
std::pair<std::string_view, std::string_view> OutputStrategyTimed::chunk(std::string_view) {
|
|
return {};
|
|
}
|
|
|
|
int OutputStrategyTimed::on_write_completed_event(std::string_view, int) {
|
|
return 0;
|
|
}
|
|
|
|
std::pair<std::string_view, std::string_view> OutputStrategySized::chunk(std::string_view) {
|
|
return {};
|
|
}
|
|
|
|
int OutputStrategySized::on_write_completed_event(std::string_view, int) {
|
|
return 0;
|
|
}
|
|
|
|
std::pair<std::string_view, std::string_view> OutputStrategySimple::chunk(std::string_view) {
|
|
return {};
|
|
}
|
|
|
|
int OutputStrategySimple::on_write_completed_event(std::string_view, int) {
|
|
return 0;
|
|
}
|