Lines Matching refs:rl
64 isc_ratelimiter_t *rl;
67 rl = isc_mem_get(mctx, sizeof(*rl));
68 if (rl == NULL)
70 rl->mctx = mctx;
71 rl->refs = 1;
72 rl->task = task;
73 isc_interval_set(&rl->interval, 0, 0);
74 rl->timer = NULL;
75 rl->pertic = 1;
76 rl->state = isc_ratelimiter_idle;
77 ISC_LIST_INIT(rl->pending);
79 result = isc_mutex_init(&rl->lock);
83 NULL, NULL, rl->task, ratelimiter_tick,
84 rl, &rl->timer);
92 rl->refs++;
94 ISC_EVENT_INIT(&rl->shutdownevent,
97 ratelimiter_shutdowncomplete, rl, rl, NULL, NULL);
99 *ratelimiterp = rl;
103 DESTROYLOCK(&rl->lock);
105 isc_mem_put(mctx, rl, sizeof(*rl));
110 isc_ratelimiter_setinterval(isc_ratelimiter_t *rl, isc_interval_t *interval) {
112 LOCK(&rl->lock);
113 rl->interval = *interval;
117 if (rl->state == isc_ratelimiter_ratelimited) {
118 result = isc_timer_reset(rl->timer, isc_timertype_ticker, NULL,
119 &rl->interval, ISC_FALSE);
121 UNLOCK(&rl->lock);
126 isc_ratelimiter_setpertic(isc_ratelimiter_t *rl, isc_uint32_t pertic) {
129 rl->pertic = pertic;
133 isc_ratelimiter_enqueue(isc_ratelimiter_t *rl, isc_task_t *task,
144 LOCK(&rl->lock);
145 if (rl->state == isc_ratelimiter_ratelimited ||
146 rl->state == isc_ratelimiter_stalled) {
149 ISC_LIST_APPEND(rl->pending, ev, ev_link);
151 } else if (rl->state == isc_ratelimiter_idle) {
152 result = isc_timer_reset(rl->timer, isc_timertype_ticker, NULL,
153 &rl->interval, ISC_FALSE);
156 rl->state = isc_ratelimiter_ratelimited;
159 INSIST(rl->state == isc_ratelimiter_shuttingdown);
162 UNLOCK(&rl->lock);
171 isc_ratelimiter_t *rl = (isc_ratelimiter_t *)event->ev_arg;
179 pertic = rl->pertic;
182 LOCK(&rl->lock);
183 p = ISC_LIST_HEAD(rl->pending);
188 ISC_LIST_UNLINK(rl->pending, p, ev_link);
194 result = isc_timer_reset(rl->timer,
198 rl->state = isc_ratelimiter_idle;
201 UNLOCK(&rl->lock);
211 isc_ratelimiter_shutdown(isc_ratelimiter_t *rl) {
214 LOCK(&rl->lock);
215 rl->state = isc_ratelimiter_shuttingdown;
216 (void)isc_timer_reset(rl->timer, isc_timertype_inactive,
218 while ((ev = ISC_LIST_HEAD(rl->pending)) != NULL) {
219 ISC_LIST_UNLINK(rl->pending, ev, ev_link);
224 isc_timer_detach(&rl->timer);
229 ev = &rl->shutdownevent;
230 isc_task_send(rl->task, &ev);
232 UNLOCK(&rl->lock);
237 isc_ratelimiter_t *rl = (isc_ratelimiter_t *)event->ev_arg;
241 isc_ratelimiter_detach(&rl);
245 ratelimiter_free(isc_ratelimiter_t *rl) {
246 DESTROYLOCK(&rl->lock);
247 isc_mem_put(rl->mctx, rl, sizeof(*rl));
265 isc_ratelimiter_t *rl = *rlp;
268 LOCK(&rl->lock);
269 REQUIRE(rl->refs > 0);
270 rl->refs--;
271 if (rl->refs == 0)
273 UNLOCK(&rl->lock);
276 ratelimiter_free(rl);
282 isc_ratelimiter_stall(isc_ratelimiter_t *rl) {
285 LOCK(&rl->lock);
286 switch (rl->state) {
291 result = isc_timer_reset(rl->timer, isc_timertype_inactive,
297 rl->state = isc_ratelimiter_stalled;
300 UNLOCK(&rl->lock);
305 isc_ratelimiter_release(isc_ratelimiter_t *rl) {
308 LOCK(&rl->lock);
309 switch (rl->state) {
314 if (!ISC_LIST_EMPTY(rl->pending)) {
315 result = isc_timer_reset(rl->timer,
317 &rl->interval, ISC_FALSE);
319 rl->state = isc_ratelimiter_ratelimited;
321 rl->state = isc_ratelimiter_idle;
327 UNLOCK(&rl->lock);