Skip to content

Commit bf7f29b

Browse files
committed
Implement InstanceStorage optionally as sync #18
1 parent 08c6594 commit bf7f29b

File tree

6 files changed

+219
-78
lines changed

6 files changed

+219
-78
lines changed

.github/workflows/full-ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ on:
1414
- trying
1515

1616
env:
17-
GDEXT_FEATURES: ''
18-
# GDEXT_FEATURES: '--features crate/feature'
19-
# GDEXT_CRATE_ARGS: '-p godot-codegen -p godot-ffi -p godot-core -p godot-macros -p godot'
20-
2117
# LSan options: https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer
2218
# * report_objects: list individual leaked objects when running LeakSanitizer
2319
LSAN_OPTIONS: report_objects=1
@@ -80,7 +76,7 @@ jobs:
8076

8177
- name: "Check clippy"
8278
run: |
83-
cargo clippy --all-targets $GDEXT_FEATURES ${{ matrix.rust-extra-args }} -- \
79+
cargo clippy --all-targets ${{ matrix.rust-extra-args }} -- \
8480
-D clippy::suspicious -D clippy::style -D clippy::complexity -D clippy::perf \
8581
-D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented -D warnings
8682
@@ -92,6 +88,8 @@ jobs:
9288
strategy:
9389
fail-fast: false # cancel all jobs as soon as one fails?
9490
matrix:
91+
name: ["macos", "windows", "linux"]
92+
feature: ["default", "threads"]
9593
# Order this way because macOS typically has the longest duration, followed by Windows, so it benefits total workflow execution time.
9694
# Additionally, the 'linux (msrv *)' special case will then be listed next to the other 'linux' jobs.
9795
# Note: Windows uses '--target x86_64-pc-windows-msvc' by default as Cargo argument.
@@ -150,10 +148,10 @@ jobs:
150148
godot-binary: ${{ matrix.godot-binary }}
151149

152150
- name: "Compile tests"
153-
run: cargo test $GDEXT_FEATURES --no-run ${{ matrix.rust-extra-args }}
151+
run: cargo test --features "${{ matrix.feature }}" --no-run ${{ matrix.rust-extra-args }}
154152

155153
- name: "Test"
156-
run: cargo test $GDEXT_FEATURES ${{ matrix.rust-extra-args }}
154+
run: cargo test --features "${{ matrix.feature }}" ${{ matrix.rust-extra-args }}
157155

158156

159157
godot-itest:
@@ -164,6 +162,8 @@ jobs:
164162
strategy:
165163
fail-fast: false # cancel all jobs as soon as one fails?
166164
matrix:
165+
name: ["macos", "windows", "linux"]
166+
feature: ["default", "threads"]
167167
# Order this way because macOS typically has the longest duration, followed by Windows, so it benefits total workflow execution time.
168168
# Additionally, the 'linux (msrv *)' special case will then be listed next to the other 'linux' jobs.
169169
# Note: Windows uses '--target x86_64-pc-windows-msvc' by default as Cargo argument.
@@ -234,7 +234,7 @@ jobs:
234234
artifact-name: godot-${{ matrix.name }}
235235
godot-binary: ${{ matrix.godot-binary }}
236236
godot-args: ${{ matrix.godot-args }}
237-
rust-extra-args: ${{ matrix.rust-extra-args }}
237+
rust-extra-args: --features "${{ matrix.feature }}" ${{ matrix.rust-extra-args }}
238238
rust-toolchain: ${{ matrix.rust-toolchain }}
239239
rust-env-rustflags: ${{ matrix.rust-env-rustflags }}
240240
with-llvm: ${{ matrix.with-llvm }}

godot-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ trace = []
1313
codegen-fmt = ["godot-ffi/codegen-fmt"]
1414
codegen-full = ["godot-codegen/codegen-full"]
1515
double-precision = ["godot-codegen/double-precision"]
16+
threads = []
1617

1718
[dependencies]
1819
godot-ffi = { path = "../godot-ffi" }

godot-core/src/obj/guards.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,35 @@
44
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
66

7+
#[cfg(not(feature = "threads"))]
78
use std::cell;
89
use std::fmt::Debug;
910
use std::ops::{Deref, DerefMut};
11+
#[cfg(feature = "threads")]
12+
use std::sync;
1013

1114
/// Immutably/shared bound reference guard for a [`Gd`][crate::obj::Gd] smart pointer.
1215
///
1316
/// See [`Gd::bind`][crate::obj::Gd::bind] for usage.
1417
#[derive(Debug)]
1518
pub struct GdRef<'a, T> {
19+
#[cfg(not(feature = "threads"))]
1620
cell_ref: cell::Ref<'a, T>,
21+
22+
#[cfg(feature = "threads")]
23+
cell_ref: sync::RwLockReadGuard<'a, T>,
1724
}
1825

1926
impl<'a, T> GdRef<'a, T> {
27+
#[cfg(not(feature = "threads"))]
2028
pub(crate) fn from_cell(cell_ref: cell::Ref<'a, T>) -> Self {
2129
Self { cell_ref }
2230
}
31+
32+
#[cfg(feature = "threads")]
33+
pub(crate) fn from_cell(cell_ref: sync::RwLockReadGuard<'a, T>) -> Self {
34+
Self { cell_ref }
35+
}
2336
}
2437

2538
impl<T> Deref for GdRef<'_, T> {
@@ -39,13 +52,23 @@ impl<T> Deref for GdRef<'_, T> {
3952
/// See [`Gd::bind_mut`][crate::obj::Gd::bind_mut] for usage.
4053
#[derive(Debug)]
4154
pub struct GdMut<'a, T> {
55+
#[cfg(not(feature = "threads"))]
4256
cell_ref: cell::RefMut<'a, T>,
57+
58+
#[cfg(feature = "threads")]
59+
cell_ref: sync::RwLockWriteGuard<'a, T>,
4360
}
4461

4562
impl<'a, T> GdMut<'a, T> {
63+
#[cfg(not(feature = "threads"))]
4664
pub(crate) fn from_cell(cell_ref: cell::RefMut<'a, T>) -> Self {
4765
Self { cell_ref }
4866
}
67+
68+
#[cfg(feature = "threads")]
69+
pub(crate) fn from_cell(cell_ref: sync::RwLockWriteGuard<'a, T>) -> Self {
70+
Self { cell_ref }
71+
}
4972
}
5073

5174
impl<T> Deref for GdMut<'_, T> {

0 commit comments

Comments
 (0)