3
Queue of Events sorted by the "at_timeout" field
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
24
#ifndef _I_PriorityEventQueue_h_
25
#define _I_PriorityEventQueue_h_
28
#include "I_ProxyAllocator.h"
32
// <5ms, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120
34
#define PQ_BUCKET_TIME(_i) (HRTIME_MSECONDS(5) << (_i))
38
struct PriorityEventQueue
41
Que(Event, link) after[N_PQ_LIST];
42
ink_hrtime last_check_time;
43
uint32_t last_check_buckets;
45
void enqueue(Event * e, ink_hrtime now)
47
ink_hrtime t = e->timeout_at - now;
49
// equivalent but faster
50
if (t <= PQ_BUCKET_TIME(3))
52
if (t <= PQ_BUCKET_TIME(1)) {
53
if (t <= PQ_BUCKET_TIME(0)) {
60
if (t <= PQ_BUCKET_TIME(2)) {
67
if (t <= PQ_BUCKET_TIME(7)) {
68
if (t <= PQ_BUCKET_TIME(5)) {
69
if (t <= PQ_BUCKET_TIME(4)) {
75
if (t <= PQ_BUCKET_TIME(6)) {
82
if (t <= PQ_BUCKET_TIME(8)) {
89
e->in_the_priority_queue = 1;
94
void remove(Event * e)
96
ink_assert(e->in_the_priority_queue);
97
e->in_the_priority_queue = 0;
98
after[e->in_heap].remove(e);
101
Event *dequeue_ready(ink_hrtime t)
104
Event *e = after[0].dequeue();
106
ink_assert(e->in_the_priority_queue);
107
e->in_the_priority_queue = 0;
112
void check_ready(ink_hrtime now, EThread * t);
114
ink_hrtime earliest_timeout()
116
for (int i = 0; i < N_PQ_LIST; i++) {
118
return last_check_time + (PQ_BUCKET_TIME(i) / 2);
120
return last_check_time + HRTIME_FOREVER;
123
PriorityEventQueue();