tor  0.4.1.0-alpha-dev
Functions | Variables
periodic.c File Reference
#include "core/or/or.h"
#include "lib/evloop/compat_libevent.h"
#include "app/config/config.h"
#include "core/mainloop/mainloop.h"
#include "core/mainloop/periodic.h"

Go to the source code of this file.

Functions

static void periodic_event_set_interval (periodic_event_item_t *event, time_t next_interval)
 
static void periodic_event_dispatch (mainloop_event_t *ev, void *data)
 
void periodic_event_reschedule (periodic_event_item_t *event)
 
void periodic_event_setup (periodic_event_item_t *event)
 
void periodic_event_launch (periodic_event_item_t *event)
 
void periodic_event_destroy (periodic_event_item_t *event)
 
void periodic_event_enable (periodic_event_item_t *event)
 
void periodic_event_disable (periodic_event_item_t *event)
 
void periodic_event_schedule_and_disable (periodic_event_item_t *event)
 

Variables

static const int MAX_INTERVAL = 10 * 365 * 86400
 

Detailed Description

Generic backend for handling periodic events.

The events in this module are used by main.c to track items that need to fire once every N seconds, possibly picking a new interval each time that they fire. See periodic_events[] in main.c for examples.

Definition in file periodic.c.

Function Documentation

◆ periodic_event_destroy()

void periodic_event_destroy ( periodic_event_item_t event)

Release all storage associated with event

Definition at line 132 of file periodic.c.

◆ periodic_event_disable()

void periodic_event_disable ( periodic_event_item_t event)

Disable the given event which means the event is destroyed and then the event's enabled flag is unset. This can be called for an event that is already disabled.

Definition at line 161 of file periodic.c.

References periodic_event_item_t::ev, mainloop_event_cancel(), and tor_assert().

Referenced by periodic_event_schedule_and_disable().

◆ periodic_event_dispatch()

static void periodic_event_dispatch ( mainloop_event_t ev,
void *  data 
)
static

Wraps dispatches for periodic events, data will be a pointer to the event that needs to be called

Definition at line 43 of file periodic.c.

References tor_assert(), and update_current_time().

◆ periodic_event_enable()

void periodic_event_enable ( periodic_event_item_t event)

Enable the given event by setting its "enabled" flag and scheduling it to run immediately in the event loop. This can be called for an event that is already enabled.

Definition at line 144 of file periodic.c.

References periodic_event_item_t::ev, mainloop_event_activate(), and tor_assert().

◆ periodic_event_launch()

void periodic_event_launch ( periodic_event_item_t event)

Handles initial dispatch for periodic events. It should happen 1 second after the events are created to mimic behaviour before #3199's refactor

Definition at line 113 of file periodic.c.

References periodic_event_item_t::ev.

◆ periodic_event_reschedule()

void periodic_event_reschedule ( periodic_event_item_t event)

Schedules event to run as soon as possible from now.

Definition at line 88 of file periodic.c.

References periodic_event_set_interval().

◆ periodic_event_schedule_and_disable()

void periodic_event_schedule_and_disable ( periodic_event_item_t event)

Disable an event, then schedule it to run once. Do nothing if the event was already disabled.

Definition at line 177 of file periodic.c.

References periodic_event_item_t::ev, mainloop_event_activate(), periodic_event_disable(), and tor_assert().

◆ periodic_event_set_interval()

static void periodic_event_set_interval ( periodic_event_item_t event,
time_t  next_interval 
)
static

Set the event event to run in next_interval seconds from now.

Definition at line 30 of file periodic.c.

References periodic_event_item_t::ev, mainloop_event_schedule(), MAX_INTERVAL, and tor_assert().

Referenced by periodic_event_reschedule().

◆ periodic_event_setup()

void periodic_event_setup ( periodic_event_item_t event)

Initializes the libevent backend for a periodic event.

Definition at line 98 of file periodic.c.

References periodic_event_item_t::ev.

Variable Documentation

◆ MAX_INTERVAL

const int MAX_INTERVAL = 10 * 365 * 86400
static

We disable any interval greater than this number of seconds, on the grounds that it is probably an absolute time mistakenly passed in as a relative time.

Definition at line 25 of file periodic.c.

Referenced by periodic_event_set_interval().