ratelimiter.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 1999-2002, 2004, 2005, 2007, 2012, 2014-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: ratelimiter.c,v 1.25 2007/06/19 23:47:17 tbox Exp $ */
/*! \file */
#include <config.h>
#include <isc/ratelimiter.h>
typedef enum {
isc_ratelimiter_idle = 2,
struct isc_ratelimiter {
int refs;
isc_task_t * task;
isc_timer_t * timer;
};
static void
static void
{
return ISC_R_NOMEMORY;
if (result != ISC_R_SUCCESS)
goto free_mem;
if (result != ISC_R_SUCCESS)
goto free_mutex;
/*
* Increment the reference count to indicate that we may
* (soon) have events outstanding.
*/
sizeof(isc_event_t),
*ratelimiterp = rl;
return (ISC_R_SUCCESS);
return (result);
}
/*
* If the timer is currently running, change its rate.
*/
}
return (result);
}
void
if (pertic == 0)
pertic = 1;
}
{
if (result == ISC_R_SUCCESS) {
}
} else {
}
return (result);
}
} else
return (result);
}
static void
isc_event_t *p;
while (pertic != 0) {
pertic--;
if (p != NULL) {
/*
* There is work to do. Let's do it after unlocking.
*/
} else {
/*
* No work left to do. Stop the timer so that we don't
* waste resources by having it fire periodically.
*/
pertic = 0; /* Force the loop to exit. */
}
if (p != NULL) {
isc_task_send(evtask, &p);
}
}
}
void
}
/*
* Send an event to our task. The delivery of this event
* indicates that no more timer events will be delivered.
*/
}
static void
}
static void
}
void
}
void
if (free_now)
}
break;
/* FALLTHROUGH */
case isc_ratelimiter_idle:
case isc_ratelimiter_stalled:
break;
}
return (result);
}
break;
case isc_ratelimiter_stalled:
if (result == ISC_R_SUCCESS)
} else
break;
case isc_ratelimiter_idle:
break;
}
return (result);
}