forked from scylladb/seastar
-
Notifications
You must be signed in to change notification settings - Fork 21
task: add task_context propagation support #268
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * This file is open source software, licensed to you under the terms | ||
| * of the Apache License, Version 2.0 (the "License"). See the NOTICE file | ||
| * distributed with this work for additional information regarding copyright | ||
| * ownership. You may not use this file except in compliance with the License. | ||
| * | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| /* | ||
| * Copyright 2026 Redpanda Data, Inc. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <seastar/core/future.hh> | ||
| #include <seastar/core/task.hh> | ||
| #include <seastar/util/defer.hh> | ||
|
|
||
| namespace seastar { | ||
|
|
||
| /// \addtogroup future-util | ||
| /// @{ | ||
|
|
||
| /// \brief Run a callable with \c ctx installed as the current task context. | ||
| /// | ||
| /// TLS is set to \c ctx for the duration of \c func's synchronous | ||
| /// execution, so tasks created inline (coroutine promises, \c .then() | ||
| /// continuations, etc.) inherit \c ctx at construction and carry it | ||
| /// through their own suspensions via their own \c task._context. The | ||
| /// caller's \c task._context is never modified, so this is safe | ||
| /// regardless of what task is running when invoked. | ||
| /// | ||
| /// \param ctx context to install; empty clears the context for the scope. | ||
| /// \param func callable returning a future; its async work inherits \c ctx. | ||
| /// \param args forwarded to \c func. | ||
| template <typename Func, typename... Args> | ||
| inline | ||
| auto | ||
| with_context([[maybe_unused]] const lw_shared_ptr<task_context>& ctx, | ||
| Func&& func, Args&&... args) noexcept { | ||
| #ifdef SEASTAR_TASK_CONTEXT | ||
| auto* prev = current_task_context(); | ||
| set_current_task_context(ctx.get()); | ||
| auto restore = defer([prev] () noexcept { | ||
| set_current_task_context(prev); | ||
| }); | ||
| #endif | ||
| return futurize_invoke(std::forward<Func>(func), std::forward<Args>(args)...); | ||
| } | ||
|
|
||
| /// @} | ||
|
|
||
| } // namespace seastar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.