From 2a13f6c8c65972ab9a7804bde460594e3816ed5a Mon Sep 17 00:00:00 2001 From: Will Medrano Date: Mon, 9 Sep 2024 06:34:55 -0700 Subject: [PATCH] Try multithreaded client creation. --- .config/nextest.toml | 1 - src/client/async_client.rs | 4 ++-- src/client/client_impl.rs | 16 +++++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.config/nextest.toml b/.config/nextest.toml index 8c9d0e55..e2dfde4f 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -1,4 +1,3 @@ [profile.default] -test-threads = 1 slow-timeout = { period = "30s", terminate-after = 4 } fail-fast = false \ No newline at end of file diff --git a/src/client/async_client.rs b/src/client/async_client.rs index ed57aad2..26834fe0 100644 --- a/src/client/async_client.rs +++ b/src/client/async_client.rs @@ -52,7 +52,7 @@ where /// `notification_handler` and `process_handler` are consumed, but they are returned when /// `Client::deactivate` is called. pub fn new(client: Client, notification_handler: N, process_handler: P) -> Result { - let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); + // let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); unsafe { sleep_on_test(); let mut callback_context = Box::new(CallbackContext { @@ -107,7 +107,7 @@ impl AsyncClient { // Helper function for deactivating. Any function that calls this should // have ownership of self and no longer use it after this call. unsafe fn maybe_deactivate(&mut self) -> Result>, Error> { - let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); + // let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); if self.callback.is_none() { return Err(Error::ClientIsNoLongerAlive); } diff --git a/src/client/client_impl.rs b/src/client/client_impl.rs index 609a3a24..8bb750d2 100644 --- a/src/client/client_impl.rs +++ b/src/client/client_impl.rs @@ -51,7 +51,7 @@ impl Client { /// Although the client may be successful in opening, there still may be some errors minor /// errors when attempting to opening. To access these, check the returned `ClientStatus`. pub fn new(client_name: &str, options: ClientOptions) -> Result<(Self, ClientStatus), Error> { - let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); + // let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); // All of the jack_sys functions below assume the client library is loaded and will panic if // it is not @@ -61,8 +61,10 @@ impl Client { } unsafe { - jack_sys::jack_set_error_function(Some(silent_handler)); - jack_sys::jack_set_info_function(Some(silent_handler)); + // jack_sys::jack_set_error_function(Some(silent_handler)); + // jack_sys::jack_set_info_function(Some(silent_handler)); + jack_sys::jack_set_error_function(Some(error_handler)); + jack_sys::jack_set_info_function(Some(info_handler)); } sleep_on_test(); let mut status_bits = 0; @@ -552,7 +554,7 @@ impl Client { source_port: &Port, destination_port: &Port, ) -> Result<(), Error> { - let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); + // let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); self.connect_ports_by_name(&source_port.name()?, &destination_port.name()?) } @@ -670,7 +672,7 @@ impl Client { /// Close the client. impl Drop for Client { fn drop(&mut self) { - let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); + // let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); debug_assert!(!self.raw().is_null()); // Rep invariant // Close the client sleep_on_test(); @@ -793,7 +795,7 @@ pub struct CycleTimes { unsafe extern "C" fn error_handler(msg: *const libc::c_char) { let res = catch_unwind(|| match std::ffi::CStr::from_ptr(msg).to_str() { - Ok(msg) => log::error!("{}", msg), + Ok(msg) => eprintln!("{}", msg), Err(err) => log::error!("failed to log to JACK error: {:?}", err), }); if let Err(err) = res { @@ -804,7 +806,7 @@ unsafe extern "C" fn error_handler(msg: *const libc::c_char) { unsafe extern "C" fn info_handler(msg: *const libc::c_char) { let res = catch_unwind(|| match std::ffi::CStr::from_ptr(msg).to_str() { - Ok(msg) => log::info!("{}", msg), + Ok(msg) => eprintln!("{}", msg), Err(err) => log::error!("failed to log to JACK info: {:?}", err), }); if let Err(err) = res {