-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Add missing thread safety to PagedAllocator #76755
Add missing thread safety to PagedAllocator #76755
Conversation
b3b3d29
to
73ec6b0
Compare
73ec6b0
to
53c8a4f
Compare
53c8a4f
to
341b958
Compare
if (thread_safe) { | ||
spin_lock.unlock(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if it is possible to have a spinlock guard like MutexLock
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a bad idea, but that would be out of the scope of this PR. And, in any case, some of the Godot code is not even using the MutexLock
, preferring explicit lock-unlock even when the RAII lock would be usable.
Also, I hate to be that guy 😃 , (and as I know very little about the low level details I feel qualified to make newbie question), should we be using spinlocks now that modern mutexes are very good? https://matklad.github.io/2020/01/04/mutexes-are-faster-than-spinlocks.html |
This is something I had in my mental (and, I think, in my written) TODO list. I attended a talk in the GDC from AMD people on how to optimize games for Ryzen processors. I think most of what they said is universal. And one of the guidelines (after comparing trivial user spinlock, clever user spinlock, and mutex) was, "Use So I'd really like that this topic was researched and benchmarked in Godot. If modern mutexes have all the good of both classic OS mutexes and spinlocks, then why not just use them. |
In any case, the modification to |
Without getting more off topic than this I'd suggest for researching the spinlock Vs mutex for Godot would be to replace spinlock in cases where they don't necessarily need to be spinlocks (I believe there are some cases where they are still suggested) with a But maybe it's a good idea to open a proposal or discussion to track this |
Thanks! |
This has involved in the end making
SpinLock
's functionsconst
, which is also consistent withMutex
.