Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
4ed4ff95
Commit
4ed4ff95
authored
Jan 18, 2014
by
Eugene Zhuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix shutting down FastClock's thread on OSX.
parent
d184b2be
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
5 deletions
+28
-5
benchmark.cc
src/benchmark.cc
+28
-5
No files found.
src/benchmark.cc
View file @
4ed4ff95
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#include "sysinfo.h"
#include "sysinfo.h"
#include "walltime.h"
#include "walltime.h"
#include <sys/time.h>
#include <pthread.h>
#include <pthread.h>
#include <semaphore.h>
#include <semaphore.h>
#include <string.h>
#include <string.h>
...
@@ -443,14 +444,19 @@ class State::FastClock {
...
@@ -443,14 +444,19 @@ class State::FastClock {
CPU_TIME
CPU_TIME
};
};
explicit
FastClock
(
Type
type
)
:
type_
(
type
),
approx_time_
(
NowMicros
())
{
explicit
FastClock
(
Type
type
)
:
type_
(
type
),
approx_time_
(
NowMicros
())
{
sem_init
(
&
bg_done_
,
0
,
0
);
pthread_cond_init
(
&
bg_cond_
,
0
);
pthread_mutex_init
(
&
bg_mutex_
,
0
);
pthread_create
(
&
bg_
,
NULL
,
&
BGThreadWrapper
,
this
);
pthread_create
(
&
bg_
,
NULL
,
&
BGThreadWrapper
,
this
);
}
}
~
FastClock
()
{
~
FastClock
()
{
sem_post
(
&
bg_done_
);
{
mutex_lock
l
(
&
bg_mutex_
);
pthread_cond_signal
(
&
bg_cond_
);
}
pthread_join
(
bg_
,
NULL
);
pthread_join
(
bg_
,
NULL
);
sem_destroy
(
&
bg_done_
);
pthread_mutex_destroy
(
&
bg_mutex_
);
pthread_cond_destroy
(
&
bg_cond_
);
}
}
// Returns true if the current time is guaranteed to be past "when_micros".
// Returns true if the current time is guaranteed to be past "when_micros".
...
@@ -489,7 +495,8 @@ class State::FastClock {
...
@@ -489,7 +495,8 @@ class State::FastClock {
std
::
atomic
<
int64_t
>
approx_time_
;
// Last time measurement taken by bg_
std
::
atomic
<
int64_t
>
approx_time_
;
// Last time measurement taken by bg_
pthread_t
bg_
;
// Background thread that updates last_time_ once every ms
pthread_t
bg_
;
// Background thread that updates last_time_ once every ms
sem_t
bg_done_
;
pthread_mutex_t
bg_mutex_
;
pthread_cond_t
bg_cond_
;
static
void
*
BGThreadWrapper
(
void
*
that
)
{
static
void
*
BGThreadWrapper
(
void
*
that
)
{
((
FastClock
*
)
that
)
->
BGThread
();
((
FastClock
*
)
that
)
->
BGThread
();
...
@@ -503,7 +510,23 @@ class State::FastClock {
...
@@ -503,7 +510,23 @@ class State::FastClock {
std
::
atomic_store
(
&
approx_time_
,
NowMicros
());
std
::
atomic_store
(
&
approx_time_
,
NowMicros
());
// NOTE: same code but no memory barrier. think on it.
// NOTE: same code but no memory barrier. think on it.
// base::subtle::Release_Store(&approx_time_, NowMicros());
// base::subtle::Release_Store(&approx_time_, NowMicros());
sem_getvalue
(
&
bg_done_
,
&
done
);
{
struct
timeval
tv
;
gettimeofday
(
&
tv
,
0
);
// Set timeout to 100 ms.
long
const
timeout
=
100000
;
struct
timespec
ts
;
ts
.
tv_sec
=
tv
.
tv_sec
+
(
timeout
/
1000000
);
ts
.
tv_nsec
=
(
tv
.
tv_usec
+
(
timeout
%
1000000
))
*
1000
;
ts
.
tv_sec
+=
ts
.
tv_nsec
/
1000000000
;
ts
.
tv_nsec
%=
1000000000
;
// NOTE: this should probably be platform specific.
mutex_lock
l
(
&
bg_mutex_
);
if
(
0
==
pthread_cond_timedwait
(
&
bg_cond_
,
&
bg_mutex_
,
&
ts
))
done
=
1
;
}
}
while
(
done
==
0
);
}
while
(
done
==
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