Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Sync requirement from NotificationHandler #167

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion examples/playback_capture.rs
Original file line number Diff line number Diff line change
@@ -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");
}

4 changes: 2 additions & 2 deletions src/client/async_client.rs
Original file line number Diff line number Diff line change
@@ -39,11 +39,11 @@ pub struct AsyncClient<N, P> {
}

unsafe impl<N, P> Send for AsyncClient<N, P> {}
unsafe impl<N, P> Sync for AsyncClient<N, P> {}
//unsafe impl<N, P> Sync for AsyncClient<N, P> {}

impl<N, P> AsyncClient<N, P>
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
28 changes: 14 additions & 14 deletions src/client/callbacks.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -104,7 +104,7 @@ pub trait ProcessHandler: Send {

unsafe extern "C" fn thread_init_callback<N, P>(data: *mut libc::c_void)
where
N: 'static + Send + Sync + NotificationHandler,
N: 'static + Send + NotificationHandler,
P: 'static + Send + ProcessHandler,
{
let ctx = CallbackContext::<N, P>::from_raw(data);
@@ -116,7 +116,7 @@ unsafe extern "C" fn shutdown<N, P>(
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::<N, P>::from_raw(data);
@@ -130,7 +130,7 @@ unsafe extern "C" fn shutdown<N, P>(

unsafe extern "C" fn process<N, P>(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::<N, P>::from_raw(data);
@@ -140,7 +140,7 @@ where

unsafe extern "C" fn freewheel<N, P>(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::<N, P>::from_raw(data);
@@ -150,7 +150,7 @@ where

unsafe extern "C" fn buffer_size<N, P>(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::<N, P>::from_raw(data);
@@ -159,7 +159,7 @@ where

unsafe extern "C" fn sample_rate<N, P>(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::<N, P>::from_raw(data);
@@ -171,7 +171,7 @@ unsafe extern "C" fn client_registration<N, P>(
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::<N, P>::from_raw(data);
@@ -186,7 +186,7 @@ unsafe extern "C" fn port_registration<N, P>(
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::<N, P>::from_raw(data);
@@ -203,7 +203,7 @@ unsafe extern "C" fn port_rename<N, P>(
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::<N, P>::from_raw(data);
@@ -220,7 +220,7 @@ unsafe extern "C" fn port_connect<N, P>(
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::<N, P>::from_raw(data);
@@ -231,7 +231,7 @@ unsafe extern "C" fn port_connect<N, P>(

unsafe extern "C" fn graph_order<N, P>(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::<N, P>::from_raw(data);
@@ -240,7 +240,7 @@ where

unsafe extern "C" fn xrun<N, P>(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::<N, P>::from_raw(data);
@@ -274,7 +274,7 @@ pub struct CallbackContext<N, P> {

impl<N, P> CallbackContext<N, P>
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<N, P> {
2 changes: 1 addition & 1 deletion src/client/client_impl.rs
Original file line number Diff line number Diff line change
@@ -110,7 +110,7 @@ impl Client {
process_handler: P,
) -> Result<AsyncClient<N, P>, Error>
where
N: 'static + Send + Sync + NotificationHandler,
N: 'static + Send + NotificationHandler,
P: 'static + Send + ProcessHandler,
{
AsyncClient::new(self, notification_handler, process_handler)
2 changes: 1 addition & 1 deletion src/client/test_callback.rs
Original file line number Diff line number Diff line change
@@ -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);
}