<commit_before>// Copyright 2010-2012 RethinkDB, all rights reserved.
#include "arch/timing.hpp"

#include "errors.hpp"
#include <boost/bind.hpp>

#include "arch/arch.hpp"
#include "arch/runtime/runtime.hpp"
#include "concurrency/wait_any.hpp"

// nap()

void nap(int64_t ms) THROWS_NOTHING {
    if (ms > 0) {
        signal_timer_t timer(ms);
        timer.wait_lazily_ordered();
    }
}

void nap(int64_t ms, signal_t *interruptor) THROWS_ONLY(interrupted_exc_t) {
    signal_timer_t timer(ms);
    wait_interruptible(&timer, interruptor);
}

// signal_timer_t

signal_timer_t::signal_timer_t(int64_t ms) {
    rassert(ms >= 0);
    timer = fire_timer_once(ms, this);
}

signal_timer_t::~signal_timer_t() {
    if (timer) cancel_timer(timer);
}

void signal_timer_t::on_timer() {
    timer = NULL;
    pulse();
}

// repeating_timer_t

repeating_timer_t::repeating_timer_t(int64_t frequency_ms, repeating_timer_callback_t *_ringee) :
    ringee(_ringee) {
    rassert(frequency_ms > 0);
    timer = add_timer(frequency_ms, this);
}

repeating_timer_t::~repeating_timer_t() {
    cancel_timer(timer);
}

void call_ringer(repeating_timer_callback_t *ringee) {
    // It would be very easy for a user of repeating_timer_t to have
    // object lifetime errors, if their ring function blocks.  So we
    // have this assertion.
    ASSERT_FINITE_CORO_WAITING;
    ringee->on_ring();
}
<commit_msg>Made the signal_timer_t handle zero-length timeouts by immediately pulsing.<commit_after>// Copyright 2010-2012 RethinkDB, all rights reserved.
#include "arch/timing.hpp"

#include "errors.hpp"
#include <boost/bind.hpp>

#include "arch/arch.hpp"
#include "arch/runtime/runtime.hpp"
#include "concurrency/wait_any.hpp"

// nap()

void nap(int64_t ms) THROWS_NOTHING {
    if (ms > 0) {
        signal_timer_t timer(ms);
        timer.wait_lazily_ordered();
    }
}

void nap(int64_t ms, signal_t *interruptor) THROWS_ONLY(interrupted_exc_t) {
    signal_timer_t timer(ms);
    wait_interruptible(&timer, interruptor);
}

// signal_timer_t

signal_timer_t::signal_timer_t(int64_t ms) : timer(NULL) {
    if (ms == 0) {
        pulse();
    } else {
        guarantee(ms > 0);
        timer = fire_timer_once(ms, this);
    }
}

signal_timer_t::~signal_timer_t() {
    if (timer) cancel_timer(timer);
}

void signal_timer_t::on_timer() {
    timer = NULL;
    pulse();
}

// repeating_timer_t

repeating_timer_t::repeating_timer_t(int64_t frequency_ms, repeating_timer_callback_t *_ringee) :
    ringee(_ringee) {
    rassert(frequency_ms > 0);
    timer = add_timer(frequency_ms, this);
}

repeating_timer_t::~repeating_timer_t() {
    cancel_timer(timer);
}

void call_ringer(repeating_timer_callback_t *ringee) {
    // It would be very easy for a user of repeating_timer_t to have
    // object lifetime errors, if their ring function blocks.  So we
    // have this assertion.
    ASSERT_FINITE_CORO_WAITING;
    ringee->on_ring();
}

{'fraction_non_alphanumeric': 0.11903137789904503, 'fraction_numerical': 0.01330150068212824, 'mean_word_length': 4.048192771084337, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3665230', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1075, 'n_words': 214}