fmod/core/file.rs
1// Copyright (c) 2024 Lily 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 fmod_sys::*;
8
9/// Information function to retrieve the state of FMOD disk access.
10///
11/// Do not use this function to synchronize your own reads with, as due to timing,
12/// you might call this function and it says false = it is not busy,
13/// but the split second after calling this function, internally FMOD might set it to busy.
14/// Use [`get_disk_busy`] for proper mutual exclusion as it uses semaphores.
15pub fn get_disk_busy() -> Result<bool> {
16 let mut busy = 0;
17 unsafe {
18 FMOD_File_GetDiskBusy(&mut busy).to_result()?;
19 }
20 Ok(busy > 0)
21}
22
23/// Sets the busy state for disk access ensuring mutual exclusion of file operations.
24///
25/// If file IO is currently being performed by FMOD this function will block until it has completed.
26///
27/// This function should be called in pairs once to set the state, then again to clear it once complete.
28pub fn set_disk_busy(busy: bool) -> Result<()> {
29 unsafe { FMOD_File_SetDiskBusy(std::ffi::c_int::from(busy)).to_result() }
30}