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

fix(dispatch2): Add 'static bound to exec_async #690

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/dispatch2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
- **BREAKING**: Use `extern "C-unwind"` instead of `extern "C"` in certain functions that required that.
- **BREAKING**: Use `isize` instead of `usize` in certain functions where that is more correct.
- **BREAKING**: An `F: 'static` bound was added to the following methods to make
sure any referenced values passed to them are borrowed for long
enough since they perform their `work` asynchronously (#689):
- `Group::exec_async`
- `Queue::exec_async`
- `Queue::barrier_async`
- `Queue::barrier_async_and_wait`


## 0.1.0 - 2022-10-02
Expand Down
4 changes: 3 additions & 1 deletion crates/dispatch2/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ impl Group {
/// Submit a function to a [Queue] and associates it with the [Group].
pub fn exec_async<F>(&self, queue: &Queue, work: F)
where
F: Send + FnOnce(),
// We need `'static` to make sure any referenced values are borrowed for
// long enough since `work` will be performed asynchronously.
F: Send + FnOnce() + 'static,
{
let work_boxed = Box::into_raw(Box::new(work)).cast::<c_void>();

Expand Down
12 changes: 9 additions & 3 deletions crates/dispatch2/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ impl Queue {
/// Submit a function for asynchronous execution on the [Queue].
pub fn exec_async<F>(&self, work: F)
where
F: Send + FnOnce(),
// We need `'static` to make sure any referenced values are borrowed for
// long enough since `work` will be performed asynchronously.
F: Send + FnOnce() + 'static,
{
let work_boxed = Box::into_raw(Box::new(work)).cast();

Expand Down Expand Up @@ -254,7 +256,9 @@ impl Queue {
/// Enqueue a barrier function for asynchronous execution on the [Queue] and return immediately.
pub fn barrier_async<F>(&self, work: F)
where
F: Send + FnOnce(),
// We need `'static` to make sure any referenced values are borrowed for
// long enough since `work` will be performed asynchronously.
F: Send + FnOnce() + 'static,
{
let work_boxed = Box::into_raw(Box::new(work)).cast();

Expand All @@ -276,7 +280,9 @@ impl Queue {
/// Submit a function for synchronous execution and mark the function as a barrier for subsequent concurrent tasks.
pub fn barrier_async_and_wait<F>(&self, work: F)
where
F: Send + FnOnce(),
// We need `'static` to make sure any referenced values are borrowed for
// long enough since `work` will be performed asynchronously.
F: Send + FnOnce() + 'static,
{
let work_boxed = Box::into_raw(Box::new(work)).cast();

Expand Down
Loading