<commit_before>#include <vector>
#include <utility>

#include <sys/time.h>
#include <time.h>

#include "dasynq-timerbase.h"
#include "dasynq-binaryheap.h"

namespace dasynq {

// Timer implementation based on the (basically obselete) POSIX itimer interface.

template <class Base> class ITimerEvents : public timer_base<Base>
{
    private:
    int timerfd_fd = -1;

    timer_queue_t timer_queue;
    
#if defined(__APPLE__)
#define itimerspec itimerval
#endif
    
    // Set the timerfd timeout to match the first timer in the queue (disable the timerfd
    // if there are no active timers).
    void set_timer_from_queue()
    {
        struct itimerspec newtime;
        if (timer_queue.empty()) {
            newtime.it_value = {0, 0};
            newtime.it_interval = {0, 0};
        }
        else {
#if defined(__APPLE__)
            auto &rp = timer_queue.get_root_priority();
            newtime.it_value.tv_sec = rp.tv_sec;
            newtime.it_value.tv_usec = rp.tv_nsec / 1000;
#else<commit_msg>itimer: remove unneeded (and no longer available) include<commit_after>#include <vector>
#include <utility>

#include <sys/time.h>
#include <time.h>

#include "dasynq-timerbase.h"

namespace dasynq {

// Timer implementation based on the (basically obselete) POSIX itimer interface.

template <class Base> class ITimerEvents : public timer_base<Base>
{
    private:
    int timerfd_fd = -1;

    timer_queue_t timer_queue;
    
#if defined(__APPLE__)
#define itimerspec itimerval
#endif
    
    // Set the timerfd timeout to match the first timer in the queue (disable the timerfd
    // if there are no active timers).
    void set_timer_from_queue()
    {
        struct itimerspec newtime;
        if (timer_queue.empty()) {
            newtime.it_value = {0, 0};
            newtime.it_interval = {0, 0};
        }
        else {
#if defined(__APPLE__)
            auto &rp = timer_queue.get_root_priority();
            newtime.it_value.tv_sec = rp.tv_sec;
            newtime.it_value.tv_usec = rp.tv_nsec / 1000;
#else
{'fraction_non_alphanumeric': 0.09906817067189799, 'fraction_numerical': 0.008827856792545365, 'mean_word_length': 2.7777777777777777, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2044448', 'n_tokens_mistral': 699, 'n_tokens_neox': 679, 'n_words': 182}