From ab033c1f21f0e3ed6009a35dd1b2612ba363d456 Mon Sep 17 00:00:00 2001 From: Richard Acayan Date: Wed, 24 Jul 2024 22:23:46 -0400 Subject: [PATCH] core: graphics: use AtomicPtr This type is required to implement both the Send and Sync trait. --- src/core/graphics.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/graphics.rs b/src/core/graphics.rs index 90d4117..fc30593 100644 --- a/src/core/graphics.rs +++ b/src/core/graphics.rs @@ -18,6 +18,7 @@ use std::fs::File; use std::io::Read; use std::iter; use std::ptr; +use std::sync::atomic::AtomicPtr; use xkeysym::Keysym; fn convert_gray_to_bgrx(mut dest: ImgRefMut>, src: ImgRef, fg_color: BGR) @@ -79,7 +80,7 @@ pub struct Graphics { fontbufs: Vec>, labels: HashMap>, sublabels: HashMap>, - ft: freetype::FT_Library, + ft: AtomicPtr, x_scale: f64, y_scale: f64, @@ -206,7 +207,7 @@ impl Graphics { panic!("FreeType error {}", err); } - ft + AtomicPtr::new(ft) }; /* @@ -293,7 +294,7 @@ impl Graphics { unsafe { let mut ftface = std::ptr::null_mut(); - freetype::FT_New_Memory_Face(self.ft, + freetype::FT_New_Memory_Face(*self.ft.get_mut(), fontbuf.as_ptr(), fontbuf.len() as freetype::FT_Long, self.fonts[idx].1 as freetype::FT_Long, @@ -686,7 +687,7 @@ impl Drop for Graphics { fn drop(&mut self) { unsafe { - freetype::FT_Done_FreeType(self.ft); + freetype::FT_Done_FreeType(*self.ft.get_mut()); } } }