Skip to content

Ensure static executor and timer#14

Closed
eivindbergem wants to merge 2 commits intomasterfrom
static-executor
Closed

Ensure static executor and timer#14
eivindbergem wants to merge 2 commits intomasterfrom
static-executor

Conversation

@eivindbergem
Copy link
Copy Markdown
Collaborator

The priority queue used by the executor and timer is only safe if it is static. Because of this, functions such as polling tasks are now unsafe. By wrapping the executor in a struct that holds a static reference, we can safely call the unsafe functions from the wrapper:

impl ShouldBeStatic {
    unsafe fn danger(&mut self) {
        do_unsafe_stuff_that_is_fine_if_static();
    }
}

struct ShoudBeStaticRef {
    target: &'static mut ShouldBeStatic,
}

impl ShouldBeStaticRef {
    fn danger(&mut self) {
        unsafe { self.target.danger(); }
    }
}

- Polling the Executor is safe if the Executor is static. However,
  adding a static lifetime to self when polling makes the borrow checker
  unhappy. By adding a wrapper struct for the Executor that holds a
  static mutable reference, we can poll safely from the wrapper.
- The priority queue sender holds static reference to queue, and is
  therefor unsafe. It is up to the caller to ensure a static lifetime
  for the queue.
@eivindbergem
Copy link
Copy Markdown
Collaborator Author

Continued in #18

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.

1 participant