Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize mutex implementation #2851

Merged
merged 1 commit into from
Aug 2, 2021
Merged

Optimize mutex implementation #2851

merged 1 commit into from
Aug 2, 2021

Conversation

qwwdfsad
Copy link
Collaborator

* Get rid of addLastIf and DCSS primitive during contention
* Leverage constants returned by tryResume* and simplify signatures

@qwwdfsad qwwdfsad requested a review from elizarov July 30, 2021 16:21
@@ -352,31 +369,37 @@ internal class MutexImpl(locked: Boolean) : Mutex, SelectClause2<Any?, Mutex> {
private abstract inner class LockWaiter(
@JvmField val owner: Any?
) : LockFreeLinkedListNode(), DisposableHandle {
private val isTaken = atomic<Boolean>(false)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's possible to avoid this field and use an atomic wrapper over the owner (then it has to be passed between tryResumeLockWaiter and completeResumeLockWaiter), but I found it way too harsh

@qwwdfsad qwwdfsad removed the request for review from elizarov July 30, 2021 17:35
@qwwdfsad qwwdfsad marked this pull request as draft July 30, 2021 17:35
    * Get rid of addLastIf and DCSS primitive during contention
    * Leverage constants returned by tryResume* and simplify signatures
@qwwdfsad qwwdfsad requested a review from elizarov July 30, 2021 17:38
@qwwdfsad qwwdfsad marked this pull request as ready for review July 30, 2021 17:38
Copy link
Contributor

@elizarov elizarov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Very good. Indeed, the "add / recheck / invalidate if something changed" trick works fine for locks.

@qwwdfsad qwwdfsad merged commit 7e762d3 into develop Aug 2, 2021
@qwwdfsad qwwdfsad deleted the optimize-mutex branch August 2, 2021 10:36
pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this pull request Sep 14, 2022
* Get rid of addLastIf and DCSS primitive during contention
* Leverage constants returned by tryResume* and simplify signatures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants