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

Make debug message callback Send + Sync. #267

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub type Renderbuffer = <Context as HasContext>::Renderbuffer;
pub type Query = <Context as HasContext>::Query;
pub type UniformLocation = <Context as HasContext>::UniformLocation;
pub type TransformFeedback = <Context as HasContext>::TransformFeedback;
pub type DebugCallback = Box<dyn FnMut(u32, u32, u32, u32, &str)>;
pub type DebugCallback = Box<dyn FnMut(u32, u32, u32, u32, &str) + Send + Sync>;

pub struct ActiveUniform {
pub size: i32,
Expand Down Expand Up @@ -1191,7 +1191,7 @@ pub trait HasContext {

unsafe fn debug_message_callback<F>(&mut self, callback: F)
where
F: FnMut(u32, u32, u32, u32, &str) + 'static;
F: FnMut(u32, u32, u32, u32, &str) + Send + Sync + 'static;

unsafe fn get_debug_message_log(&self, count: u32) -> Vec<DebugMessageLogEntry>;

Expand Down
22 changes: 21 additions & 1 deletion src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ struct DebugCallbackRawPtr {
callback: *mut std::os::raw::c_void,
}

unsafe impl Send for DebugCallbackRawPtr {}
unsafe impl Sync for DebugCallbackRawPtr {}

impl Drop for DebugCallbackRawPtr {
fn drop(&mut self) {
unsafe {
Expand Down Expand Up @@ -2707,7 +2710,7 @@ impl HasContext for Context {

unsafe fn debug_message_callback<F>(&mut self, callback: F)
where
F: FnMut(u32, u32, u32, u32, &str) + 'static,
F: FnMut(u32, u32, u32, u32, &str) + Send + Sync + 'static,
{
match self.debug_callback {
Some(_) => {
Expand Down Expand Up @@ -3215,3 +3218,20 @@ extern "system" fn raw_debug_message_callback(
(callback)(source, gltype, id, severity, msg);
});
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_send() {
fn assert_send<T: Send>() {}
assert_send::<Context>();
}

#[test]
fn test_sync() {
fn assert_sync<T: Sync>() {}
assert_sync::<Context>();
}
}
Loading