Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
7ad3bfbf
Commit
7ad3bfbf
authored
Feb 18, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add MiraiAtomicBoolean, fuck atomicfu
parent
eafa943e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
13 deletions
+46
-13
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/event/internal/MiraiAtomicBoolean.kt
...tlin/net/mamoe/mirai/event/internal/MiraiAtomicBoolean.kt
+17
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
.../net.mamoe.mirai/event/internal/InternalEventListeners.kt
+11
-13
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/internal/MiraiAtomicBoolean.kt
...tlin/net/mamoe/mirai/event/internal/MiraiAtomicBoolean.kt
+18
-0
No files found.
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/event/internal/MiraiAtomicBoolean.kt
0 → 100644
View file @
7ad3bfbf
package
net.mamoe.mirai.event.internal
import
java.util.concurrent.atomic.AtomicBoolean
internal
actual
class
MiraiAtomicBoolean
actual
constructor
(
initial
:
Boolean
)
{
private
val
delegate
:
AtomicBoolean
=
AtomicBoolean
(
initial
)
actual
fun
compareAndSet
(
expect
:
Boolean
,
update
:
Boolean
):
Boolean
{
return
delegate
.
compareAndSet
(
expect
,
update
)
}
actual
var
value
:
Boolean
get
()
=
delegate
.
get
()
set
(
value
)
{
delegate
.
set
(
value
)
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
View file @
7ad3bfbf
...
...
@@ -9,7 +9,6 @@
package
net.mamoe.mirai.event.internal
import
kotlinx.atomicfu.atomic
import
kotlinx.coroutines.*
import
net.mamoe.mirai.event.Event
import
net.mamoe.mirai.event.EventDisabled
...
...
@@ -79,6 +78,13 @@ internal fun <E : Event> KClass<out E>.listeners(): EventListeners<E> = EventLis
internal
class
EventListeners
<
E
:
Event
>
:
LockFreeLinkedList
<
Listener
<
E
>>()
internal
expect
class
MiraiAtomicBoolean
(
initial
:
Boolean
)
{
fun
compareAndSet
(
expect
:
Boolean
,
update
:
Boolean
):
Boolean
var
value
:
Boolean
}
/**
* 管理每个事件 class 的 [EventListeners].
* [EventListeners] 是 lazy 的: 它们只会在被需要的时候才创建和存储.
...
...
@@ -88,16 +94,8 @@ internal object EventListenerManager {
private
val
registries
=
LockFreeLinkedList
<
Registry
<
*
>>()
private
val
lock
=
atomic
(
false
)
private
fun
setLockValue
(
value
:
Boolean
)
{
lock
.
value
=
value
}
@Suppress
(
"BooleanLiteralArgument"
)
private
fun
trySetLockTrue
():
Boolean
{
return
lock
.
compareAndSet
(
false
,
true
)
}
// 不要用 atomicfu. 在 publish 后会出现 VerifyError
private
val
lock
:
MiraiAtomicBoolean
=
MiraiAtomicBoolean
(
false
)
@Suppress
(
"UNCHECKED_CAST"
,
"BooleanLiteralArgument"
)
internal
tailrec
fun
<
E
:
Event
>
get
(
clazz
:
KClass
<
out
E
>):
EventListeners
<
E
>
{
...
...
@@ -106,10 +104,10 @@ internal object EventListenerManager {
return
it
.
listeners
as
EventListeners
<
E
>
}
}
if
(
trySetLockTrue
(
))
{
if
(
lock
.
compareAndSet
(
false
,
true
))
{
val
registry
=
Registry
(
clazz
,
EventListeners
())
registries
.
addLast
(
registry
)
setLockValue
(
false
)
lock
.
value
=
false
return
registry
.
listeners
as
EventListeners
<
E
>
}
return
get
(
clazz
)
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/internal/MiraiAtomicBoolean.kt
0 → 100644
View file @
7ad3bfbf
package
net.mamoe.mirai.event.internal
import
java.util.concurrent.atomic.AtomicBoolean
internal
actual
class
MiraiAtomicBoolean
actual
constructor
(
initial
:
Boolean
)
{
private
val
delegate
:
AtomicBoolean
=
AtomicBoolean
(
initial
)
actual
fun
compareAndSet
(
expect
:
Boolean
,
update
:
Boolean
):
Boolean
{
return
delegate
.
compareAndSet
(
expect
,
update
)
}
actual
var
value
:
Boolean
get
()
=
delegate
.
get
()
set
(
value
)
{
delegate
.
set
(
value
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment