-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Global main thread ID #1045
Global main thread ID #1045
Conversation
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1045 |
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.
Thanks, good idea!
I'm not sure if I'm doing premature optimization here, but since initialization happens exactly once, I'm not a huge fan of all future code needing to obtain a lock to read the thread ID. This might even be slower than thread::current().id()
, depending on how that is implemented/cached.
In the library we have ManualInitCell<T>
for this purpose. The invariant is that the value is only accessed after initialization, which means it needs to be unsafe
, which is a bit annoying for ergonomics. In Debug mode, misuse would still be caught.
Thoughts? If it's not used in hot paths, we could keep things simple with OnceLock
.
Yeah, I think that is a good idea. I definitely need to check the main thread ID every time a new async task is created, and it's hard to say if that will end up in someone's hot path. It being unsafe is unfortunate, but manageable. |
@Bromeon this probably also fits better into the |
04484f3
to
4d3d3ee
Compare
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.
@Bromeon this probably also fits better into the
global
module thanmeta
right?
Not really, that module is for global symbols from Godot itself.
Maybe init/mod.rs
?
This functionality is only needed in godot-core, not in godot-ffi?
Hmm, yes, I think it could be used in |
4d3d3ee
to
f0485c1
Compare
Good idea! Can you add the panic docs under its own section Do you think it also makes sense to add a function |
f0485c1
to
38a9949
Compare
38a9949
to
9718ffc
Compare
Looks like a convenient shortcut, I have added it. |
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.
Thanks a lot!
In #1043 I need to identify the main thread without accessing the related engine API.
By storing the current thread ID during initialization, we can identify the main thread from that point on. I only found one other use of the main thread ID in
godot-ffi
but having access to the ThreadId of the main-thread could also be useful to user code.