ratelimiter.c File Reference

#include <config.h>
#include <isc/mem.h>
#include <isc/ratelimiter.h>
#include <isc/task.h>
#include <isc/time.h>
#include <isc/timer.h>
#include <isc/util.h>

Go to the source code of this file.

Data Structures

struct  isc_ratelimiter

Defines

#define ISC_RATELIMITEREVENT_SHUTDOWN   (ISC_EVENTCLASS_RATELIMITER + 1)

Enumerations

enum  isc_ratelimiter_state_t { isc_ratelimiter_stalled = 0, isc_ratelimiter_ratelimited = 1, isc_ratelimiter_idle = 2, isc_ratelimiter_shuttingdown = 3 }

Functions

static void ratelimiter_tick (isc_task_t *task, isc_event_t *event)
static void ratelimiter_shutdowncomplete (isc_task_t *task, isc_event_t *event)
isc_result_t isc_ratelimiter_create (isc_mem_t *mctx, isc_timermgr_t *timermgr, isc_task_t *task, isc_ratelimiter_t **ratelimiterp)
 Create a rate limiter. The execution interval is initially undefined.
isc_result_t isc_ratelimiter_setinterval (isc_ratelimiter_t *rl, isc_interval_t *interval)
void isc_ratelimiter_setpertic (isc_ratelimiter_t *rl, isc_uint32_t pertic)
 Set the number of events processed per interval timer tick. If 'perint' is zero it is treated as 1.
isc_result_t isc_ratelimiter_enqueue (isc_ratelimiter_t *rl, isc_task_t *task, isc_event_t **eventp)
 Queue an event for rate-limited execution.
isc_result_t isc_ratelimiter_dequeue (isc_ratelimiter_t *rl, isc_event_t *event)
void isc_ratelimiter_shutdown (isc_ratelimiter_t *rl)
 Shut down a rate limiter.
static void ratelimiter_free (isc_ratelimiter_t *rl)
void isc_ratelimiter_attach (isc_ratelimiter_t *source, isc_ratelimiter_t **target)
 Attach to a rate limiter.
void isc_ratelimiter_detach (isc_ratelimiter_t **rlp)
 Detach from a rate limiter.
isc_result_t isc_ratelimiter_stall (isc_ratelimiter_t *rl)
 Stall event processing.
isc_result_t isc_ratelimiter_release (isc_ratelimiter_t *rl)
 Release a stalled rate limiter.


Detailed Description

Definition in file ratelimiter.c.


Define Documentation

#define ISC_RATELIMITEREVENT_SHUTDOWN   (ISC_EVENTCLASS_RATELIMITER + 1)

Definition at line 51 of file ratelimiter.c.

Referenced by isc_ratelimiter_create().


Enumeration Type Documentation

enum isc_ratelimiter_state_t

Enumerator:
isc_ratelimiter_stalled 
isc_ratelimiter_ratelimited 
isc_ratelimiter_idle 
isc_ratelimiter_shuttingdown 

Definition at line 31 of file ratelimiter.c.


Function Documentation

static void ratelimiter_tick ( isc_task_t task,
isc_event_t event 
) [static]

Definition at line 194 of file ratelimiter.c.

References INSIST, isc_event_free(), ISC_FALSE, ISC_LIST_HEAD, ISC_LIST_UNLINK, ISC_R_SUCCESS, isc_ratelimiter_idle, isc_task_send(), isc_timer_reset(), isc_timertype_inactive, isc_ratelimiter::lock, LOCK, isc_ratelimiter::pertic, RUNTIME_CHECK, isc_ratelimiter::state, isc_ratelimiter::timer, UNLOCK, and UNUSED.

Referenced by isc_ratelimiter_create().

static void ratelimiter_shutdowncomplete ( isc_task_t task,
isc_event_t event 
) [static]

Definition at line 265 of file ratelimiter.c.

References isc_ratelimiter_detach(), and UNUSED.

Referenced by isc_ratelimiter_create().

isc_result_t isc_ratelimiter_create ( isc_mem_t mctx,
isc_timermgr_t timermgr,
isc_task_t task,
isc_ratelimiter_t **  ratelimiterp 
)

Create a rate limiter. The execution interval is initially undefined.

Definition at line 60 of file ratelimiter.c.

References DESTROYLOCK, INSIST, isc_ratelimiter::interval, ISC_EVENT_INIT, isc_interval_set(), ISC_LIST_INIT, isc_mem_get, isc_mem_put, isc_mutex_init, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_ratelimiter_idle, ISC_RATELIMITEREVENT_SHUTDOWN, isc_timer_create(), isc_timertype_inactive, isc_ratelimiter::lock, isc_ratelimiter::mctx, isc_ratelimiter::pertic, ratelimiter_shutdowncomplete(), ratelimiter_tick(), isc_ratelimiter::refs, isc_ratelimiter::shutdownevent, isc_ratelimiter::state, isc_ratelimiter::task, and isc_ratelimiter::timer.

Referenced by dns_zonemgr_create().

isc_result_t isc_ratelimiter_setinterval ( isc_ratelimiter_t rl,
isc_interval_t interval 
)

Set the minimum interval between event executions. The interval value is copied, so the caller need not preserve it.

Requires: '*interval' is a nonzero interval.

Definition at line 111 of file ratelimiter.c.

References isc_ratelimiter::interval, ISC_FALSE, ISC_R_SUCCESS, isc_ratelimiter_ratelimited, isc_timer_reset(), isc_timertype_ticker, isc_ratelimiter::lock, LOCK, REQUIRE, isc_ratelimiter::state, isc_ratelimiter::timer, and UNLOCK.

Referenced by setrl().

void isc_ratelimiter_setpertic ( isc_ratelimiter_t rl,
isc_uint32_t  pertic 
)

Set the number of events processed per interval timer tick. If 'perint' is zero it is treated as 1.

Definition at line 131 of file ratelimiter.c.

References isc_ratelimiter::pertic, and REQUIRE.

Referenced by setrl().

isc_result_t isc_ratelimiter_enqueue ( isc_ratelimiter_t rl,
isc_task_t task,
isc_event_t **  eventp 
)

Queue an event for rate-limited execution.

This is similar to doing an isc_task_send() to the 'task', except that the execution may be delayed to achieve the desired rate of execution.

'(*eventp)->ev_sender' is used to hold the task. The caller must ensure that the task exists until the event is delivered.

Requires:

Definition at line 141 of file ratelimiter.c.

References INSIST, isc_ratelimiter::interval, ISC_FALSE, ISC_LIST_APPEND, ISC_R_SHUTTINGDOWN, ISC_R_SUCCESS, isc_ratelimiter_idle, isc_ratelimiter_ratelimited, isc_ratelimiter_shuttingdown, isc_ratelimiter_stalled, isc_task_send(), isc_timer_reset(), isc_timertype_ticker, isc_ratelimiter::lock, LOCK, REQUIRE, isc_ratelimiter::state, isc_ratelimiter::timer, and UNLOCK.

Referenced by notify_isqueued(), notify_send_queue(), and queue_soa_query().

isc_result_t isc_ratelimiter_dequeue ( isc_ratelimiter_t rl,
isc_event_t event 
)

Definition at line 177 of file ratelimiter.c.

References ISC_LINK_LINKED, ISC_LIST_UNLINK, ISC_R_NOTFOUND, ISC_R_SUCCESS, isc_ratelimiter::lock, LOCK, REQUIRE, and UNLOCK.

Referenced by notify_isqueued().

void isc_ratelimiter_shutdown ( isc_ratelimiter_t ratelimiter  ) 

Shut down a rate limiter.

Ensures:

Definition at line 236 of file ratelimiter.c.

References ISC_EVENTATTR_CANCELED, ISC_FALSE, ISC_LIST_HEAD, ISC_LIST_UNLINK, isc_ratelimiter_shuttingdown, isc_task_send(), isc_timer_detach(), isc_timer_reset(), isc_timertype_inactive, isc_ratelimiter::lock, LOCK, REQUIRE, isc_ratelimiter::shutdownevent, isc_ratelimiter::state, isc_ratelimiter::task, isc_ratelimiter::timer, and UNLOCK.

Referenced by dns_zonemgr_shutdown().

static void ratelimiter_free ( isc_ratelimiter_t rl  )  [static]

Definition at line 274 of file ratelimiter.c.

References DESTROYLOCK, isc_mem_put, isc_ratelimiter::lock, and isc_ratelimiter::mctx.

Referenced by isc_ratelimiter_detach().

void isc_ratelimiter_attach ( isc_ratelimiter_t source,
isc_ratelimiter_t **  target 
)

Attach to a rate limiter.

Definition at line 280 of file ratelimiter.c.

References INSIST, isc_ratelimiter::lock, LOCK, isc_ratelimiter::refs, REQUIRE, and UNLOCK.

void isc_ratelimiter_detach ( isc_ratelimiter_t **  rlp  ) 

Detach from a rate limiter.

Definition at line 294 of file ratelimiter.c.

References free_now, ISC_FALSE, ISC_TRUE, isc_ratelimiter::lock, LOCK, ratelimiter_free(), isc_ratelimiter::refs, REQUIRE, and UNLOCK.

Referenced by dns_zonemgr_create(), ratelimiter_shutdowncomplete(), and zonemgr_free().

isc_result_t isc_ratelimiter_stall ( isc_ratelimiter_t rl  ) 

Stall event processing.

Definition at line 316 of file ratelimiter.c.

References ISC_FALSE, ISC_R_SHUTTINGDOWN, ISC_R_SUCCESS, isc_ratelimiter_idle, isc_ratelimiter_ratelimited, isc_ratelimiter_shuttingdown, isc_ratelimiter_stalled, isc_timer_reset(), isc_timertype_inactive, isc_ratelimiter::lock, LOCK, REQUIRE, RUNTIME_CHECK, isc_ratelimiter::state, isc_ratelimiter::timer, and UNLOCK.

isc_result_t isc_ratelimiter_release ( isc_ratelimiter_t rl  ) 

Release a stalled rate limiter.

Definition at line 341 of file ratelimiter.c.

References isc_ratelimiter::interval, ISC_FALSE, ISC_LIST_EMPTY, ISC_R_SHUTTINGDOWN, ISC_R_SUCCESS, isc_ratelimiter_idle, isc_ratelimiter_ratelimited, isc_ratelimiter_shuttingdown, isc_ratelimiter_stalled, isc_timer_reset(), isc_timertype_ticker, isc_ratelimiter::lock, LOCK, REQUIRE, isc_ratelimiter::state, isc_ratelimiter::timer, and UNLOCK.


Generated on Tue Apr 28 17:41:18 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha