-
Notifications
You must be signed in to change notification settings - Fork 15
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
Remove static mut in graphics_device.rs
#674
base: task/r-test-lock-static-mut
Are you sure you want to change the base?
Conversation
26ce4d6
to
e76f980
Compare
e76f980
to
5fa82bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See slack for more comments
// Refcell safety: Only called on the R thread and we make sure not to | ||
// recurse into `DeviceContext` methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no refcell in this function IIUC
comm_manager_tx: Sender<CommManagerEvent>, | ||
iopub_tx: Sender<IOPubMessage>, | ||
dynamic_plots: bool, | ||
) { | ||
let id = unwrap!(self._id.clone(), None => { | ||
// Refcell Safety: Short borrows in the file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment wrong? More like Cloning to borrow for as short as possible
@@ -271,10 +279,13 @@ impl DeviceContext { | |||
} | |||
|
|||
// Save our new socket. | |||
self._channels.insert(id.to_string(), socket.clone()); | |||
// Refcell Safety: Short borrows in the file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "in the file" mean?
Progress towards #661.
DEVICE_CONTEXT
is now a thread-local variable to reflect the fact it should only be accessed from the R thread.It's wrapped in a
RefCell
that is initialized fromRMain
on startup. All subsequent accesses are read-only and never panic.The device context requires mutable state. Where possible we use
Cell
which never panics. In a couple of places we useRefCell
with care not to double-borrow on mutation, mainly by only performing short borrows to prevent holding a reference while recusing into a device context method by accident. (I haven't examined whether that would be possible in principle to recurse into a method as I'm not familiar with the graphics device code and its R hooks. I just made sure the borrows were short or at least only invoked pure Rust code.)