Skip to content

Commit

Permalink
feat: VoiceModelFile::close後もidmetasへのアクセスを保証
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Jan 23, 2025
1 parent 57a39ba commit 3aade90
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
12 changes: 10 additions & 2 deletions crates/voicevox_core/src/voice_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,12 @@ pub(crate) mod blocking {
Inner::open(path).block_on().map(Self)
}

/// VVMファイルを閉じる。
pub fn close(self) -> (VoiceModelId, VoiceModelMeta) {
let heads = self.0.into_heads();
(*heads.header.manifest.id(), heads.header.metas.clone())
}

pub(crate) fn inner(&self) -> &Inner<SingleTasked> {
&self.0
}
Expand Down Expand Up @@ -653,8 +659,10 @@ pub(crate) mod nonblocking {
}

/// VVMファイルを閉じる。
pub async fn close(self) {
self.0.into_heads().zip.into_inner().close().await;
pub async fn close(self) -> (VoiceModelId, VoiceModelMeta) {
let heads = self.0.into_heads();
heads.zip.into_inner().close().await;
(*heads.header.manifest.id(), heads.header.metas.clone())
}

pub(crate) fn inner(&self) -> &Inner<BlockingThreadPool> {
Expand Down
17 changes: 15 additions & 2 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,28 @@ pub extern "C" fn voicevox_voice_model_file_create_metas_json(

// TODO: cbindgenが`#[unsafe(no_mangle)]`に対応したら`#[no_mangle]`を置き換える
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
/// ::VoicevoxVoiceModelFile を、所有しているファイルディスクリプタを閉じた上で<b>破棄</b>(_destruct_)する
/// ::VoicevoxVoiceModelFile が所有しているファイルディスクリプタを閉じる
///
/// 破棄対象への他スレッドでのアクセスが存在する場合、それらがすべて終わるのを待ってから破棄する。
///
/// この関数の呼び出し後に破棄し終えた対象にアクセスすると、プロセスを異常終了する。
///
/// @param [in] model 破棄対象
/// @param [in] model 対象
#[no_mangle]
pub extern "C" fn voicevox_voice_model_file_close(model: *mut VoicevoxVoiceModelFile) {
init_logger_once();
todo!();
}

// TODO: cbindgenが`#[unsafe(no_mangle)]`に対応したら`#[no_mangle]`を置き換える
// SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
/// ::VoicevoxVoiceModelFile を、所有しているファイルディスクリプタを閉じた上で<b>破棄</b>(_destruct_)する。
///
/// 破棄対象への他スレッドでのアクセスが存在する場合、それらがすべて終わるのを待ってから破棄する。
///
/// @param [in] model 破棄対象
#[no_mangle]
pub extern "C" fn voicevox_voice_model_file_delete(model: *mut VoicevoxVoiceModelFile) {
init_logger_once();
model.drop_body();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ public class VoiceModelFile implements Closeable {

private long handle;

/** ID。 */
/**
* ID。
*
* <p>{@link #close}の後でも利用可能。
*/
@Nonnull public final UUID id;

/** メタ情報。 */
/**
* メタ情報。
*
* <p>{@link #close}の後でも利用可能。
*/
@Nonnull public final SpeakerMeta[] metas;

public VoiceModelFile(String modelPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ class VoiceModelFile:
...
@property
def id(self) -> VoiceModelId:
"""ID。"""
"""
ID。
:attr:`close` および :attr:`__aexit__` の後でも利用可能。
"""
...
@property
def metas(self) -> list[SpeakerMeta]:
"""
メタ情報。
この中身を書き換えても、 ``VoiceModelFile`` としての動作には影響しない。
:attr:`close` および :attr:`__aexit__` の後でも利用可能。
"""
...
async def __aenter__(self) -> "VoiceModelFile": ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ class VoiceModelFile:
...
@property
def id(self) -> VoiceModelId:
"""ID。"""
"""
ID。
:attr:`close` および :attr:`__exit__` の後でも利用可能。
"""
...
@property
def metas(self) -> list[SpeakerMeta]:
"""
メタ情報。
この中身を書き換えても、 ``VoiceModelFile`` としての動作には影響しない。
:attr:`close` および :attr:`__exit__` の後でも利用可能。
"""
...
def __enter__(self) -> "VoiceModelFile": ...
Expand Down

0 comments on commit 3aade90

Please sign in to comment.