Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
0bd7b221
Commit
0bd7b221
authored
Jun 22, 2019
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace all uses of std::chrono with KJ clock APIs.
parent
36b91bdb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
31 deletions
+18
-31
async-unix.c++
c++/src/kj/async-unix.c++
+9
-16
async-unix.h
c++/src/kj/async-unix.h
+1
-1
async-win32.c++
c++/src/kj/async-win32.c++
+5
-9
async-win32.h
c++/src/kj/async-win32.h
+2
-2
test.c++
c++/src/kj/test.c++
+1
-3
No files found.
c++/src/kj/async-unix.c++
View file @
0bd7b221
...
...
@@ -28,7 +28,6 @@
#include <errno.h>
#include <inttypes.h>
#include <limits>
#include <chrono>
#include <pthread.h>
#include <map>
#include <sys/wait.h>
...
...
@@ -44,14 +43,6 @@
namespace
kj
{
// =======================================================================================
// Timer code common to multiple implementations
TimePoint
UnixEventPort
::
readClock
()
{
return
origin
<
TimePoint
>
()
+
std
::
chrono
::
duration_cast
<
std
::
chrono
::
nanoseconds
>
(
std
::
chrono
::
steady_clock
::
now
().
time_since_epoch
()).
count
()
*
NANOSECONDS
;
}
// =======================================================================================
// Signal code common to multiple implementations
...
...
@@ -284,7 +275,8 @@ void UnixEventPort::gotSignal(const siginfo_t& siginfo) {
// epoll FdObserver implementation
UnixEventPort
::
UnixEventPort
()
:
timerImpl
(
readClock
()),
:
clock
(
systemPreciseMonotonicClock
()),
timerImpl
(
clock
.
now
()),
epollFd
(
-
1
),
signalFd
(
-
1
),
eventFd
(
-
1
)
{
...
...
@@ -413,7 +405,7 @@ Promise<void> UnixEventPort::FdObserver::whenWriteDisconnected() {
bool
UnixEventPort
::
wait
()
{
return
doEpollWait
(
timerImpl
.
timeoutToNextEvent
(
readClock
(),
MILLISECONDS
,
int
(
maxValue
))
timerImpl
.
timeoutToNextEvent
(
clock
.
now
(),
MILLISECONDS
,
int
(
maxValue
))
.
map
([](
uint64_t
t
)
->
int
{
return
t
;
})
.
orDefault
(
-
1
));
}
...
...
@@ -602,7 +594,7 @@ bool UnixEventPort::doEpollWait(int timeout) {
}
}
timerImpl
.
advanceTo
(
readClock
());
timerImpl
.
advanceTo
(
clock
.
now
());
return
woken
;
}
...
...
@@ -616,7 +608,8 @@ bool UnixEventPort::doEpollWait(int timeout) {
#endif
UnixEventPort
::
UnixEventPort
()
:
timerImpl
(
readClock
())
{
:
clock
(
systemPreciseMonotonicClock
()),
timerImpl
(
clock
.
now
())
{
static_assert
(
sizeof
(
threadId
)
>=
sizeof
(
pthread_t
),
"pthread_t is larger than a long long on your platform. Please port."
);
*
reinterpret_cast
<
pthread_t
*>
(
&
threadId
)
=
pthread_self
();
...
...
@@ -854,7 +847,7 @@ bool UnixEventPort::wait() {
sigprocmask
(
SIG_UNBLOCK
,
&
newMask
,
&
origMask
);
pollContext
.
run
(
timerImpl
.
timeoutToNextEvent
(
readClock
(),
MILLISECONDS
,
int
(
maxValue
))
timerImpl
.
timeoutToNextEvent
(
clock
.
now
(),
MILLISECONDS
,
int
(
maxValue
))
.
map
([](
uint64_t
t
)
->
int
{
return
t
;
})
.
orDefault
(
-
1
));
...
...
@@ -863,7 +856,7 @@ bool UnixEventPort::wait() {
// Queue events.
pollContext
.
processResults
();
timerImpl
.
advanceTo
(
readClock
());
timerImpl
.
advanceTo
(
clock
.
now
());
return
false
;
}
...
...
@@ -925,7 +918,7 @@ bool UnixEventPort::poll() {
pollContext
.
run
(
0
);
pollContext
.
processResults
();
}
timerImpl
.
advanceTo
(
readClock
());
timerImpl
.
advanceTo
(
clock
.
now
());
return
woken
;
}
...
...
c++/src/kj/async-unix.h
View file @
0bd7b221
...
...
@@ -142,12 +142,12 @@ private:
class
SignalPromiseAdapter
;
class
ChildExitPromiseAdapter
;
const
MonotonicClock
&
clock
;
TimerImpl
timerImpl
;
SignalPromiseAdapter
*
signalHead
=
nullptr
;
SignalPromiseAdapter
**
signalTail
=
&
signalHead
;
TimePoint
readClock
();
void
gotSignal
(
const
siginfo_t
&
siginfo
);
friend
class
TimerPromiseAdapter
;
...
...
c++/src/kj/async-win32.c++
View file @
0bd7b221
...
...
@@ -28,7 +28,7 @@
#include "async-win32.h"
#include "debug.h"
#include <atomic>
#include
<chrono>
#include
"time.h"
#include "refcount.h"
#include <ntsecapi.h> // NTSTATUS
#include <ntstatus.h> // STATUS_SUCCESS
...
...
@@ -38,7 +38,8 @@
namespace
kj
{
Win32IocpEventPort
::
Win32IocpEventPort
()
:
iocp
(
newIocpHandle
()),
thread
(
openCurrentThread
()),
timerImpl
(
readClock
())
{}
:
clock
(
systemPreciseMonotonicClock
()),
iocp
(
newIocpHandle
()),
thread
(
openCurrentThread
()),
timerImpl
(
clock
.
now
())
{}
Win32IocpEventPort
::~
Win32IocpEventPort
()
noexcept
(
false
)
{}
...
...
@@ -157,17 +158,12 @@ Own<Win32EventPort::SignalObserver> Win32IocpEventPort::observeSignalState(HANDL
return
waitThreads
.
observeSignalState
(
handle
);
}
TimePoint
Win32IocpEventPort
::
readClock
()
{
return
origin
<
TimePoint
>
()
+
std
::
chrono
::
duration_cast
<
std
::
chrono
::
nanoseconds
>
(
std
::
chrono
::
steady_clock
::
now
().
time_since_epoch
()).
count
()
*
NANOSECONDS
;
}
bool
Win32IocpEventPort
::
wait
()
{
waitIocp
(
timerImpl
.
timeoutToNextEvent
(
readClock
(),
MILLISECONDS
,
INFINITE
-
1
)
waitIocp
(
timerImpl
.
timeoutToNextEvent
(
clock
.
now
(),
MILLISECONDS
,
INFINITE
-
1
)
.
map
([](
uint64_t
t
)
->
DWORD
{
return
t
;
})
.
orDefault
(
INFINITE
));
timerImpl
.
advanceTo
(
readClock
());
timerImpl
.
advanceTo
(
clock
.
now
());
return
receivedWake
();
}
...
...
c++/src/kj/async-win32.h
View file @
0bd7b221
...
...
@@ -209,6 +209,8 @@ private:
class
IoOperationImpl
;
class
IoObserverImpl
;
const
MonotonicClock
&
clock
;
AutoCloseHandle
iocp
;
AutoCloseHandle
thread
;
Win32WaitObjectThreadPool
waitThreads
;
...
...
@@ -216,8 +218,6 @@ private:
mutable
std
::
atomic
<
bool
>
sentWake
{
false
};
bool
isAllowApc
=
false
;
static
TimePoint
readClock
();
void
waitIocp
(
DWORD
timeoutMs
);
// Wait on the I/O completion port for up to timeoutMs and pump events. Does not advance the
// timer; caller must do that.
...
...
c++/src/kj/test.c++
View file @
0bd7b221
...
...
@@ -30,7 +30,6 @@
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <chrono>
#include "time.h"
#ifndef _WIN32
#include <sys/mman.h>
...
...
@@ -185,8 +184,7 @@ private:
};
TimePoint
readClock
()
{
return
origin
<
TimePoint
>
()
+
std
::
chrono
::
duration_cast
<
std
::
chrono
::
nanoseconds
>
(
std
::
chrono
::
steady_clock
::
now
().
time_since_epoch
()).
count
()
*
NANOSECONDS
;
return
systemPreciseMonotonicClock
().
now
();
}
}
// namespace
...
...
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