Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make chip-tool run on a single event loop #7824

Merged

Conversation

mrjerryjohns
Copy link
Contributor

@mrjerryjohns mrjerryjohns commented Jun 22, 2021

Problem

chip-tool demonstrates how to use StartEventLoopTask/StopEventLoopTask to run Matter on a thread different from the "main thread" of the application.

It should also demonstrate how to use RunEventLoop to run Matter on the app main thread. Sort of, since not all implementations of RunEventLoop do that.

@bzbarsky-apple bzbarsky-apple force-pushed the chiptool-single-eventloop branch from 25232bb to d163625 Compare June 23, 2021 22:20
@mrjerryjohns mrjerryjohns changed the title WIP: Make chip-tool run on a single event loop Make chip-tool run on a single event loop Jun 23, 2021
implementation of PlatformManager in _StopEventLoopTask() was too
over-eager - this resulted in complaints from TSAN that it was still
being accessed by RunEventLoop() when it finally came out of the runloop
due to _StopEventLoopTask() signalling its termination.

Fix: Move that clean-up to _Shutdown(), where it arguably should have
been in the first place. This is nicely symmetric to its initialization
in InitChipTask().
#else // CONFIG_USE_SEPARATE_EVENTLOOP
err = command->Run();
SuccessOrExit(err);
command->ScheduleWaitForResponse(command->GetWaitDurationInSeconds());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This set of lines highlight how much a mirror image of the other these two approaches are, and capture their essence:

Either you asynchronously schedule work and synchronously wait for the response (separate event loop), or synchronously do work and asynchronously wait for the response (same event loop).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This set of lines highlight how much a mirror image of the other these two approaches are, and capture their essence:

Either you asynchronously schedule work and synchronously wait for the response (separate event loop), or synchronously do work and asynchronously wait for the response (same event loop).

Could you also add this as a comment in the code (maybe Command.h at the first #if)?

@bzbarsky-apple
Copy link
Contributor

@mspang @andy31415 @Damian-Nordic @jmartinez-silabs Please take a look?

@mspang mspang requested a review from kpschoedel June 24, 2021 17:27
examples/chip-tool/commands/common/Command.cpp Outdated Show resolved Hide resolved
#else // CONFIG_USE_SEPARATE_EVENTLOOP
err = command->Run();
SuccessOrExit(err);
command->ScheduleWaitForResponse(command->GetWaitDurationInSeconds());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This set of lines highlight how much a mirror image of the other these two approaches are, and capture their essence:

Either you asynchronously schedule work and synchronously wait for the response (separate event loop), or synchronously do work and asynchronously wait for the response (same event loop).

Could you also add this as a comment in the code (maybe Command.h at the first #if)?

@mspang
Copy link
Contributor

mspang commented Jun 24, 2021

Problem

Single event loop for chip-tool.

This deserves some significant elaboration?

@bzbarsky-apple
Copy link
Contributor

This deserves some significant elaboration?

Added some.

@bzbarsky-apple bzbarsky-apple merged commit 972bff5 into project-chip:master Jun 24, 2021
nikita-s-wrk pushed a commit to nikita-s-wrk/connectedhomeip that referenced this pull request Sep 23, 2021
* Make it possible to run chip-tool on a single event loop.

* Cleaning up the state lock and conditional vars in the POSIX
implementation of PlatformManager in _StopEventLoopTask() was too
over-eager - this resulted in complaints from TSAN that it was still
being accessed by RunEventLoop() when it finally came out of the runloop
due to _StopEventLoopTask() signalling its termination.

Fix: Move that clean-up to _Shutdown(), where it arguably should have
been in the first place. This is nicely symmetric to its initialization
in InitChipTask().

* Fix typo in artifact name

* Address review comments

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants