From f97631e36320219e014332d1317551e23cfc1bd2 Mon Sep 17 00:00:00 2001 From: Billy Messenger Date: Sat, 19 Feb 2022 10:35:21 -0600 Subject: [PATCH 1/3] remove Sync requirement from NotificationHandler --- Cargo.toml | 2 +- src/client/async_client.rs | 2 +- src/client/callbacks.rs | 26 +++++++++++++------------- src/client/client_impl.rs | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2f3743058..79f8ef31e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" name = "jack" readme = "README.md" repository = "https://github.com/RustAudio/rust-jack" -version = "0.9.0" +version = "0.9.1" [dependencies] bitflags = "1" diff --git a/src/client/async_client.rs b/src/client/async_client.rs index 05593c36f..d9a37eae9 100644 --- a/src/client/async_client.rs +++ b/src/client/async_client.rs @@ -43,7 +43,7 @@ unsafe impl Sync for AsyncClient {} impl AsyncClient where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { /// Tell the JACK server that the program is ready to start processing audio. JACK will call the diff --git a/src/client/callbacks.rs b/src/client/callbacks.rs index ea060bc4d..937a7dbeb 100644 --- a/src/client/callbacks.rs +++ b/src/client/callbacks.rs @@ -104,7 +104,7 @@ pub trait ProcessHandler: Send { unsafe extern "C" fn thread_init_callback(data: *mut libc::c_void) where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -116,7 +116,7 @@ unsafe extern "C" fn shutdown( reason: *const libc::c_char, data: *mut libc::c_void, ) where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -130,7 +130,7 @@ unsafe extern "C" fn shutdown( unsafe extern "C" fn process(n_frames: Frames, data: *mut libc::c_void) -> libc::c_int where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -140,7 +140,7 @@ where unsafe extern "C" fn freewheel(starting: libc::c_int, data: *mut libc::c_void) where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -150,7 +150,7 @@ where unsafe extern "C" fn buffer_size(n_frames: Frames, data: *mut libc::c_void) -> libc::c_int where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -159,7 +159,7 @@ where unsafe extern "C" fn sample_rate(n_frames: Frames, data: *mut libc::c_void) -> libc::c_int where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -171,7 +171,7 @@ unsafe extern "C" fn client_registration( register: libc::c_int, data: *mut libc::c_void, ) where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -186,7 +186,7 @@ unsafe extern "C" fn port_registration( register: libc::c_int, data: *mut libc::c_void, ) where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -203,7 +203,7 @@ unsafe extern "C" fn port_rename( data: *mut libc::c_void, ) -> libc::c_int where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -220,7 +220,7 @@ unsafe extern "C" fn port_connect( connect: libc::c_int, data: *mut libc::c_void, ) where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -231,7 +231,7 @@ unsafe extern "C" fn port_connect( unsafe extern "C" fn graph_order(data: *mut libc::c_void) -> libc::c_int where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -240,7 +240,7 @@ where unsafe extern "C" fn xrun(data: *mut libc::c_void) -> libc::c_int where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); @@ -274,7 +274,7 @@ pub struct CallbackContext { impl CallbackContext where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { pub unsafe fn from_raw<'a>(ptr: *mut libc::c_void) -> &'a mut CallbackContext { diff --git a/src/client/client_impl.rs b/src/client/client_impl.rs index f667e93ff..5a14240cc 100644 --- a/src/client/client_impl.rs +++ b/src/client/client_impl.rs @@ -110,7 +110,7 @@ impl Client { process_handler: P, ) -> Result, Error> where - N: 'static + Send + Sync + NotificationHandler, + N: 'static + Send + NotificationHandler, P: 'static + Send + ProcessHandler, { AsyncClient::new(self, notification_handler, process_handler) From f025c1655770a249141a1d54d7dc926238091c61 Mon Sep 17 00:00:00 2001 From: Billy Messenger Date: Sat, 19 Feb 2022 11:27:12 -0600 Subject: [PATCH 2/3] remove Sync impl from AsyncClient --- src/client/async_client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/async_client.rs b/src/client/async_client.rs index d9a37eae9..c3ac9782e 100644 --- a/src/client/async_client.rs +++ b/src/client/async_client.rs @@ -39,7 +39,7 @@ pub struct AsyncClient { } unsafe impl Send for AsyncClient {} -unsafe impl Sync for AsyncClient {} +//unsafe impl Sync for AsyncClient {} impl AsyncClient where From d632cbf998559cf14cf0dfe75077ea13f212e3c3 Mon Sep 17 00:00:00 2001 From: Billy Messenger Date: Sat, 19 Feb 2022 11:46:52 -0600 Subject: [PATCH 3/3] make self in NotificationHandler::thread_init mutable --- examples/playback_capture.rs | 2 +- src/client/callbacks.rs | 2 +- src/client/test_callback.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/playback_capture.rs b/examples/playback_capture.rs index e4f755ecd..ec5d8ba5f 100644 --- a/examples/playback_capture.rs +++ b/examples/playback_capture.rs @@ -46,7 +46,7 @@ fn main() { struct Notifications; impl jack::NotificationHandler for Notifications { - fn thread_init(&self, _: &jack::Client) { + fn thread_init(&mut self, _: &jack::Client) { println!("JACK: thread init"); } diff --git a/src/client/callbacks.rs b/src/client/callbacks.rs index 937a7dbeb..14e95d5b8 100644 --- a/src/client/callbacks.rs +++ b/src/client/callbacks.rs @@ -14,7 +14,7 @@ pub trait NotificationHandler: Send { /// handled. /// /// It does not need to be suitable for real-time execution. - fn thread_init(&self, _: &Client) {} + fn thread_init(&mut self, _: &Client) {} /// Called when the JACK server shuts down the client thread. The function /// must be written as if diff --git a/src/client/test_callback.rs b/src/client/test_callback.rs index a626c0497..48998fb33 100644 --- a/src/client/test_callback.rs +++ b/src/client/test_callback.rs @@ -23,7 +23,7 @@ pub struct Counter { } impl NotificationHandler for Counter { - fn thread_init(&self, _: &Client) { + fn thread_init(&mut self, _: &Client) { self.thread_init_count.fetch_add(1, Ordering::Relaxed); }