Skip to main content

CoolPropLib

Struct CoolPropLib 

Source
pub struct CoolPropLib(/* private fields */);
Expand description

Process-wide synchronization boundary for the loaded CoolProp dynamic library.

Use CoolPropLib::shared_access only for native operations known to support concurrent execution. Use CoolPropLib::exclusive_access for configuration and debug changes, global error or warning handling, REFPROP operations, VTPR construction or reload, tabular backends, and operations whose concurrency guarantees are unknown. When in doubt, use exclusive access.

Do not acquire a second access guard while another guard is held by the same thread. Drop the current guard before changing access modes.

For this synchronization boundary to be effective, all access to the bundled native library in a process must go through COOLPROP. Constructing bindings::CoolProp directly bypasses this boundary and requires equivalent process-wide synchronization from the caller.

Implementations§

Source§

impl CoolPropLib

Source

pub fn shared_access(&self) -> SharedAccess<'_>

Acquires shared access to the native library.

A shared guard does not make an arbitrary native function or backend reentrant. Use it only for operations explicitly known to support concurrent execution, such as calculations on independent states backed by HEOS, INCOMP, IF97, SRK, PR, PCSAFT, or an already-constructed VTPR state.

Some native functions report failure through a sentinel value and store details in the process-global errstring. Do not release shared access and then treat that string as the error from the failed call: another failure may replace it first. To retrieve attributable error details:

  1. Release the shared guard.
  2. Acquire exclusive access.
  3. Read and discard any stale errstring with get_global_param_string, which clears the stored message.
  4. Repeat the complete native call.
  5. Read errstring with get_global_param_string before releasing the same exclusive guard.

If error details are not needed, perform only steps 1–3; no retry is required.

Lock poisoning is recovered transparently; access does not panic solely because a previous guard holder panicked.

§Examples
use coolprop_sys::COOLPROP;

let coolprop = COOLPROP.shared_access();
let critical_temperature = unsafe { coolprop.Props1SI(c"Water".as_ptr(), c"Tcrit".as_ptr()) };
assert!(critical_temperature.is_finite());
Source

pub fn exclusive_access(&self) -> ExclusiveAccess<'_>

Acquires exclusive access to the native library.

Use this for configuration changes, pending-error retrieval, REFPROP calls, VTPR state construction, tabular backends, and other calls that touch mutable process-global state. When a native call may set a process-global error or warning, keep the same exclusive guard from that call through retrieval of its errstring or warnstring.

Lock poisoning is recovered transparently; access does not panic solely because a previous guard holder panicked.

§Examples
use coolprop_sys::COOLPROP;

let coolprop = COOLPROP.exclusive_access();
unsafe {
    coolprop.set_debug_level(0);
}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.