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
258ac288
Commit
258ac288
authored
Jan 03, 2014
by
william
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move timeouts_addf to macro
parent
a87ff8f7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
11 deletions
+28
-11
timeout.c
timeout.c
+0
-7
timeout.h
timeout.h
+28
-4
No files found.
timeout.c
View file @
258ac288
...
@@ -31,8 +31,6 @@
...
@@ -31,8 +31,6 @@
#include <inttypes.h>
/* UINT64_C uint64_t */
#include <inttypes.h>
/* UINT64_C uint64_t */
#include <math.h>
/* ceil(3) */
#include <string.h>
/* memset(3) */
#include <string.h>
/* memset(3) */
#include <errno.h>
/* errno */
#include <errno.h>
/* errno */
...
@@ -370,11 +368,6 @@ TIMEOUT_PUBLIC void timeouts_add(struct timeouts *T, struct timeout *to, timeout
...
@@ -370,11 +368,6 @@ TIMEOUT_PUBLIC void timeouts_add(struct timeouts *T, struct timeout *to, timeout
}
/* timeouts_add() */
}
/* timeouts_add() */
TIMEOUT_PUBLIC
void
timeouts_addf
(
struct
timeouts
*
T
,
struct
timeout
*
to
,
double
timeout
)
{
timeouts_add
(
T
,
to
,
ceil
(
timeout
*
T
->
hertz
));
}
/* timeouts_addf() */
TIMEOUT_PUBLIC
void
timeouts_update
(
struct
timeouts
*
T
,
abstime_t
curtime
)
{
TIMEOUT_PUBLIC
void
timeouts_update
(
struct
timeouts
*
T
,
abstime_t
curtime
)
{
timeout_t
elapsed
=
curtime
-
T
->
curtime
;
timeout_t
elapsed
=
curtime
-
T
->
curtime
;
struct
timeout_list
todo
;
struct
timeout_list
todo
;
...
...
timeout.h
View file @
258ac288
...
@@ -77,6 +77,8 @@ TIMEOUT_PUBLIC int timeout_v_api(void);
...
@@ -77,6 +77,8 @@ TIMEOUT_PUBLIC int timeout_v_api(void);
typedef
uint64_t
timeout_t
;
typedef
uint64_t
timeout_t
;
#define timeout_error_t int
/* for documentation purposes */
/*
/*
* C A L L B A C K I N T E R F A C E
* C A L L B A C K I N T E R F A C E
...
@@ -147,7 +149,7 @@ TIMEOUT_PUBLIC void timeout_del(struct timeout *);
...
@@ -147,7 +149,7 @@ TIMEOUT_PUBLIC void timeout_del(struct timeout *);
struct
timeouts
;
struct
timeouts
;
TIMEOUT_PUBLIC
struct
timeouts
*
timeouts_open
(
timeout_t
,
in
t
*
);
TIMEOUT_PUBLIC
struct
timeouts
*
timeouts_open
(
timeout_t
,
timeout_error_
t
*
);
/* open a new timing wheel, setting optional HZ (for float conversions) */
/* open a new timing wheel, setting optional HZ (for float conversions) */
TIMEOUT_PUBLIC
void
timeouts_close
(
struct
timeouts
*
);
TIMEOUT_PUBLIC
void
timeouts_close
(
struct
timeouts
*
);
...
@@ -168,12 +170,12 @@ TIMEOUT_PUBLIC timeout_t timeouts_timeout(struct timeouts *);
...
@@ -168,12 +170,12 @@ TIMEOUT_PUBLIC timeout_t timeouts_timeout(struct timeouts *);
TIMEOUT_PUBLIC
void
timeouts_add
(
struct
timeouts
*
,
struct
timeout
*
,
timeout_t
);
TIMEOUT_PUBLIC
void
timeouts_add
(
struct
timeouts
*
,
struct
timeout
*
,
timeout_t
);
/* add timeout to timing wheel */
/* add timeout to timing wheel */
TIMEOUT_PUBLIC
void
timeouts_addf
(
struct
timeouts
*
,
struct
timeout
*
,
double
);
/* add timeout to timing wheel, translating floating point timeout */
TIMEOUT_PUBLIC
void
timeouts_del
(
struct
timeouts
*
,
struct
timeout
*
);
TIMEOUT_PUBLIC
void
timeouts_del
(
struct
timeouts
*
,
struct
timeout
*
);
/* remove timeout from any timing wheel or expired queue (okay if on neither) */
/* remove timeout from any timing wheel or expired queue (okay if on neither) */
TIMEOUT_PUBLIC
struct
timeout
*
timeouts_get
(
struct
timeouts
*
);
/* return any expired timeout (caller should loop until NULL-return) */
TIMEOUT_PUBLIC
bool
timeouts_pending
(
struct
timeouts
*
);
TIMEOUT_PUBLIC
bool
timeouts_pending
(
struct
timeouts
*
);
/* return true if any timeouts pending on timing wheel */
/* return true if any timeouts pending on timing wheel */
...
@@ -184,4 +186,26 @@ TIMEOUT_PUBLIC bool timeouts_check(struct timeouts *, FILE *);
...
@@ -184,4 +186,26 @@ TIMEOUT_PUBLIC bool timeouts_check(struct timeouts *, FILE *);
/* return true if invariants hold. describes failures to optional file handle. */
/* return true if invariants hold. describes failures to optional file handle. */
/*
* B O N U S W H E E L I N T E R F A C E S
*
* I usually use floating point timeouts in all my code, but it's cleaner to
* separate it to keep the core algorithmic code simple.
*
* Using macros instead of static inline routines where <math.h> routines
* might be used to keep -lm linking optional.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <math.h>
/* ceil(3) */
#define timeouts_f2i(T, f) \
(ceil((f) * timeouts_hz((T))))
/* prefer late expiration over early */
#define timeouts_i2f(T, i) \
((i) / timeouts_hz((T)))
#define timeouts_addf(T, to, timeout) \
timeouts_add((T), (to), timeouts_f2i((T), (timeout)))
#endif
/* TIMEOUT_H */
#endif
/* TIMEOUT_H */
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