fmod/core/file.rs
1// Copyright (c) 2024 Melody Madeline Lyons
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use crate::{FmodResultExt, Result};
8use fmod_sys::*;
9
10/// Information function to retrieve the state of FMOD disk access.
11///
12/// Do not use this function to synchronize your own reads with, as due to timing,
13/// you might call this function and it says false = it is not busy,
14/// but the split second after calling this function, internally FMOD might set it to busy.
15/// Use [`get_disk_busy`] for proper mutual exclusion as it uses semaphores.
16pub fn get_disk_busy() -> Result<bool> {
17 let mut busy = 0;
18 unsafe {
19 FMOD_File_GetDiskBusy(&raw mut busy).to_result()?;
20 }
21 Ok(busy > 0)
22}
23
24/// Sets the busy state for disk access ensuring mutual exclusion of file operations.
25///
26/// If file IO is currently being performed by FMOD this function will block until it has completed.
27///
28/// This function should be called in pairs once to set the state, then again to clear it once complete.
29pub fn set_disk_busy(busy: bool) -> Result<()> {
30 unsafe { FMOD_File_SetDiskBusy(std::ffi::c_int::from(busy)).to_result() }
31}