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
1446ede2
Commit
1446ede2
authored
Jul 02, 2019
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test using same-thread executor, fix bugs.
parent
776eee73
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletion
+42
-1
async-xthread-test.c++
c++/src/kj/async-xthread-test.c++
+24
-0
async.c++
c++/src/kj/async.c++
+18
-1
No files found.
c++/src/kj/async-xthread-test.c++
View file @
1446ede2
...
@@ -432,5 +432,29 @@ KJ_TEST("cross-thread cancellation in both directions at once") {
...
@@ -432,5 +432,29 @@ KJ_TEST("cross-thread cancellation in both directions at once") {
simultaneous
(
parentExecutor
,
childExecutor
);
simultaneous
(
parentExecutor
,
childExecutor
);
}
}
KJ_TEST
(
"call own thread's executor"
)
{
KJ_XTHREAD_TEST_SETUP_LOOP
;
auto
&
executor
=
getCurrentThreadExecutor
();
{
uint
i
=
executor
.
executeSync
([]()
{
return
123u
;
});
KJ_EXPECT
(
i
==
123
);
}
KJ_EXPECT_THROW_MESSAGE
(
"can't call executeSync() on own thread's executor with a promise-returning function"
,
executor
.
executeSync
([]()
{
return
kj
::
evalLater
([]()
{});
}));
{
uint
i
=
executor
.
executeAsync
([]()
{
return
123u
;
}).
wait
(
waitScope
);
KJ_EXPECT
(
i
==
123
);
}
}
}
// namespace
}
// namespace
}
// namespace kj
}
// namespace kj
c++/src/kj/async.c++
View file @
1446ede2
...
@@ -604,8 +604,25 @@ Executor::~Executor() noexcept(false) {}
...
@@ -604,8 +604,25 @@ Executor::~Executor() noexcept(false) {}
void
Executor
::
send
(
_
::
XThreadEvent
&
event
,
bool
sync
)
const
{
void
Executor
::
send
(
_
::
XThreadEvent
&
event
,
bool
sync
)
const
{
KJ_ASSERT
(
event
.
state
==
_
::
XThreadEvent
::
UNUSED
);
KJ_ASSERT
(
event
.
state
==
_
::
XThreadEvent
::
UNUSED
);
if
(
!
sync
)
{
if
(
sync
)
{
if
(
threadLocalEventLoop
==
&
loop
)
{
// Invoking a sync request on our own thread. Just execute it directly; if we try to queue
// it to the loop, we'll deadlock.
auto
promiseNode
=
event
.
execute
();
// If the function returns a promise, we have no way to pump the event loop to wait for it,
// because the event loop may already be pumping somewhere up the stack.
KJ_ASSERT
(
promiseNode
==
nullptr
,
"can't call executeSync() on own thread's executor with a promise-returning function"
);
return
;
}
}
else
{
event
.
replyExecutor
=
getCurrentThreadExecutor
();
event
.
replyExecutor
=
getCurrentThreadExecutor
();
// Note that async requests will "just work" even if the target executor is our own thread's
// executor. In theory we could detect this case to avoid some locking and signals but that
// would be extra code complexity for probably little benefit.
}
}
auto
lock
=
impl
->
state
.
lockExclusive
();
auto
lock
=
impl
->
state
.
lockExclusive
();
...
...
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