-
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
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
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
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.
It's referring to other borrows made by the device context. Not sure how best to phrase this.
@@ -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?
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.
DeviceContext
is private to the file.
6d2a559
to
49d2cfa
Compare
Logging this from Slack for reference: Atomics are for multi-threaded accesses but here it's single-threaded so using Since this is all single-threaded, using |
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.)