Skip to content
Open
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: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ version = "0.0.1"
edition = "2021"
description = "The dggal-rust crate"
license-file = "LICENSE"

[dependencies]
#ecrt = { path = "../ecrt" }
rust-version = "1.88"
4 changes: 4 additions & 0 deletions src/bindings/dggal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ macro_rules! CRS {
pub const epsg: dggal_sys::CRSRegistry = dggal_sys::CRSRegistry_CRSRegistry_epsg;
pub const ogc: dggal_sys::CRSRegistry = dggal_sys::CRSRegistry_CRSRegistry_ogc;

unsafe impl Sync for DGGRS {}
unsafe impl Send for DGGRS {}
unsafe impl Sync for DGGAL {}
unsafe impl Send for DGGAL {}
Comment on lines +72 to +75
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerstlouis I had a few issues to get tests to work concurrently and I just expanded your commit to also wrap DGGAL with Send + Sync. Do you think it is okay?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichaelJendryke To run the initial example concurrency test that was not necessary.

Could you please clarify what the new test is doing?

What is this new lazy mutex stuff doing?

The DGGRS class is already thread safe and none of the methods modifies the object state, so they can freely be executed in parallel without locking any mutex.

The Application class is intended to be a singleton.
Instantiating multiple Application class will likely break things at this point.
Are you trying to use Application in multiple threads?
Since it's only used for instantiating DGGAL, which is then use to instantiate the DGGRS(s), this would ideally all be done in the main thread during initialization stage (though I don't think it would cause any problem to instantiate a new DGGRS from the same DGGAL from other threads as needed later on).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this Lazy stuff is just to try to avoid the user having to initialize this thing themselves and ensure there is global singleton set up for these objects? I think I actually had something like this in the bindings for an earlier version.

I remember being advised against this when developing the Rust bindings, but I understand doing this if this is to avoid GeoPlegma users having to do this themselves since it's specific to a particular backend.

pub struct DGGRS {
imp: dggal_sys::DGGRS,
mDGGAL: ecrt_sys::Module,
Expand Down
18 changes: 10 additions & 8 deletions src/bindings/ecrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ impl Deref for Instance {
}

// eC runtime singleton
unsafe impl Sync for Application {}
unsafe impl Send for Application {}
Comment on lines +102 to +103
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerstlouis also here for the Application

pub struct Application {
pub app: ecrt_sys::Application,
}
Expand Down Expand Up @@ -133,34 +135,34 @@ pub trait TTAU64 {

impl TTAU64 for u64 {
fn from_u64(value: u64) -> Self {
unsafe { transmute(value) }
value
}
fn to_u64(&self) -> u64 {
unsafe { transmute(*self) }
*self
}
}
impl TTAU64 for i64 {
fn from_u64(value: u64) -> Self {
unsafe { transmute(value) }
u64::cast_signed(value)
}
fn to_u64(&self) -> u64 {
unsafe { transmute(*self) }
i64::cast_unsigned(*self)
}
}
impl TTAU64 for f64 {
fn from_u64(value: u64) -> Self {
unsafe { transmute(value) }
f64::from_bits(value)
}
fn to_u64(&self) -> u64 {
unsafe { transmute(*self) }
f64::to_bits(*self)
}
}
impl TTAU64 for f32 {
fn from_u64(value: u64) -> Self {
unsafe { transmute(value as u32) }
f32::from_bits(value as u32)
}
fn to_u64(&self) -> u64 {
unsafe { transmute::<f32, u32>(*self) as u64 }
f32::to_bits(*self) as u64
}
}
impl TTAU64 for u32 {
Expand Down
5 changes: 5 additions & 0 deletions src/ffi/dggal_cffi.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(improper_ctypes)]

/* originally generated by rust-bindgen 0.71.1 */

use crate::ffi::ecrt_cffi as ecrt_sys;
Expand Down
5 changes: 5 additions & 0 deletions src/ffi/ecrt_cffi.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(improper_ctypes)]

/* originally generated by rust-bindgen 0.71.1 */

pub const _STDIO_H: u32 = 1;
Expand Down