Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
folly
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
Libraries
folly
Commits
2171293f
Commit
2171293f
authored
Sep 16, 2015
by
Lucian Grijincu
Committed by
facebook-github-bot-9
Sep 16, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
folly: clock: remove static globals, replace with meyers singleton
Reviewed By: @yfeldblum Differential Revision: D2446000
parent
99eb3f45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
6 deletions
+17
-6
folly/detail/Clock.cpp
folly/detail/Clock.cpp
+17
-6
No files found.
folly/detail/Clock.cpp
View file @
2171293f
...
...
@@ -20,17 +20,27 @@
#include <errno.h>
#include <mach/mach_time.h>
static
mach_timebase_info_data_t
tb_info
;
static
bool
tb_init
=
mach_timebase_info
(
&
tb_info
)
==
KERN_SUCCESS
;
namespace
{
const
mach_timebase_info_data_t
*
tbInfo
()
{
static
auto
info
=
[]
{
static
mach_timebase_info_data_t
info
;
return
(
mach_timebase_info
(
&
info
)
==
KERN_SUCCESS
)
?
&
info
:
nullptr
;
}();
return
info
;
};
}
// anonymous namespace
int
clock_gettime
(
clockid_t
clk_id
,
struct
timespec
*
ts
)
{
if
(
!
tb_init
)
{
auto
tb_info
=
tbInfo
();
if
(
tb_info
==
nullptr
)
{
errno
=
EINVAL
;
return
-
1
;
}
uint64_t
now_ticks
=
mach_absolute_time
();
uint64_t
now_ns
=
(
now_ticks
*
tb_info
.
numer
)
/
tb_info
.
denom
;
uint64_t
now_ns
=
(
now_ticks
*
tb_info
->
numer
)
/
tb_info
->
denom
;
ts
->
tv_sec
=
now_ns
/
1000000000
;
ts
->
tv_nsec
=
now_ns
%
1000000000
;
...
...
@@ -38,13 +48,14 @@ int clock_gettime(clockid_t clk_id, struct timespec* ts) {
}
int
clock_getres
(
clockid_t
clk_id
,
struct
timespec
*
ts
)
{
if
(
!
tb_init
)
{
auto
tb_info
=
tbInfo
();
if
(
tb_info
==
nullptr
)
{
errno
=
EINVAL
;
return
-
1
;
}
ts
->
tv_sec
=
0
;
ts
->
tv_nsec
=
tb_info
.
numer
/
tb_info
.
denom
;
ts
->
tv_nsec
=
tb_info
->
numer
/
tb_info
->
denom
;
return
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