Skip to content

Commit

Permalink
Try multithreaded client creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedrano committed Sep 9, 2024
1 parent c1e0281 commit 2a13f6c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[profile.default]
test-threads = 1
slow-timeout = { period = "30s", terminate-after = 4 }
fail-fast = false
4 changes: 2 additions & 2 deletions src/client/async_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Error> {
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 {
Expand Down Expand Up @@ -107,7 +107,7 @@ impl<N, P> AsyncClient<N, P> {
// 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<Box<CallbackContext<N, P>>, 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);
}
Expand Down
16 changes: 9 additions & 7 deletions src/client/client_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -552,7 +554,7 @@ impl Client {
source_port: &Port<A>,
destination_port: &Port<B>,
) -> 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()?)
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 2a13f6c

Please sign in to comment.