Skip to content

asio strand scheduler#627

Merged
victimsnino merged 8 commits into
victimsnino:v2from
CorentinBT:asio_scheduler
Sep 11, 2024
Merged

asio strand scheduler#627
victimsnino merged 8 commits into
victimsnino:v2from
CorentinBT:asio_scheduler

Conversation

@CorentinBT
Copy link
Copy Markdown
Contributor

@CorentinBT CorentinBT commented Aug 29, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new build configuration option to enable ASIO support in the RPP library.
    • Added a new strand class for thread-safe task scheduling using ASIO's strand functionality.
    • Integrated the worker_strategy class to facilitate task execution strategies within the strand class.
  • Documentation

    • Updated documentation to clarify the integration of ASIO with ReactivePlusPlus.
  • Tests

    • Added unit tests for the strand scheduler to validate its functionality and behavior in various scenarios.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 29, 2024

Walkthrough

Walkthrough

The changes introduce a new build configuration option for the RPP library, specifically the RPP_BUILD_ASIO_CODE flag, allowing users to include or exclude ASIO library integration for asynchronous programming. Updates include new CMake presets, the addition of a strand class for thread-safe task scheduling, and enhancements to dependency management in the build system, along with new unit tests for the strand scheduler.

Changes

File(s) Change Summary
BUILDING.md Added RPP_BUILD_ASIO_CODE option for ASIO support.
CMakePresets.json Introduced new preset build-asio and updated existing presets to inherit from it.
cmake/dependencies.cmake, cmake/variables.cmake, cmake/install-rules.cmake Added logic for ASIO support in the build configuration, including a new macro for linking.
src/extensions/rppasio/rppasio/schedulers/strand.hpp Introduced strand class for task scheduling with ASIO, including state_t and worker_strategy classes.
src/tests/rppasio/test_rppasio_scheduler.cpp Added unit tests for strand scheduler functionality.
conanfile.py Added with_asio option for conditional ASIO dependency inclusion.
src/extensions/CMakeLists.txt, src/tests/CMakeLists.txt Updated to include rppasio module in the build and test configurations.
src/extensions/rppasio/rppasio/fwd.hpp, src/extensions/rppasio/rppasio/rppasio.hpp, src/extensions/rppasio/rppasio/schedulers.hpp, src/extensions/rppasio/rppasio/schedulers/fwd.hpp Introduced new header files for the rppasio module, establishing structure for ASIO integration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CMake
    participant RPP
    participant ASIO

    User->>CMake: Configure build with RPP_BUILD_ASIO_CODE ON
    CMake->>RPP: Include ASIO dependencies
    RPP->>ASIO: Link ASIO library
    RPP->>User: Build successful with ASIO support
Loading

🐇 "In the meadow, I hop with glee,
New features bloom, oh joy for me!
ASIO joins the fun today,
With tasks and threads, we leap and play.
Reactive magic, swift and bright,
Hopping through code, what a delight!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
BUILDING.md (1)

31-31: Fix the grammatical issue.

The description contains a grammatical issue. Apply this diff to fix it:

- `RPP_BUILD_ASIO_CODE` - (ON/OFF) build RPPASIO related code (examples/tests)(rppasio module doesn't requires this one) (default OFF) - requires asio to be installed
+ `RPP_BUILD_ASIO_CODE` - (ON/OFF) build RPPASIO related code (examples/tests)(rppasio module doesn't require this one) (default OFF) - requires asio to be installed
Tools
LanguageTool

[grammar] ~31-~31: The auxiliary verb ‘do’ requires the base form of the verb.
Context: ...(examples/tests)(rppasio module doesn't requires this one) (default OFF) - requires asio...

(DID_BASEFORM)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0e02593 and 8dcafa8.

Files selected for processing (16)
  • BUILDING.md (1 hunks)
  • CMakePresets.json (3 hunks)
  • cmake/dependencies.cmake (1 hunks)
  • cmake/install-rules.cmake (1 hunks)
  • cmake/variables.cmake (2 hunks)
  • conanfile.py (2 hunks)
  • src/extensions/CMakeLists.txt (1 hunks)
  • src/extensions/rppasio/CMakeLists.txt (1 hunks)
  • src/extensions/rppasio/rppasio/fwd.hpp (1 hunks)
  • src/extensions/rppasio/rppasio/rppasio.hpp (1 hunks)
  • src/extensions/rppasio/rppasio/schedulers.hpp (1 hunks)
  • src/extensions/rppasio/rppasio/schedulers/fwd.hpp (1 hunks)
  • src/extensions/rppasio/rppasio/schedulers/strand.hpp (1 hunks)
  • src/tests/CMakeLists.txt (2 hunks)
  • src/tests/rppasio/test_rppasio_scheduler.cpp (1 hunks)
  • src/tests/utils/rpp_trompeloil.hpp (2 hunks)
Files skipped from review due to trivial changes (5)
  • src/extensions/rppasio/CMakeLists.txt
  • src/extensions/rppasio/rppasio/fwd.hpp
  • src/extensions/rppasio/rppasio/rppasio.hpp
  • src/extensions/rppasio/rppasio/schedulers.hpp
  • src/extensions/rppasio/rppasio/schedulers/fwd.hpp
Additional context used
LanguageTool
BUILDING.md

[grammar] ~31-~31: The auxiliary verb ‘do’ requires the base form of the verb.
Context: ...(examples/tests)(rppasio module doesn't requires this one) (default OFF) - requires asio...

(DID_BASEFORM)

Additional comments not posted (31)
src/extensions/CMakeLists.txt (1)

3-3: LGTM!

The addition of the rppasio subdirectory is consistent with the existing structure.

conanfile.py (3)

14-15: LGTM!

The addition of the with_asio option is consistent with the existing options.


22-23: LGTM!

The addition of the with_asio default option is consistent with the existing default options.


42-44: LGTM! But verify the usage of the new option.

The conditional inclusion of the asio dependency is correctly implemented. However, ensure that all necessary parts of the codebase handle the new with_asio option appropriately.

Run the following script to verify the usage of the new option:

cmake/install-rules.cmake (1)

35-39: LGTM!

The addition of the installation rule for rppasio is consistent with the existing rules for other targets.

src/tests/CMakeLists.txt (2)

31-33: LGTM!

The conditional logic for rppasio support is correctly implemented.


67-69: LGTM!

The conditional logic for rppasio test registration is correctly implemented.

src/tests/utils/rpp_trompeloil.hpp (2)

8-9: LGTM!

The inclusion of the rpp/observers/observer.hpp header is necessary for the new member functions in the mock_observer class.


71-73: LGTM!

The new member functions enhance the mock_observer class's functionality by providing flexible ways to obtain observers.

cmake/variables.cmake (2)

86-86: LGTM!

The addition of the new configuration option RPP_BUILD_ASIO_CODE is straightforward and follows the existing pattern for other options.


108-110: LGTM!

The conditional block that appends ASIO-related arguments to the CONAN_ARGS variable is correctly implemented and follows the existing pattern for other options.

src/extensions/rppasio/rppasio/schedulers/strand.hpp (6)

20-69: LGTM!

The class strand and its nested class state are correctly implemented and follow best practices for ASIO integration.


37-65: LGTM!

The defer_for method is correctly implemented and handles both immediate and delayed execution of tasks.


71-90: LGTM!

The class worker_strategy is correctly implemented and follows best practices for ASIO integration.


79-83: LGTM!

The defer_for method is correctly implemented and delegates the task to the state class.


98-101: LGTM!

The create_worker method is correctly implemented and returns a worker for the strand.


92-95: LGTM!

The constructor is correctly implemented and initializes the strand with an executor.

src/tests/rppasio/test_rppasio_scheduler.cpp (5)

40-65: LGTM!

The test case strand utilized current_thread is correctly implemented and verifies the expected behavior.


67-83: LGTM!

The test case strand works till end is correctly implemented and verifies the expected behavior.


86-105: LGTM!

The test case strand in combination with current_thread is correctly implemented and verifies the expected behavior.


107-138: LGTM!

The test case strand worker has correct execution order is correctly implemented and verifies the expected behavior.


31-37: LGTM!

The drain function is correctly implemented and ensures that the context runs until the disposable is disposed.

cmake/dependencies.cmake (2)

128-131: LGTM!

The conditional block for ASIO support is correctly implemented.


132-135: LGTM!

The macro rpp_add_asio_support_to_executable is correctly implemented.

CMakePresets.json (7)

148-154: LGTM!

The new preset "build-asio" is correctly implemented.


178-178: LGTM!

The updated preset "ci-coverage-clang" is correctly implemented.


187-187: LGTM!

The updated preset "ci-sanitize-tsan" is correctly implemented.


194-194: LGTM!

The updated preset "ci-sanitize-asan" is correctly implemented.


201-201: LGTM!

The updated preset "ci-sanitize-lsan" is correctly implemented.


208-208: LGTM!

The updated preset "ci-sanitize-msan" is correctly implemented.


215-215: LGTM!

The updated preset "ci-sanitize-ubsan" is correctly implemented.

namespace rppasio::schedulers
{
/**
* @brief TODO
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

TODO =)

@victimsnino victimsnino mentioned this pull request Aug 30, 2024
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 30, 2024

BENCHMARK RESULTS (AUTOGENERATED)

ci-ubuntu-gcc

General

name rxcpp rpp prev rpp ratio
Subscribe empty callbacks to empty observable 305.22 ns 2.16 ns 2.16 ns 1.00
Subscribe empty callbacks to empty observable via pipe operator 305.26 ns 2.16 ns 2.16 ns 1.00

Sources

name rxcpp rpp prev rpp ratio
from array of 1 - create + subscribe + immediate 697.51 ns 0.31 ns 0.31 ns 1.00
from array of 1 - create + subscribe + current_thread 1038.15 ns 3.71 ns 3.42 ns 1.08
concat_as_source of just(1 immediate) create + subscribe 2262.74 ns 114.51 ns 104.71 ns 1.09
defer from array of 1 - defer + create + subscribe + immediate 729.66 ns 0.31 ns 0.31 ns 1.00
interval - interval + take(3) + subscribe + immediate 2092.99 ns 59.23 ns 59.23 ns 1.00
interval - interval + take(3) + subscribe + current_thread 3029.53 ns 32.40 ns 32.46 ns 1.00
from array of 1 - create + as_blocking + subscribe + new_thread 30301.29 ns 31626.65 ns 35779.06 ns 0.88
from array of 1000 - create + as_blocking + subscribe + new_thread 38147.72 ns 52609.15 ns 55631.67 ns 0.95
concat_as_source of just(1 immediate) and just(1,2 immediate)create + subscribe 3470.24 ns 143.69 ns 127.89 ns 1.12

Filtering Operators

name rxcpp rpp prev rpp ratio
immediate_just+take(1)+subscribe 1082.11 ns 0.31 ns 0.31 ns 1.00
immediate_just+filter(true)+subscribe 874.02 ns 0.31 ns 0.31 ns 1.00
immediate_just(1,2)+skip(1)+subscribe 999.58 ns 0.31 ns 0.31 ns 1.00
immediate_just(1,1,2)+distinct_until_changed()+subscribe 926.82 ns 0.31 ns 0.31 ns 1.00
immediate_just(1,2)+first()+subscribe 1238.10 ns 0.31 ns 0.31 ns 1.00
immediate_just(1,2)+last()+subscribe 927.09 ns 0.31 ns 0.31 ns 1.00
immediate_just+take_last(1)+subscribe 1135.64 ns 17.90 ns 18.55 ns 0.96
immediate_just(1,2,3)+element_at(1)+subscribe 835.34 ns 0.31 ns 0.31 ns 1.00

Schedulers

name rxcpp rpp prev rpp ratio
immediate scheduler create worker + schedule 279.50 ns 2.16 ns 2.16 ns 1.00
current_thread scheduler create worker + schedule 375.93 ns 5.86 ns 5.90 ns 0.99
current_thread scheduler create worker + schedule + recursive schedule 814.64 ns 56.04 ns 55.62 ns 1.01

Transforming Operators

name rxcpp rpp prev rpp ratio
immediate_just+map(v*2)+subscribe 860.12 ns 0.31 ns 0.31 ns 1.00
immediate_just+scan(10, std::plus)+subscribe 878.72 ns 0.31 ns 0.31 ns 1.00
immediate_just+flat_map(immediate_just(v*2))+subscribe 2295.54 ns 175.40 ns 162.78 ns 1.08
immediate_just+buffer(2)+subscribe 1520.68 ns 13.58 ns 14.20 ns 0.96
immediate_just+window(2)+subscribe + subscsribe inner 2429.74 ns 1111.72 ns 1062.29 ns 1.05

Conditional Operators

name rxcpp rpp prev rpp ratio
immediate_just+take_while(false)+subscribe 918.14 ns - - 0.00
immediate_just+take_while(true)+subscribe 852.98 ns 0.31 ns 0.31 ns 1.00

Utility Operators

name rxcpp rpp prev rpp ratio
immediate_just(1)+subscribe_on(immediate)+subscribe 2022.79 ns 0.31 ns 0.31 ns 1.00

Combining Operators

name rxcpp rpp prev rpp ratio
immediate_just(immediate_just(1), immediate_just(1)) + merge() + subscribe 3438.12 ns 184.57 ns 187.54 ns 0.98
immediate_just(1) + merge_with(immediate_just(2)) + subscribe 3610.80 ns 178.07 ns 171.48 ns 1.04
immediate_just(1) + with_latest_from(immediate_just(2)) + subscribe - 145.74 ns 136.91 ns 1.06
immediate_just(immediate_just(1),immediate_just(1)) + switch_on_next() + subscribe 3516.69 ns 941.03 ns 885.27 ns 1.06
immediate_just(1) + zip(immediate_just(2)) + subscribe 2159.67 ns 237.12 ns 225.23 ns 1.05

Subjects

name rxcpp rpp prev rpp ratio
publish_subject with 1 observer - on_next 34.56 ns 14.73 ns 14.61 ns 1.01
subscribe 100 observers to publish_subject 199273.83 ns 15567.74 ns 15421.60 ns 1.01
100 on_next to 100 observers to publish_subject 32519.95 ns 17128.84 ns 20460.62 ns 0.84

Scenarios

name rxcpp rpp prev rpp ratio
basic sample 1436.64 ns 12.97 ns 12.65 ns 1.03
basic sample with immediate scheduler 1414.32 ns 5.55 ns 5.24 ns 1.06

Aggregating Operators

name rxcpp rpp prev rpp ratio
immediate_just+reduce(10, std::plus)+subscribe 936.54 ns 0.31 ns 0.31 ns 1.00

Error Handling Operators

name rxcpp rpp prev rpp ratio
create(on_next(1), on_error())+on_error_resume_next(immediate_just(2)))+subscribe 2071.30 ns 1006.05 ns 1013.24 ns 0.99
create(on_error())+retry(1)+subscribe 593.81 ns 98.37 ns 107.89 ns 0.91

ci-macos

General

name rxcpp rpp prev rpp ratio
Subscribe empty callbacks to empty observable 1065.39 ns 4.30 ns 3.89 ns 1.11
Subscribe empty callbacks to empty observable via pipe operator 1056.42 ns 4.17 ns 3.87 ns 1.08

Sources

name rxcpp rpp prev rpp ratio
from array of 1 - create + subscribe + immediate 2231.79 ns 0.26 ns 0.23 ns 1.13
from array of 1 - create + subscribe + current_thread 2640.63 ns 38.27 ns 34.68 ns 1.10
concat_as_source of just(1 immediate) create + subscribe 5897.81 ns 357.40 ns 337.75 ns 1.06
defer from array of 1 - defer + create + subscribe + immediate 1955.91 ns 0.23 ns 0.24 ns 0.99
interval - interval + take(3) + subscribe + immediate 4914.53 ns 113.72 ns 113.98 ns 1.00
interval - interval + take(3) + subscribe + current_thread 6821.72 ns 105.91 ns 97.30 ns 1.09
from array of 1 - create + as_blocking + subscribe + new_thread 105694.45 ns 102624.44 ns 94219.18 ns 1.09
from array of 1000 - create + as_blocking + subscribe + new_thread 96079.55 ns 126474.75 ns 99710.60 ns 1.27
concat_as_source of just(1 immediate) and just(1,2 immediate)create + subscribe 8660.16 ns 390.16 ns 383.78 ns 1.02

Filtering Operators

name rxcpp rpp prev rpp ratio
immediate_just+take(1)+subscribe 3565.56 ns 0.27 ns 0.23 ns 1.18
immediate_just+filter(true)+subscribe 2106.46 ns 0.25 ns 0.22 ns 1.11
immediate_just(1,2)+skip(1)+subscribe 2750.12 ns 0.23 ns 0.23 ns 1.02
immediate_just(1,1,2)+distinct_until_changed()+subscribe 2066.63 ns 0.47 ns 0.46 ns 1.02
immediate_just(1,2)+first()+subscribe 3176.51 ns 0.23 ns 0.22 ns 1.05
immediate_just(1,2)+last()+subscribe 2389.61 ns 0.23 ns 0.22 ns 1.05
immediate_just+take_last(1)+subscribe 3180.67 ns 0.23 ns 0.22 ns 1.05
immediate_just(1,2,3)+element_at(1)+subscribe 2123.04 ns 0.23 ns 0.23 ns 1.02

Schedulers

name rxcpp rpp prev rpp ratio
immediate scheduler create worker + schedule 963.23 ns 4.71 ns 4.14 ns 1.14
current_thread scheduler create worker + schedule 1349.29 ns 43.78 ns 38.52 ns 1.14
current_thread scheduler create worker + schedule + recursive schedule 1999.02 ns 204.82 ns 209.26 ns 0.98

Transforming Operators

name rxcpp rpp prev rpp ratio
immediate_just+map(v*2)+subscribe 2098.12 ns 4.20 ns 4.33 ns 0.97
immediate_just+scan(10, std::plus)+subscribe 2341.41 ns 0.47 ns 0.46 ns 1.02
immediate_just+flat_map(immediate_just(v*2))+subscribe 5303.99 ns 402.55 ns 400.88 ns 1.00
immediate_just+buffer(2)+subscribe 2481.87 ns 64.43 ns 62.93 ns 1.02
immediate_just+window(2)+subscribe + subscsribe inner 6993.02 ns 2415.02 ns 2306.79 ns 1.05

Conditional Operators

name rxcpp rpp prev rpp ratio
immediate_just+take_while(false)+subscribe 2102.48 ns - - 0.00
immediate_just+take_while(true)+subscribe 2097.78 ns 0.23 ns 0.23 ns 1.02

Utility Operators

name rxcpp rpp prev rpp ratio
immediate_just(1)+subscribe_on(immediate)+subscribe 4907.37 ns 5.13 ns 4.78 ns 1.07

Combining Operators

name rxcpp rpp prev rpp ratio
immediate_just(immediate_just(1), immediate_just(1)) + merge() + subscribe 7345.64 ns 438.64 ns 440.60 ns 1.00
immediate_just(1) + merge_with(immediate_just(2)) + subscribe 8360.14 ns 441.96 ns 439.71 ns 1.01
immediate_just(1) + with_latest_from(immediate_just(2)) + subscribe - 459.58 ns 459.90 ns 1.00
immediate_just(immediate_just(1),immediate_just(1)) + switch_on_next() + subscribe 7993.45 ns 1909.54 ns 1911.64 ns 1.00
immediate_just(1) + zip(immediate_just(2)) + subscribe 5103.68 ns 840.14 ns 828.49 ns 1.01

Subjects

name rxcpp rpp prev rpp ratio
publish_subject with 1 observer - on_next 76.74 ns 48.90 ns 48.72 ns 1.00
subscribe 100 observers to publish_subject 344197.00 ns 40828.96 ns 40678.50 ns 1.00
100 on_next to 100 observers to publish_subject 51332.74 ns 18785.19 ns 16590.69 ns 1.13

Scenarios

name rxcpp rpp prev rpp ratio
basic sample 2761.89 ns 68.95 ns 69.65 ns 0.99
basic sample with immediate scheduler 2784.64 ns 18.49 ns 18.74 ns 0.99

Aggregating Operators

name rxcpp rpp prev rpp ratio
immediate_just+reduce(10, std::plus)+subscribe 2396.43 ns 0.23 ns 0.23 ns 1.00

Error Handling Operators

name rxcpp rpp prev rpp ratio
create(on_next(1), on_error())+on_error_resume_next(immediate_just(2)))+subscribe 6596.40 ns 4181.09 ns 4110.65 ns 1.02
create(on_error())+retry(1)+subscribe 1808.91 ns 287.43 ns 284.80 ns 1.01

ci-ubuntu-clang

General

name rxcpp rpp prev rpp ratio
Subscribe empty callbacks to empty observable 279.87 ns 1.54 ns 1.54 ns 1.00
Subscribe empty callbacks to empty observable via pipe operator 267.81 ns 1.54 ns 1.54 ns 1.00

Sources

name rxcpp rpp prev rpp ratio
from array of 1 - create + subscribe + immediate 583.72 ns 0.31 ns 0.31 ns 1.00
from array of 1 - create + subscribe + current_thread 815.39 ns 4.32 ns 4.32 ns 1.00
concat_as_source of just(1 immediate) create + subscribe 2343.89 ns 130.96 ns 130.58 ns 1.00
defer from array of 1 - defer + create + subscribe + immediate 789.24 ns 0.31 ns 0.31 ns 1.00
interval - interval + take(3) + subscribe + immediate 2264.64 ns 58.31 ns 58.31 ns 1.00
interval - interval + take(3) + subscribe + current_thread 3481.75 ns 30.88 ns 30.90 ns 1.00
from array of 1 - create + as_blocking + subscribe + new_thread 27098.61 ns 30819.68 ns 31702.06 ns 0.97
from array of 1000 - create + as_blocking + subscribe + new_thread 38959.44 ns 38898.88 ns 36502.28 ns 1.07
concat_as_source of just(1 immediate) and just(1,2 immediate)create + subscribe 3732.55 ns 150.57 ns 150.14 ns 1.00

Filtering Operators

name rxcpp rpp prev rpp ratio
immediate_just+take(1)+subscribe 1138.46 ns 0.31 ns 0.31 ns 1.00
immediate_just+filter(true)+subscribe 875.70 ns 0.31 ns 0.31 ns 1.00
immediate_just(1,2)+skip(1)+subscribe 1087.59 ns 0.31 ns 0.31 ns 1.00
immediate_just(1,1,2)+distinct_until_changed()+subscribe 920.99 ns 0.31 ns 0.31 ns 1.02
immediate_just(1,2)+first()+subscribe 1369.48 ns 0.31 ns 0.31 ns 1.00
immediate_just(1,2)+last()+subscribe 1053.26 ns 0.31 ns 0.31 ns 1.00
immediate_just+take_last(1)+subscribe 1180.56 ns 0.31 ns 0.31 ns 1.00
immediate_just(1,2,3)+element_at(1)+subscribe 913.67 ns 0.31 ns 0.31 ns 1.00

Schedulers

name rxcpp rpp prev rpp ratio
immediate scheduler create worker + schedule 284.92 ns 1.54 ns 1.54 ns 1.00
current_thread scheduler create worker + schedule 392.21 ns 4.94 ns 4.94 ns 1.00
current_thread scheduler create worker + schedule + recursive schedule 905.39 ns 55.85 ns 55.73 ns 1.00

Transforming Operators

name rxcpp rpp prev rpp ratio
immediate_just+map(v*2)+subscribe 871.84 ns 0.31 ns 0.31 ns 1.00
immediate_just+scan(10, std::plus)+subscribe 983.92 ns 0.31 ns 0.31 ns 1.00
immediate_just+flat_map(immediate_just(v*2))+subscribe 2263.43 ns 138.43 ns 138.53 ns 1.00
immediate_just+buffer(2)+subscribe 1510.57 ns 13.60 ns 13.59 ns 1.00
immediate_just+window(2)+subscribe + subscsribe inner 2458.04 ns 930.03 ns 928.39 ns 1.00

Conditional Operators

name rxcpp rpp prev rpp ratio
immediate_just+take_while(false)+subscribe 866.77 ns - - 0.00
immediate_just+take_while(true)+subscribe 868.18 ns 0.31 ns 0.31 ns 1.00

Utility Operators

name rxcpp rpp prev rpp ratio
immediate_just(1)+subscribe_on(immediate)+subscribe 2125.59 ns 0.31 ns 0.31 ns 1.00

Combining Operators

name rxcpp rpp prev rpp ratio
immediate_just(immediate_just(1), immediate_just(1)) + merge() + subscribe 3275.54 ns 160.23 ns 164.77 ns 0.97
immediate_just(1) + merge_with(immediate_just(2)) + subscribe 3791.02 ns 148.05 ns 151.11 ns 0.98
immediate_just(1) + with_latest_from(immediate_just(2)) + subscribe - 144.34 ns 143.84 ns 1.00
immediate_just(immediate_just(1),immediate_just(1)) + switch_on_next() + subscribe 3389.62 ns 842.29 ns 844.08 ns 1.00
immediate_just(1) + zip(immediate_just(2)) + subscribe 2246.46 ns 201.11 ns 200.48 ns 1.00

Subjects

name rxcpp rpp prev rpp ratio
publish_subject with 1 observer - on_next 53.64 ns 17.66 ns 17.55 ns 1.01
subscribe 100 observers to publish_subject 213034.25 ns 15956.58 ns 15970.75 ns 1.00
100 on_next to 100 observers to publish_subject 42789.80 ns 20415.21 ns 20908.68 ns 0.98

Scenarios

name rxcpp rpp prev rpp ratio
basic sample 1323.70 ns 11.73 ns 11.73 ns 1.00
basic sample with immediate scheduler 1322.12 ns 6.17 ns 6.17 ns 1.00

Aggregating Operators

name rxcpp rpp prev rpp ratio
immediate_just+reduce(10, std::plus)+subscribe 1014.31 ns 0.31 ns 0.31 ns 1.00

Error Handling Operators

name rxcpp rpp prev rpp ratio
create(on_next(1), on_error())+on_error_resume_next(immediate_just(2)))+subscribe 2177.39 ns 1233.11 ns 1272.39 ns 0.97
create(on_error())+retry(1)+subscribe 652.56 ns 138.03 ns 138.53 ns 1.00

ci-windows

General

name rxcpp rpp prev rpp ratio
Subscribe empty callbacks to empty observable 561.60 ns 4.02 ns 4.88 ns 0.82
Subscribe empty callbacks to empty observable via pipe operator 589.45 ns 4.02 ns 4.94 ns 0.81

Sources

name rxcpp rpp prev rpp ratio
from array of 1 - create + subscribe + immediate 1163.33 ns 9.71 ns 9.71 ns 1.00
from array of 1 - create + subscribe + current_thread 1425.67 ns 17.91 ns 17.60 ns 1.02
concat_as_source of just(1 immediate) create + subscribe 3964.04 ns 189.01 ns 177.26 ns 1.07
defer from array of 1 - defer + create + subscribe + immediate 1459.67 ns 9.42 ns 9.41 ns 1.00
interval - interval + take(3) + subscribe + immediate 3041.45 ns 145.32 ns 144.40 ns 1.01
interval - interval + take(3) + subscribe + current_thread 3421.75 ns 64.29 ns 65.09 ns 0.99
from array of 1 - create + as_blocking + subscribe + new_thread 121000.00 ns 102272.73 ns 124000.00 ns 0.82
from array of 1000 - create + as_blocking + subscribe + new_thread 135071.43 ns 166785.71 ns 146937.50 ns 1.14
concat_as_source of just(1 immediate) and just(1,2 immediate)create + subscribe 5263.29 ns 212.26 ns 207.82 ns 1.02

Filtering Operators

name rxcpp rpp prev rpp ratio
immediate_just+take(1)+subscribe 1805.82 ns 25.30 ns 24.99 ns 1.01
immediate_just+filter(true)+subscribe 1308.06 ns 24.37 ns 24.05 ns 1.01
immediate_just(1,2)+skip(1)+subscribe 1698.73 ns 24.06 ns 23.45 ns 1.03
immediate_just(1,1,2)+distinct_until_changed()+subscribe 1362.63 ns 29.01 ns 26.37 ns 1.10
immediate_just(1,2)+first()+subscribe 2054.84 ns 22.82 ns 23.74 ns 0.96
immediate_just(1,2)+last()+subscribe 1774.73 ns 24.06 ns 24.72 ns 0.97
immediate_just+take_last(1)+subscribe 1990.04 ns 69.64 ns 70.33 ns 0.99
immediate_just(1,2,3)+element_at(1)+subscribe 1350.89 ns 27.47 ns 26.58 ns 1.03

Schedulers

name rxcpp rpp prev rpp ratio
immediate scheduler create worker + schedule 475.24 ns 6.17 ns 6.79 ns 0.91
current_thread scheduler create worker + schedule 648.80 ns 14.21 ns 14.57 ns 0.98
current_thread scheduler create worker + schedule + recursive schedule 1553.58 ns 108.32 ns 103.29 ns 1.05

Transforming Operators

name rxcpp rpp prev rpp ratio
immediate_just+map(v*2)+subscribe 1305.37 ns 24.37 ns 24.36 ns 1.00
immediate_just+scan(10, std::plus)+subscribe 1405.24 ns 26.53 ns 26.51 ns 1.00
immediate_just+flat_map(immediate_just(v*2))+subscribe 3729.33 ns 211.52 ns 212.91 ns 0.99
immediate_just+buffer(2)+subscribe 2315.95 ns 70.47 ns 69.02 ns 1.02
immediate_just+window(2)+subscribe + subscsribe inner 3988.54 ns 1284.83 ns 1307.55 ns 0.98

Conditional Operators

name rxcpp rpp prev rpp ratio
immediate_just+take_while(false)+subscribe 1303.55 ns 23.14 ns 23.14 ns 1.00
immediate_just+take_while(true)+subscribe 1302.17 ns 24.36 ns 24.05 ns 1.01

Utility Operators

name rxcpp rpp prev rpp ratio
immediate_just(1)+subscribe_on(immediate)+subscribe 3110.81 ns 11.11 ns 11.10 ns 1.00

Combining Operators

name rxcpp rpp prev rpp ratio
immediate_just(immediate_just(1), immediate_just(1)) + merge() + subscribe 5004.93 ns 225.59 ns 229.81 ns 0.98
immediate_just(1) + merge_with(immediate_just(2)) + subscribe 5649.21 ns 208.21 ns 225.48 ns 0.92
immediate_just(1) + with_latest_from(immediate_just(2)) + subscribe - 199.34 ns 204.26 ns 0.98
immediate_just(immediate_just(1),immediate_just(1)) + switch_on_next() + subscribe 5302.78 ns 918.41 ns 961.55 ns 0.96
immediate_just(1) + zip(immediate_just(2)) + subscribe 3762.83 ns 525.72 ns 532.02 ns 0.99

Subjects

name rxcpp rpp prev rpp ratio
publish_subject with 1 observer - on_next 37.36 ns 20.67 ns 20.68 ns 1.00
subscribe 100 observers to publish_subject 263800.00 ns 29635.90 ns 28417.95 ns 1.04
100 on_next to 100 observers to publish_subject 51925.00 ns 38823.33 ns 38822.58 ns 1.00

Scenarios

name rxcpp rpp prev rpp ratio
basic sample 1840.92 ns 102.58 ns 102.64 ns 1.00
basic sample with immediate scheduler 1849.36 ns 74.75 ns 74.07 ns 1.01

Aggregating Operators

name rxcpp rpp prev rpp ratio
immediate_just+reduce(10, std::plus)+subscribe 1435.87 ns 24.99 ns 24.66 ns 1.01

Error Handling Operators

name rxcpp rpp prev rpp ratio
create(on_next(1), on_error())+on_error_resume_next(immediate_just(2)))+subscribe 2371.19 ns 354.10 ns 366.82 ns 0.97
create(on_error())+retry(1)+subscribe 1172.60 ns 140.37 ns 141.04 ns 1.00

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 30, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.64%. Comparing base (8ddb555) to head (c60a8c8).
Report is 1 commits behind head on v2.

Files with missing lines Patch % Lines
src/rpp/rpp/schedulers/details/queue.hpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v2     #627      +/-   ##
==========================================
- Coverage   95.69%   95.64%   -0.06%     
==========================================
  Files          97       97              
  Lines        1882     1883       +1     
==========================================
  Hits         1801     1801              
- Misses         81       82       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@victimsnino
Copy link
Copy Markdown
Owner

@CorentinBT , sonarcloud showing valid issues:
https://sonarcloud.io/project/issues?severities=BLOCKER%2CCRITICAL%2CMAJOR%2CMINOR&sinceLeakPeriod=true&issueStatuses=OPEN%2CCONFIRMED&types=BUG&pullRequest=627&id=victimsnino_ReactivePlusPlus&open=AZGlXtnEPhZvl699Zupo

you are trying to forward values but they just forwarded inside lambda: from this point it is regular variable and should be just moved. Forward inside lambda is ok in case of capturing by reference

@CorentinBT
Copy link
Copy Markdown
Contributor Author

@CorentinBT , sonarcloud showing valid issues: https://sonarcloud.io/project/issues?severities=BLOCKER%2CCRITICAL%2CMAJOR%2CMINOR&sinceLeakPeriod=true&issueStatuses=OPEN%2CCONFIRMED&types=BUG&pullRequest=627&id=victimsnino_ReactivePlusPlus&open=AZGlXtnEPhZvl699Zupo

you are trying to forward values but they just forwarded inside lambda: from this point it is regular variable and should be just moved. Forward inside lambda is ok in case of capturing by reference

done

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8dcafa8 and cc71a92.

Files selected for processing (2)
  • BUILDING.md (1 hunks)
  • src/extensions/rppasio/rppasio/schedulers/strand.hpp (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • BUILDING.md
Additional comments not posted (4)
src/extensions/rppasio/rppasio/schedulers/strand.hpp (4)

1-10: LGTM!

The license header comment is informative and follows the standard practice.


34-73: LGTM!

The state class is well-designed and follows the ASIO programming model. The use of asio::post and asio::basic_waitable_timer is appropriate for deferring the execution of schedulable functions. The recursive call to defer_for is a good way to handle the case where the schedulable function returns a new duration. The state class is thread-safe because it uses an asio::io_context::strand to serialize the execution of schedulable functions.


75-94: LGTM!

The worker_strategy class is a simple wrapper around the state class and provides the interface for the worker class. The get_disposable method returns a none_disposable object, which is appropriate for this scheduler because it does not have a disposable object. The now method returns the current time, which is used by the worker class to calculate the absolute time for deferred execution.


32-108: LGTM!

The strand class is a simple scheduler that uses the ASIO library to execute schedulable functions. The use of the worker_strategy class is a good way to provide the interface for the worker class. The create_worker method returns a worker object that can be used to schedule tasks.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cc71a92 and e2dc293.

Files selected for processing (1)
  • CMakePresets.json (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • CMakePresets.json

@CorentinBT CorentinBT marked this pull request as ready for review September 1, 2024 19:48
Comment thread src/extensions/rppasio/rppasio/schedulers/strand.hpp Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (2)
BUILDING.md (1)

31-31: Approve the addition of RPP_BUILD_ASIO_CODE.

The new build configuration option RPP_BUILD_ASIO_CODE is correctly added and follows the existing pattern for similar options. It is clear and understandable.

Consider adding a direct link to the ASIO library installation instructions to aid users in setting up their environment.

src/rpp/rpp/schedulers/current_thread.hpp (1)

87-87: Visibility Change: Public Access Specifier Added

The addition of the public access specifier to the current_thread class enhances its accessibility. This change allows other components, such as the new_thread class, to interact more directly with current_thread. While this can be beneficial for certain design patterns, it also increases the risk of misuse or unintended interactions. It is crucial to ensure that this change aligns with the overall design principles of the library and does not expose internal mechanisms that should remain encapsulated.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e2dc293 and b64f664.

Files selected for processing (18)
  • BUILDING.md (1 hunks)
  • CMakePresets.json (3 hunks)
  • cmake/dependencies.cmake (1 hunks)
  • cmake/install-rules.cmake (1 hunks)
  • cmake/variables.cmake (2 hunks)
  • conanfile.py (2 hunks)
  • src/extensions/CMakeLists.txt (1 hunks)
  • src/extensions/rppasio/CMakeLists.txt (1 hunks)
  • src/extensions/rppasio/rppasio/fwd.hpp (1 hunks)
  • src/extensions/rppasio/rppasio/rppasio.hpp (1 hunks)
  • src/extensions/rppasio/rppasio/schedulers.hpp (1 hunks)
  • src/extensions/rppasio/rppasio/schedulers/fwd.hpp (1 hunks)
  • src/extensions/rppasio/rppasio/schedulers/strand.hpp (1 hunks)
  • src/rpp/rpp/schedulers/current_thread.hpp (1 hunks)
  • src/rpp/rpp/schedulers/details/queue.hpp (2 hunks)
  • src/tests/CMakeLists.txt (2 hunks)
  • src/tests/rppasio/test_rppasio_scheduler.cpp (1 hunks)
  • src/tests/utils/rpp_trompeloil.hpp (2 hunks)
Files skipped from review due to trivial changes (5)
  • src/extensions/CMakeLists.txt
  • src/extensions/rppasio/CMakeLists.txt
  • src/extensions/rppasio/rppasio/fwd.hpp
  • src/extensions/rppasio/rppasio/schedulers.hpp
  • src/extensions/rppasio/rppasio/schedulers/fwd.hpp
Files skipped from review as they are similar to previous changes (9)
  • CMakePresets.json
  • cmake/dependencies.cmake
  • cmake/install-rules.cmake
  • cmake/variables.cmake
  • conanfile.py
  • src/extensions/rppasio/rppasio/rppasio.hpp
  • src/tests/CMakeLists.txt
  • src/tests/rppasio/test_rppasio_scheduler.cpp
  • src/tests/utils/rpp_trompeloil.hpp
Additional comments not posted (10)
BUILDING.md (1)

29-30: Approve grammatical corrections in option descriptions.

The grammatical corrections in the descriptions for RPP_BUILD_QT_CODE and RPP_BUILD_GRPC_CODE enhance the clarity and correctness of the documentation.

src/rpp/rpp/schedulers/current_thread.hpp (6)

Line range hint 89-93: Thread-Local Queue Access: Well-Implemented

The implementation of the get_queue method using thread-local storage is appropriate and well-suited for the task scheduling mechanism of the current_thread scheduler. This approach ensures that each thread maintains its own queue independently, which is crucial for the correct operation of thread-specific task scheduling.


Line range hint 97-125: Task Execution Logic: Correct and Efficient

The drain_queue method is well-implemented, providing robust logic for executing tasks from the queue. It correctly handles task disposal, scheduling delays, and task rescheduling. This method is central to the functionality of the current_thread scheduler, ensuring that tasks are executed in the correct order and at the right times.


Line range hint 127-147: Improper Value Forwarding in Lambda Captures

The defer_for method uses forwarding for the function, handler, and arguments. While this is generally a good practice to avoid unnecessary copies, it is crucial to ensure that these forwarded values are not captured by reference in any lambdas within this method or passed to other functions that might store them beyond the lifetime of the original objects. This concern aligns with the feedback from the PR comments about potential issues with value forwarding in lambdas. It is recommended to review all lambda captures within this method to ensure they are capturing values correctly and not leading to any unintended side effects.


Line range hint 149-161: Specific Time Point Scheduling: Correctly Implemented

The defer_to method provides a clear and correct implementation for scheduling tasks at a specific time point. It appropriately uses forwarding for the function, handler, and arguments to optimize performance and reduce unnecessary copies. This method is crucial for precise timing control in task scheduling.


Line range hint 163-165: Current Time Retrieval: Simple and Effective

The now method effectively retrieves the current time point using the details::now() function. This utility method is essential for other scheduling methods in the current_thread class, providing a reliable source for the current time.


Line range hint 167-183: Queue Lifecycle Management: Robust and Safe

The own_queue_guard method provides a robust mechanism for managing the lifecycle of the queue. It uses a boolean flag to ensure that the queue is only cleared when necessary, preventing memory leaks or other issues related to improper resource management. This method is a critical part of ensuring that the current_thread scheduler operates reliably and efficiently.

src/rpp/rpp/schedulers/details/queue.hpp (2)

78-78: Approval of the new on_error function.

The addition of the on_error function as a pure virtual method in schedulable_base is a positive change, enhancing the robustness of error handling by enforcing its implementation in all derived classes.


164-164: Review the implementation of on_error in specific_schedulable.

The override of on_error in specific_schedulable correctly delegates the error handling to its member's on_error method. However, based on the PR comments, it is crucial to ensure that the lambda capture strategy used within this context correctly handles the forwarding of values. Specifically, review whether the values captured by m_args are being moved appropriately instead of incorrectly using std::forward, which could lead to issues as described in the PR comments.

Consider verifying the lambda capture and forwarding strategy with a detailed examination of how m_args is utilized across different contexts in the codebase.

src/extensions/rppasio/rppasio/schedulers/strand.hpp (1)

22-194: Approval: Overall design and structure of the strand class

The strand class is well-designed, integrating seamlessly with ASIO's io_context to provide a robust mechanism for scheduling tasks in a thread-safe manner. The use of modern C++ features like templates, shared pointers, and lambda expressions enhances its functionality and flexibility.

The implementation is generally solid, with good use of C++ best practices and ASIO integration. The concerns raised in previous comments regarding lambda captures are the only major issues needing attention.

Comment thread src/extensions/rppasio/rppasio/schedulers/strand.hpp Outdated
Comment thread src/extensions/rppasio/rppasio/schedulers/strand.hpp Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b64f664 and 5906592.

Files selected for processing (1)
  • src/extensions/rppasio/rppasio/schedulers/strand.hpp (1 hunks)
Additional comments not posted (1)
src/extensions/rppasio/rppasio/schedulers/strand.hpp (1)

127-127: Clarification on now() usage

@CorentinBT, regarding your uncertainty about setting now() here, it seems appropriate to use now() to update the timepoint of a schedulable after it has been processed. This ensures that the schedulable is re-queued with an updated time based on the current time, which is crucial for accurate scheduling and avoiding drift in time-sensitive applications.

Please confirm if this aligns with the intended behavior or if further adjustments are needed.

Comment thread src/extensions/rppasio/rppasio/schedulers/strand.hpp
Comment thread src/extensions/rppasio/rppasio/schedulers/strand.hpp
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5906592 and 32570e3.

Files selected for processing (1)
  • src/extensions/rppasio/rppasio/schedulers/strand.hpp (1 hunks)
Additional comments not posted (2)
src/extensions/rppasio/rppasio/schedulers/strand.hpp (2)

60-73: Review: Lambda captures in asynchronous wait handler

The lambda expression used in the defer_with_time handler captures forwarded arguments. As previously noted, capturing forwarded arguments directly can lead to potential misuse of the moved-from state of these arguments if the lambda is invoked multiple times.

To prevent potential issues and ensure the lambda captures the arguments correctly, consider capturing them by moving the arguments instead of forwarding. Here's a suggested change:

- timer->async_wait(asio::bind_executor(m_strand, [self = this->shared_from_this(), timer, fn = std::forward<Fn>(fn), handler = std::forward<Handler>(handler), ... args = std::forward<Args>(args)](const asio::error_code& ec) mutable {
+ timer->async_wait(asio::bind_executor(m_strand, [self = this->shared_from_this(), timer, fn = std::move(fn), handler = std::move(handler), ... args = std::move(args)](const asio::error_code& ec) mutable {

This modification ensures that the lambda captures are appropriate for the intended single invocation per scheduling.

Likely invalid or redundant comment.


44-57: Review: Handling of value forwarding in lambda expressions

The implementation of defer uses std::forward to forward arguments to a lambda expression. This is generally used to maintain the value category of the arguments passed to a function template. However, when these forwarded arguments are captured by the lambda, they should be captured by value to ensure that they are moved, not forwarded again. This is because forwarding is context-dependent and only makes sense when forwarding to another function that accepts a universal reference.

The current implementation captures forwarded arguments in the lambda, which might lead to incorrect behavior or inefficiencies if the lambda is invoked multiple times, as the state of these arguments after the first invocation is indeterminate.

Consider capturing these arguments by value in the lambda to ensure correct and efficient behavior. Here's a suggested change:

- asio::post(asio::bind_executor(m_strand, [self = this->shared_from_this(), fn = std::forward<Fn>(fn), handler = std::forward<Handler>(handler), ... args = std::forward<Args>(args)]() mutable {
+ asio::post(asio::bind_executor(m_strand, [self = this->shared_from_this(), fn = std::move(fn), handler = std::move(handler), ... args = std::move(args)]() mutable {

This change ensures that the lambda captures moved versions of the arguments, which is more appropriate for the use case where the lambda is only supposed to be called once per scheduling.

Likely invalid or redundant comment.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 32570e3 and 2561ce4.

Files selected for processing (1)
  • src/rpp/rpp/schedulers/current_thread.hpp (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/rpp/rpp/schedulers/current_thread.hpp

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2561ce4 and c60a8c8.

Files selected for processing (1)
  • src/tests/rppasio/test_rppasio_scheduler.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/tests/rppasio/test_rppasio_scheduler.cpp

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Sep 7, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@victimsnino victimsnino merged commit ed65786 into victimsnino:v2 Sep 11, 2024
This was referenced Sep 15, 2024
This was referenced Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants