Fix undefined behavior

There's no guarantee that the lock is being held by the main thread at
that moment, so the unsafe block violated the safety contract.
macos-click-through
MultisampledNight 3 years ago
parent ac48a6cfb4
commit ee0037a31e
No known key found for this signature in database
GPG Key ID: 02B1BAF6A675FF9B

@ -69,9 +69,6 @@ impl Settings {
pub fn set<T: Clone + Send + Sync + 'static>(&self, t: &T) { pub fn set<T: Clone + Send + Sync + 'static>(&self, t: &T) {
let type_id: TypeId = TypeId::of::<T>(); let type_id: TypeId = TypeId::of::<T>();
let t: T = (*t).clone(); let t: T = (*t).clone();
unsafe {
self.settings.force_unlock_write();
}
let mut write_lock = self.settings.write(); let mut write_lock = self.settings.write();
write_lock.insert(type_id, Box::new(t)); write_lock.insert(type_id, Box::new(t));
} }

Loading…
Cancel
Save