Skip to content

Commit

Permalink
Fix incorrect LazyThreadSafetyMode.NONE usages, because:
Browse files Browse the repository at this point in the history
- it's an undefined behavior on Native platforms
- to ensure singleton property
  • Loading branch information
Him188 committed Sep 24, 2024
1 parent e54ac69 commit 66e5acd
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum class WebViewDriver {
}

companion object {
val enabledEntries by lazy(LazyThreadSafetyMode.NONE) {
val enabledEntries by lazy {
entries.sortedDescending()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.data.source.danmaku.protocol

import kotlinx.serialization.Serializable
import me.him188.ani.app.data.source.danmaku.protocol.ReleaseClass.entries


@Serializable
Expand Down Expand Up @@ -55,7 +65,7 @@ enum class ReleaseClass {
/**
* 在客户端启用了的项目
*/
val enabledEntries by lazy(LazyThreadSafetyMode.NONE) {
val enabledEntries by lazy {
entries.filter { it != RC }.sortedDescending()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.data.source.media.fetch

import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -93,7 +102,7 @@ class FilteredMediaSourceResults(
// }
//}

private val EmptyFilteredMediaSourceResults by lazy(LazyThreadSafetyMode.NONE) {
private val EmptyFilteredMediaSourceResults by lazy {
FilteredMediaSourceResults(flowOf(emptyList()), flowOf(MediaSelectorSettings.Default))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class SelectorMediaSource(
}.merge()
}

override val matcher: WebVideoMatcher by lazy(LazyThreadSafetyMode.NONE) {
override val matcher: WebVideoMatcher by lazy(LazyThreadSafetyMode.PUBLICATION) {
WebVideoMatcher { url, _ ->
engine.matchWebVideo(url, arguments.searchConfig.matchVideo)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.tools.torrent

import kotlinx.coroutines.CoroutineName
Expand Down Expand Up @@ -52,7 +61,7 @@ class DefaultTorrentManager(
)
}

override val engines: List<TorrentEngine> by lazy(LazyThreadSafetyMode.NONE) {
override val engines: List<TorrentEngine> by lazy {
// 注意, 是故意只启用一个下载器的, 因为每个下载器都会创建一个 DirectoryMediaCacheStorage
// 并且使用相同的 mediaSourceId: MediaCacheManager.LOCAL_FS_MEDIA_SOURCE_ID.
// 搜索数据源时会使用 mediaSourceId 作为 map key, 导致总是只会用一个 storage.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright (C) 2024 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.app.ui.subject.episode.mediaFetch

import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -135,7 +144,7 @@ class MediaSourceResultsPresentation(
val totalSourceCount by derivedStateOf { list.count { it.kind != MediaSourceKind.LocalCache } } // 缓存数据源属于内部的, 用户应当无感
}

private val EmptyMediaSourceResultsPresentation by lazy(LazyThreadSafetyMode.NONE) {
private val EmptyMediaSourceResultsPresentation by lazy {
MediaSourceResultsPresentation(emptyMediaSourceResults(), EmptyCoroutineContext)
}

Expand Down

0 comments on commit 66e5acd

Please sign in to comment.