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

threads: remove unused recursive mutex support #15995

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kasper93
Copy link
Contributor

@kasper93 kasper93 commented Mar 3, 2025

The only use of MP_MUTEX_RECURSIVE is in vdpau.c. If it is disabled, remove the unused code. This simplifies the win32 implementation by eliminating unnecessary critical section references.

Copy link

github-actions bot commented Mar 3, 2025

Download the artifacts for this pull request:

Windows
macOS

@na-na-hi
Copy link
Contributor

na-na-hi commented Mar 3, 2025

Shouldn't win32 recursive mutex be removed completely instead of ifdef? I don't think vdpau is supported on win32.

@kasper93
Copy link
Contributor Author

kasper93 commented Mar 3, 2025

Shouldn't win32 recursive mutex be removed completely instead of ifdef? I don't think vdpau is supported on win32.

The idea is if in the feature anyone wants to use it the code is there. When I added it initially there was more users of recursive mutex. I also don't like those ifdefs, but not having feature parity between wrappers would be awkward.

@na-na-hi
Copy link
Contributor

na-na-hi commented Mar 3, 2025

When I added it initially there was more users of recursive mutex. I also don't like those ifdefs, but not having feature parity between wrappers would be awkward.

It doesn't simplify the code when the recursive mutex isn't removed but instead adding more ifdefs on top of it. At best it saves a few bytes for the mutex struct. If you want to keep the recursive mutex implementation for future use, I don't think the ifdefs worth it, because if it is added in a mandatory part of mpv, then the recursive mutex becomes mandatory anyway so ifdefs aren't needed.

@Dudemanguy
Copy link
Member

I'd rather just remove vdpau than this tbh. Not that I'm suggesting we need to.

@kasper93
Copy link
Contributor Author

kasper93 commented Mar 3, 2025

It doesn't simplify the code

Simplification is not the main objective of this PR.

At best it saves a few bytes for the mutex struct.

It saves 40 bytes from mp_mutex struct. Still not the main concern. The main difference is the bloated code by adding if (mutex->use_cs) with essentially dead branch of code. And I by design wanted to inline it, so it is optimized out, if possible. Also mp_mutex_destroy becomes noop, so there is not even need for function call.

because if it is added in a mandatory part of mpv, then the recursive mutex becomes mandatory anyway so ifdefs aren't needed.

That's a big "if". I would rather avoid recursive mutexes at all cost.

I'd rather just remove vdpau than this tbh. Not that I'm suggesting we need to.

Maybe I should read the code if this mutex is needed there.

@na-na-hi
Copy link
Contributor

na-na-hi commented Mar 3, 2025

The main difference is the bloated code by adding if (mutex->use_cs) with essentially dead branch of code. And I by design wanted to inline it, so it is optimized out, if possible.

There is no need to put ifdef everywhere if this is what you wanted. Replace mutex->use_cs with a macro like MP_MUTEX_IS_CS(mutex) and ifdef that to be 0. The compiler will eliminate the if (0) branch.

@kasper93
Copy link
Contributor Author

kasper93 commented Mar 3, 2025

I will remove recursive mutex completely after #15997 is merged.

EDIT: Updated this PR too.

kasper93 added 2 commits March 3, 2025 20:59
And eliminate recursive lock. This doesn't have to be guarded by mutex,
if for some reason preemption happens while we are handling preemption,
we remember the flag and do the dance gain. This is even nicer than
locking preemption callback.
After removal of `MP_MUTEX_RECURSIVE` from vdpau.c there are no more
clients of recursive mutex. Remove all the code related to it. This
commit can be reverted if in the future it is needed again. For now
let's not keep dead code.
@kasper93 kasper93 added this to the Release v0.41.0 milestone Mar 6, 2025
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.

3 participants