<commit_before>#include "_ft_internal.h"

///

static void _ft_context_on_sigexit(struct ev_loop * loop, ev_signal * w, int revents);
static void _ft_context_on_heartbeat_timer(struct ev_loop * loop, ev_timer * w, int revents);
static void _ft_context_on_shutdown_timer(struct ev_loop * loop, ev_timer * w, int revents);
static void ft_context_on_prepare(struct ev_loop * loop, ev_prepare * w, int revents);

struct _ft_context_callback_entry
{
	ft_context_callback callback;
	void * data;
};

///

bool ft_context_init(struct ft_context * this)
{
	bool ok;

	this->ev_loop = ev_default_loop(ft_config.libev_loop_flags);
	if (this->ev_loop == NULL) return false;

	this->flags.running = true;
	this->shutdown_counter = 0;

	// Set a logging context
	ft_log_context(this);

	// Install signal handlers
	ev_signal_init(&this->sigint_w, _ft_context_on_sigexit, SIGINT);
	ev_signal_start(this->ev_loop, &this->sigint_w);
	ev_unref(this->ev_loop);
	this->sigint_w.data = this;

	ev_signal_init(&this->sigterm_w, _ft_context_on_sigexit, SIGTERM);
	ev_signal_start(this->ev_loop, &this->sigterm_w);
	ev_unref(this->ev_loop);
	this->sigterm_w.data = this;

	// Install heartbeat timer watcher
	ev_timer_init(&this->heartbeat_w, _ft_context_on_heartbeat_timer, 0.0, ft_config.heartbeat_interval);
	ev_set_priority(&this->heartbeat_w, -2);
	ev_timer_start(this->ev_loop, &this->heartbeat_w);
	ev_unref(this->ev_loop);
	this->heartbeat_w.data = this;
	this->heartbeat_at = 0.0;

	// Install proapre handler that allows to prepare for a event sleep<commit_msg>Add a missing assert.<commit_after>#include "_ft_internal.h"

///

static void _ft_context_on_sigexit(struct ev_loop * loop, ev_signal * w, int revents);
static void _ft_context_on_heartbeat_timer(struct ev_loop * loop, ev_timer * w, int revents);
static void _ft_context_on_shutdown_timer(struct ev_loop * loop, ev_timer * w, int revents);
static void ft_context_on_prepare(struct ev_loop * loop, ev_prepare * w, int revents);

struct _ft_context_callback_entry
{
	ft_context_callback callback;
	void * data;
};

///

bool ft_context_init(struct ft_context * this)
{
	bool ok;
	assert(this != NULL);

	this->ev_loop = ev_default_loop(ft_config.libev_loop_flags);
	if (this->ev_loop == NULL) return false;

	this->flags.running = true;
	this->shutdown_counter = 0;

	// Set a logging context
	ft_log_context(this);

	// Install signal handlers
	ev_signal_init(&this->sigint_w, _ft_context_on_sigexit, SIGINT);
	ev_signal_start(this->ev_loop, &this->sigint_w);
	ev_unref(this->ev_loop);
	this->sigint_w.data = this;

	ev_signal_init(&this->sigterm_w, _ft_context_on_sigexit, SIGTERM);
	ev_signal_start(this->ev_loop, &this->sigterm_w);
	ev_unref(this->ev_loop);
	this->sigterm_w.data = this;

	// Install heartbeat timer watcher
	ev_timer_init(&this->heartbeat_w, _ft_context_on_heartbeat_timer, 0.0, ft_config.heartbeat_interval);
	ev_set_priority(&this->heartbeat_w, -2);
	ev_timer_start(this->ev_loop, &this->heartbeat_w);
	ev_unref(this->ev_loop);
	this->heartbeat_w.data = this;
	this->heartbeat_at = 0.0;

	// Install proapre handler that allows to prepare for a event sleep
{'fraction_non_alphanumeric': 0.11896386312759834, 'fraction_numerical': 0.003837543971858011, 'mean_word_length': 5.9050772626931565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2677955', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1169, 'n_words': 230}