Skip to content

Commit

Permalink
Retain run loop (zed-industries#11241)
Browse files Browse the repository at this point in the history
Contributes: zed-industries#11168


https://developer.apple.com/documentation/corefoundation/1542428-cfrunloopgetcurrent
implies that we should be `CFRetain`ing the run loop.

Lets do that, and see if it reduces the number of crashes we see.

Release Notes:

- (maybe) Fix a rare crash in watching settings files.
  • Loading branch information
ConradIrwin authored and luckydye committed May 2, 2024
1 parent 1881e33 commit 1f0abfd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/fsevent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bitflags.workspace = true
parking_lot.workspace = true

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation.workspace = true
fsevent-sys = "3.0.2"

[dev-dependencies]
Expand Down
4 changes: 3 additions & 1 deletion crates/fsevent/src/fsevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ impl EventStream {
{
self.state.callback = Some(Box::new(f));
unsafe {
let run_loop = cf::CFRunLoopGetCurrent();
let run_loop =
core_foundation::base::CFRetain(cf::CFRunLoopGetCurrent()) as *mut c_void;
{
let mut state = self.lifecycle.lock();
match *state {
Expand Down Expand Up @@ -248,6 +249,7 @@ impl Drop for Handle {
if let Lifecycle::Running(run_loop) = *state {
unsafe {
cf::CFRunLoopStop(run_loop);
cf::CFRelease(run_loop)
}
}
*state = Lifecycle::Stopped;
Expand Down

0 comments on commit 1f0abfd

Please sign in to comment.