Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
timeout.c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
timeout.c
Commits
7f9cf219
Commit
7f9cf219
authored
Dec 13, 2013
by
william
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
switch to TAILQs which have less branching logic, and because FreeBSD dropped CIRCLEQs altogether
parent
bed23e4a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
37 deletions
+30
-37
timer.c
timer.c
+30
-37
No files found.
timer.c
View file @
7f9cf219
...
@@ -61,24 +61,16 @@
...
@@ -61,24 +61,16 @@
#define MAX(a, b) (((a) > (b))? (a) : (b))
#define MAX(a, b) (((a) > (b))? (a) : (b))
#endif
#endif
#define CIRCLEQ_CONCAT(head1, head2, field) do { \
#if !defined TAILQ_CONCAT
if (!CIRCLEQ_EMPTY(head2)) { \
#define TAILQ_CONCAT(head1, head2, field) do { \
if (!CIRCLEQ_EMPTY(head1)) { \
if (!TAILQ_EMPTY(head2)) { \
(head1)->cqh_last->field.cqe_next = \
*(head1)->tqh_last = (head2)->tqh_first; \
(head2)->cqh_first; \
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
(head2)->cqh_first->field.cqe_prev = \
(head1)->tqh_last = (head2)->tqh_last; \
(head1)->cqh_last; \
TAILQ_INIT((head2)); \
} else { \
(head1)->cqh_first = (head2)->cqh_first; \
(head2)->cqh_first->field.cqe_prev = \
(void *)(head1); \
} \
(head1)->cqh_last = (head2)->cqh_last; \
(head2)->cqh_last->field.cqe_next = \
(void *)(head1); \
CIRCLEQ_INIT(head2); \
} \
} \
} while (0)
} while (0)
#endif
/*
/*
...
@@ -193,7 +185,7 @@ static inline wheel_t rotr(const wheel_t v, int c) {
...
@@ -193,7 +185,7 @@ static inline wheel_t rotr(const wheel_t v, int c) {
*
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
CIRCLE
Q_HEAD
(
timeout_list
,
timeout
);
TAIL
Q_HEAD
(
timeout_list
,
timeout
);
#define TIMEOUT_INITIALIZER { 0, 0, { 0, 0 } }
#define TIMEOUT_INITIALIZER { 0, 0, { 0, 0 } }
...
@@ -203,7 +195,8 @@ struct timeout {
...
@@ -203,7 +195,8 @@ struct timeout {
timeout_t
expires
;
timeout_t
expires
;
struct
timeout_list
*
pending
;
struct
timeout_list
*
pending
;
CIRCLEQ_ENTRY
(
timeout
)
cqe
;
TAILQ_ENTRY
(
timeout
)
tqe
;
};
/* struct timeout */
};
/* struct timeout */
...
@@ -236,11 +229,11 @@ static struct timeouts *timeouts_init(struct timeouts *T, timeout_t hz) {
...
@@ -236,11 +229,11 @@ static struct timeouts *timeouts_init(struct timeouts *T, timeout_t hz) {
for
(
i
=
0
;
i
<
countof
(
T
->
wheel
);
i
++
)
{
for
(
i
=
0
;
i
<
countof
(
T
->
wheel
);
i
++
)
{
for
(
j
=
0
;
j
<
countof
(
T
->
wheel
[
i
]);
j
++
)
{
for
(
j
=
0
;
j
<
countof
(
T
->
wheel
[
i
]);
j
++
)
{
CIRCLE
Q_INIT
(
&
T
->
wheel
[
i
][
j
]);
TAIL
Q_INIT
(
&
T
->
wheel
[
i
][
j
]);
}
}
}
}
CIRCLE
Q_INIT
(
&
T
->
expired
);
TAIL
Q_INIT
(
&
T
->
expired
);
for
(
i
=
0
;
i
<
countof
(
T
->
pending
);
i
++
)
{
for
(
i
=
0
;
i
<
countof
(
T
->
pending
);
i
++
)
{
T
->
pending
[
i
]
=
0
;
T
->
pending
[
i
]
=
0
;
...
@@ -255,7 +248,7 @@ static struct timeouts *timeouts_init(struct timeouts *T, timeout_t hz) {
...
@@ -255,7 +248,7 @@ static struct timeouts *timeouts_init(struct timeouts *T, timeout_t hz) {
void
timeouts_del
(
struct
timeouts
*
T
,
struct
timeout
*
to
)
{
void
timeouts_del
(
struct
timeouts
*
T
,
struct
timeout
*
to
)
{
if
(
to
->
pending
)
{
if
(
to
->
pending
)
{
if
(
to
->
pending
!=
&
T
->
expired
&&
CIRCLE
Q_EMPTY
(
to
->
pending
))
{
if
(
to
->
pending
!=
&
T
->
expired
&&
TAIL
Q_EMPTY
(
to
->
pending
))
{
ptrdiff_t
index
=
to
->
pending
-
&
T
->
wheel
[
0
][
0
];
ptrdiff_t
index
=
to
->
pending
-
&
T
->
wheel
[
0
][
0
];
int
wheel
=
index
/
WHEEL_LEN
;
int
wheel
=
index
/
WHEEL_LEN
;
int
slot
=
index
%
WHEEL_LEN
;
int
slot
=
index
%
WHEEL_LEN
;
...
@@ -263,7 +256,7 @@ void timeouts_del(struct timeouts *T, struct timeout *to) {
...
@@ -263,7 +256,7 @@ void timeouts_del(struct timeouts *T, struct timeout *to) {
T
->
pending
[
wheel
]
&=
~
(
WHEEL_C
(
1
)
<<
slot
);
T
->
pending
[
wheel
]
&=
~
(
WHEEL_C
(
1
)
<<
slot
);
}
}
CIRCLEQ_REMOVE
(
to
->
pending
,
to
,
c
qe
);
TAILQ_REMOVE
(
to
->
pending
,
to
,
t
qe
);
to
->
pending
=
NULL
;
to
->
pending
=
NULL
;
}
}
}
/* timeouts_del() */
}
/* timeouts_del() */
...
@@ -299,12 +292,12 @@ void timeouts_add(struct timeouts *T, struct timeout *to, timeout_t expires) {
...
@@ -299,12 +292,12 @@ void timeouts_add(struct timeouts *T, struct timeout *to, timeout_t expires) {
slot
=
timeout_slot
(
wheel
,
to
->
expires
);
slot
=
timeout_slot
(
wheel
,
to
->
expires
);
to
->
pending
=
&
T
->
wheel
[
wheel
][
slot
];
to
->
pending
=
&
T
->
wheel
[
wheel
][
slot
];
CIRCLEQ_INSERT_HEAD
(
to
->
pending
,
to
,
c
qe
);
TAILQ_INSERT_TAIL
(
to
->
pending
,
to
,
t
qe
);
T
->
pending
[
wheel
]
|=
WHEEL_C
(
1
)
<<
slot
;
T
->
pending
[
wheel
]
|=
WHEEL_C
(
1
)
<<
slot
;
}
else
{
}
else
{
to
->
pending
=
&
T
->
expired
;
to
->
pending
=
&
T
->
expired
;
CIRCLEQ_INSERT_HEAD
(
to
->
pending
,
to
,
c
qe
);
TAILQ_INSERT_TAIL
(
to
->
pending
,
to
,
t
qe
);
}
}
}
/* timeouts_add() */
}
/* timeouts_add() */
...
@@ -314,7 +307,7 @@ void timeouts_step(struct timeouts *T, abstime_t curtime) {
...
@@ -314,7 +307,7 @@ void timeouts_step(struct timeouts *T, abstime_t curtime) {
struct
timeout_list
todo
;
struct
timeout_list
todo
;
int
wheel
;
int
wheel
;
CIRCLE
Q_INIT
(
&
todo
);
TAIL
Q_INIT
(
&
todo
);
/*
/*
* There's no avoiding looping over every wheel. It's best to keep
* There's no avoiding looping over every wheel. It's best to keep
...
@@ -348,7 +341,7 @@ void timeouts_step(struct timeouts *T, abstime_t curtime) {
...
@@ -348,7 +341,7 @@ void timeouts_step(struct timeouts *T, abstime_t curtime) {
while
(
pending
&
T
->
pending
[
wheel
])
{
while
(
pending
&
T
->
pending
[
wheel
])
{
int
slot
=
ctz
(
pending
&
T
->
pending
[
wheel
]);
int
slot
=
ctz
(
pending
&
T
->
pending
[
wheel
]);
CIRCLEQ_CONCAT
(
&
todo
,
&
T
->
wheel
[
wheel
][
slot
],
c
qe
);
TAILQ_CONCAT
(
&
todo
,
&
T
->
wheel
[
wheel
][
slot
],
t
qe
);
T
->
pending
[
wheel
]
&=
~
(
UINT64_C
(
1
)
<<
slot
);
T
->
pending
[
wheel
]
&=
~
(
UINT64_C
(
1
)
<<
slot
);
}
}
...
@@ -361,10 +354,10 @@ void timeouts_step(struct timeouts *T, abstime_t curtime) {
...
@@ -361,10 +354,10 @@ void timeouts_step(struct timeouts *T, abstime_t curtime) {
T
->
curtime
=
curtime
;
T
->
curtime
=
curtime
;
while
(
!
CIRCLE
Q_EMPTY
(
&
todo
))
{
while
(
!
TAIL
Q_EMPTY
(
&
todo
))
{
struct
timeout
*
to
=
CIRCLE
Q_FIRST
(
&
todo
);
struct
timeout
*
to
=
TAIL
Q_FIRST
(
&
todo
);
CIRCLEQ_REMOVE
(
&
todo
,
to
,
c
qe
);
TAILQ_REMOVE
(
&
todo
,
to
,
t
qe
);
to
->
pending
=
0
;
to
->
pending
=
0
;
timeouts_add
(
T
,
to
,
to
->
expires
);
timeouts_add
(
T
,
to
,
to
->
expires
);
...
@@ -387,7 +380,7 @@ bool timeouts_pending(struct timeouts *T) {
...
@@ -387,7 +380,7 @@ bool timeouts_pending(struct timeouts *T) {
bool
timeouts_expired
(
struct
timeouts
*
T
)
{
bool
timeouts_expired
(
struct
timeouts
*
T
)
{
return
!
CIRCLE
Q_EMPTY
(
&
T
->
expired
);
return
!
TAIL
Q_EMPTY
(
&
T
->
expired
);
}
/* timeouts_expired() */
}
/* timeouts_expired() */
...
@@ -435,7 +428,7 @@ static timeout_t tms__timeout(struct timeouts *T) {
...
@@ -435,7 +428,7 @@ static timeout_t tms__timeout(struct timeouts *T) {
* processing the wheel.
* processing the wheel.
*/
*/
timeout_t
timeouts_timeout
(
struct
timeouts
*
T
)
{
timeout_t
timeouts_timeout
(
struct
timeouts
*
T
)
{
if
(
!
CIRCLE
Q_EMPTY
(
&
T
->
expired
))
if
(
!
TAIL
Q_EMPTY
(
&
T
->
expired
))
return
0
;
return
0
;
return
tms__timeout
(
T
);
return
tms__timeout
(
T
);
...
@@ -444,10 +437,10 @@ timeout_t timeouts_timeout(struct timeouts *T) {
...
@@ -444,10 +437,10 @@ timeout_t timeouts_timeout(struct timeouts *T) {
struct
timeout
*
timeouts_get
(
struct
timeouts
*
T
)
{
struct
timeout
*
timeouts_get
(
struct
timeouts
*
T
)
{
if
(
!
CIRCLE
Q_EMPTY
(
&
T
->
expired
))
{
if
(
!
TAIL
Q_EMPTY
(
&
T
->
expired
))
{
struct
timeout
*
to
=
CIRCLE
Q_FIRST
(
&
T
->
expired
);
struct
timeout
*
to
=
TAIL
Q_FIRST
(
&
T
->
expired
);
CIRCLEQ_REMOVE
(
&
T
->
expired
,
to
,
c
qe
);
TAILQ_REMOVE
(
&
T
->
expired
,
to
,
t
qe
);
to
->
pending
=
0
;
to
->
pending
=
0
;
return
to
;
return
to
;
...
@@ -467,7 +460,7 @@ static struct timeout *tms__min(struct timeouts *T) {
...
@@ -467,7 +460,7 @@ static struct timeout *tms__min(struct timeouts *T) {
for
(
i
=
0
;
i
<
countof
(
T
->
wheel
);
i
++
)
{
for
(
i
=
0
;
i
<
countof
(
T
->
wheel
);
i
++
)
{
for
(
j
=
0
;
j
<
countof
(
T
->
wheel
[
i
]);
j
++
)
{
for
(
j
=
0
;
j
<
countof
(
T
->
wheel
[
i
]);
j
++
)
{
CIRCLEQ_FOREACH
(
to
,
&
T
->
wheel
[
i
][
j
],
c
qe
)
{
TAILQ_FOREACH
(
to
,
&
T
->
wheel
[
i
][
j
],
t
qe
)
{
if
(
!
min
||
to
->
expires
<
min
->
expires
)
if
(
!
min
||
to
->
expires
<
min
->
expires
)
min
=
to
;
min
=
to
;
}
}
...
@@ -509,7 +502,7 @@ bool timeouts_check(struct timeouts *T, FILE *fp) {
...
@@ -509,7 +502,7 @@ bool timeouts_check(struct timeouts *T, FILE *fp) {
}
else
{
}
else
{
timeout
=
timeouts_timeout
(
T
);
timeout
=
timeouts_timeout
(
T
);
if
(
!
CIRCLE
Q_EMPTY
(
&
T
->
expired
))
if
(
!
TAIL
Q_EMPTY
(
&
T
->
expired
))
check
(
timeout
==
0
,
"wrong soft timeout (soft:%"
TIMEOUT_PRIu
" != hard:%"
TIMEOUT_PRIu
")
\n
"
,
timeout
,
TIMEOUT_C
(
0
));
check
(
timeout
==
0
,
"wrong soft timeout (soft:%"
TIMEOUT_PRIu
" != hard:%"
TIMEOUT_PRIu
")
\n
"
,
timeout
,
TIMEOUT_C
(
0
));
else
else
check
(
timeout
==
~
TIMEOUT_C
(
0
),
"wrong soft timeout (soft:%"
TIMEOUT_PRIu
" != hard:%"
TIMEOUT_PRIu
")
\n
"
,
timeout
,
~
TIMEOUT_C
(
0
));
check
(
timeout
==
~
TIMEOUT_C
(
0
),
"wrong soft timeout (soft:%"
TIMEOUT_PRIu
" != hard:%"
TIMEOUT_PRIu
")
\n
"
,
timeout
,
~
TIMEOUT_C
(
0
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment