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
273e79a5
Commit
273e79a5
authored
Feb 02, 2014
by
william
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some issues
parent
7a7f63a8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
16 deletions
+23
-16
bench-llrb.c
bench-llrb.c
+13
-6
bench.c
bench.c
+10
-10
No files found.
bench-llrb.c
View file @
273e79a5
...
@@ -316,16 +316,17 @@ struct rbtimeouts {
...
@@ -316,16 +316,17 @@ struct rbtimeouts {
static
int
timeoutcmp
(
struct
rbtimeout
*
a
,
struct
rbtimeout
*
b
)
{
static
int
timeoutcmp
(
struct
rbtimeout
*
a
,
struct
rbtimeout
*
b
)
{
if
(
a
->
expires
<
b
->
expires
)
if
(
a
->
expires
<
b
->
expires
)
{
return
-
1
;
return
-
1
;
else
if
(
a
->
expires
>
b
->
expires
)
}
else
if
(
a
->
expires
>
b
->
expires
)
{
return
1
;
return
1
;
else
if
(
a
<
b
)
}
else
if
(
a
<
b
)
{
return
-
1
;
return
-
1
;
else
if
(
a
>
b
)
}
else
if
(
a
>
b
)
{
return
1
;
return
1
;
else
}
else
{
return
0
;
return
0
;
}
}
/* timeoutcmp() */
}
/* timeoutcmp() */
LLRB_GENERATE_STATIC
(
tree
,
rbtimeout
,
rbe
,
timeoutcmp
)
LLRB_GENERATE_STATIC
(
tree
,
rbtimeout
,
rbe
,
timeoutcmp
)
...
@@ -335,6 +336,7 @@ static void *init(struct timeout *timeout, size_t count, int verbose) {
...
@@ -335,6 +336,7 @@ static void *init(struct timeout *timeout, size_t count, int verbose) {
size_t
i
;
size_t
i
;
T
=
malloc
(
sizeof
*
T
);
T
=
malloc
(
sizeof
*
T
);
T
->
curtime
=
0
;
LLRB_INIT
(
&
T
->
tree
);
LLRB_INIT
(
&
T
->
tree
);
for
(
i
=
0
;
i
<
count
;
i
++
)
{
for
(
i
=
0
;
i
<
count
;
i
++
)
{
...
@@ -351,9 +353,12 @@ static void add(void *ctx, struct timeout *_to, timeout_t expires) {
...
@@ -351,9 +353,12 @@ static void add(void *ctx, struct timeout *_to, timeout_t expires) {
struct
rbtimeouts
*
T
=
ctx
;
struct
rbtimeouts
*
T
=
ctx
;
struct
rbtimeout
*
to
=
(
void
*
)
_to
;
struct
rbtimeout
*
to
=
(
void
*
)
_to
;
if
(
to
->
pending
)
LLRB_REMOVE
(
tree
,
&
T
->
tree
,
to
);
to
->
expires
=
T
->
curtime
+
expires
;
to
->
expires
=
T
->
curtime
+
expires
;
LLRB_INSERT
(
tree
,
&
T
->
tree
,
to
);
LLRB_INSERT
(
tree
,
&
T
->
tree
,
to
);
to
->
pending
=
0
;
to
->
pending
=
1
;
}
/* add() */
}
/* add() */
...
@@ -363,6 +368,7 @@ static void del(void *ctx, struct timeout *_to) {
...
@@ -363,6 +368,7 @@ static void del(void *ctx, struct timeout *_to) {
LLRB_REMOVE
(
tree
,
&
T
->
tree
,
to
);
LLRB_REMOVE
(
tree
,
&
T
->
tree
,
to
);
to
->
pending
=
0
;
to
->
pending
=
0
;
to
->
expires
=
0
;
}
/* del() */
}
/* del() */
...
@@ -373,6 +379,7 @@ static struct timeout *get(void *ctx) {
...
@@ -373,6 +379,7 @@ static struct timeout *get(void *ctx) {
if
((
to
=
LLRB_MIN
(
tree
,
&
T
->
tree
))
&&
to
->
expires
<=
T
->
curtime
)
{
if
((
to
=
LLRB_MIN
(
tree
,
&
T
->
tree
))
&&
to
->
expires
<=
T
->
curtime
)
{
LLRB_REMOVE
(
tree
,
&
T
->
tree
,
to
);
LLRB_REMOVE
(
tree
,
&
T
->
tree
,
to
);
to
->
pending
=
0
;
to
->
pending
=
0
;
to
->
expires
=
0
;
return
(
void
*
)
to
;
return
(
void
*
)
to
;
}
}
...
...
bench.c
View file @
273e79a5
...
@@ -29,19 +29,19 @@ struct bench {
...
@@ -29,19 +29,19 @@ struct bench {
struct
benchops
ops
;
struct
benchops
ops
;
timeout_t
curtime
;
timeout_t
curtime
;
#if __APPLE__
mach_timebase_info_data_t
timebase
;
#endif
};
/* struct bench */
};
/* struct bench */
#if __APPLE__
static
mach_timebase_info_data_t
timebase
;
#endif
static
int
bench_clock
(
lua_State
*
L
)
{
static
int
bench_clock
(
lua_State
*
L
)
{
#if __APPLE__
#if __APPLE__
struct
bench
*
B
=
lua_touserdata
(
L
,
1
);
unsigned
long
long
abt
;
unsigned
long
long
abt
;
abt
=
mach_absolute_time
();
abt
=
mach_absolute_time
();
abt
=
abt
*
B
->
timebase
.
numer
/
B
->
timebase
.
denom
;
abt
=
abt
*
timebase
.
numer
/
timebase
.
denom
;
lua_pushnumber
(
L
,
(
double
)
abt
/
1000000000L
);
lua_pushnumber
(
L
,
(
double
)
abt
/
1000000000L
);
#else
#else
...
@@ -67,10 +67,6 @@ static int bench_new(lua_State *L) {
...
@@ -67,10 +67,6 @@ static int bench_new(lua_State *L) {
B
=
lua_newuserdata
(
L
,
sizeof
*
B
);
B
=
lua_newuserdata
(
L
,
sizeof
*
B
);
memset
(
B
,
0
,
sizeof
*
B
);
memset
(
B
,
0
,
sizeof
*
B
);
#if __APPLE__
mach_timebase_info
(
&
B
->
timebase
);
#endif
luaL_getmetatable
(
L
,
"BENCH*"
);
luaL_getmetatable
(
L
,
"BENCH*"
);
lua_setmetatable
(
L
,
-
2
);
lua_setmetatable
(
L
,
-
2
);
...
@@ -160,7 +156,7 @@ static int bench__gc(lua_State *L) {
...
@@ -160,7 +156,7 @@ static int bench__gc(lua_State *L) {
}
}
return
0
;
return
0
;
}
/* bench_
expire
() */
}
/* bench_
_gc
() */
static
const
luaL_Reg
bench_methods
[]
=
{
static
const
luaL_Reg
bench_methods
[]
=
{
...
@@ -184,6 +180,10 @@ static const luaL_Reg bench_globals[] = {
...
@@ -184,6 +180,10 @@ static const luaL_Reg bench_globals[] = {
};
};
int
luaopen_bench
(
lua_State
*
L
)
{
int
luaopen_bench
(
lua_State
*
L
)
{
#if __APPLE__
mach_timebase_info
(
&
timebase
);
#endif
if
(
luaL_newmetatable
(
L
,
"BENCH*"
))
{
if
(
luaL_newmetatable
(
L
,
"BENCH*"
))
{
luaL_register
(
L
,
NULL
,
bench_metatable
);
luaL_register
(
L
,
NULL
,
bench_metatable
);
lua_newtable
(
L
);
lua_newtable
(
L
);
...
...
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