Skip to content

Conversation

@Bromeon
Copy link
Member

@Bromeon Bromeon commented Dec 28, 2023

Similar to once_cell::Lazy, this type allows lazy initialization in static variables, without Option or other workarounds. The implementation was initially very simple (just 100 LoC), but got a bit more involved once try_lock() was added. An older commit contains the simpler implementation. Depending on needs, we might also consider RwLock instead of Mutex internally, but I think it's not necessary right now, and it would add quite a bit of further complexity in both implementation and usage (e.g. for caches).

I replaced two occurrences of Mutex<Option<T>> in gdext with Global<T> and added a new one.

Global<T> is currently not part of the public API, but we may consider exposing it if there is demand.

At some point, we should also consider what to do with the static mut in godot-ffi that gives access to the entire BINDING. We need to see if concurrent access is needed. And if yes, how to provide it without compromising performance for every single Godot API call.

Leave in 2 places: one actually needs Option for late-init, the other needs try_lock().
Also use ClassName by value whenever possible, since it's Copy.
@Bromeon Bromeon added feature Adds functionality to the library c: core Core components labels Dec 28, 2023
@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-547

@Bromeon Bromeon force-pushed the feature/global-cell branch from 61d43b7 to f6dc092 Compare December 28, 2023 09:56
@Bromeon Bromeon enabled auto-merge December 28, 2023 10:00
@Bromeon Bromeon added this pull request to the merge queue Dec 28, 2023
Merged via the queue into master with commit 13af9d6 Dec 28, 2023
@Bromeon Bromeon deleted the feature/global-cell branch December 28, 2023 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: core Core components feature Adds functionality to the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants