Skip to content

Commit

Permalink
Implement InstanceStorage optionally as sync godot-rust#18
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Apr 22, 2023
1 parent 08c6594 commit bf7f29b
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 78 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/full-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ on:
- trying

env:
GDEXT_FEATURES: ''
# GDEXT_FEATURES: '--features crate/feature'
# GDEXT_CRATE_ARGS: '-p godot-codegen -p godot-ffi -p godot-core -p godot-macros -p godot'

# LSan options: https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer
# * report_objects: list individual leaked objects when running LeakSanitizer
LSAN_OPTIONS: report_objects=1
Expand Down Expand Up @@ -80,7 +76,7 @@ jobs:

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

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

- name: "Test"
run: cargo test $GDEXT_FEATURES ${{ matrix.rust-extra-args }}
run: cargo test --features "${{ matrix.feature }}" ${{ matrix.rust-extra-args }}


godot-itest:
Expand All @@ -164,6 +162,8 @@ jobs:
strategy:
fail-fast: false # cancel all jobs as soon as one fails?
matrix:
name: ["macos", "windows", "linux"]
feature: ["default", "threads"]
# Order this way because macOS typically has the longest duration, followed by Windows, so it benefits total workflow execution time.
# Additionally, the 'linux (msrv *)' special case will then be listed next to the other 'linux' jobs.
# Note: Windows uses '--target x86_64-pc-windows-msvc' by default as Cargo argument.
Expand Down Expand Up @@ -234,7 +234,7 @@ jobs:
artifact-name: godot-${{ matrix.name }}
godot-binary: ${{ matrix.godot-binary }}
godot-args: ${{ matrix.godot-args }}
rust-extra-args: ${{ matrix.rust-extra-args }}
rust-extra-args: --features "${{ matrix.feature }}" ${{ matrix.rust-extra-args }}
rust-toolchain: ${{ matrix.rust-toolchain }}
rust-env-rustflags: ${{ matrix.rust-env-rustflags }}
with-llvm: ${{ matrix.with-llvm }}
Expand Down
1 change: 1 addition & 0 deletions godot-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ trace = []
codegen-fmt = ["godot-ffi/codegen-fmt"]
codegen-full = ["godot-codegen/codegen-full"]
double-precision = ["godot-codegen/double-precision"]
threads = []

[dependencies]
godot-ffi = { path = "../godot-ffi" }
Expand Down
23 changes: 23 additions & 0 deletions godot-core/src/obj/guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,35 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#[cfg(not(feature = "threads"))]
use std::cell;
use std::fmt::Debug;
use std::ops::{Deref, DerefMut};
#[cfg(feature = "threads")]
use std::sync;

/// Immutably/shared bound reference guard for a [`Gd`][crate::obj::Gd] smart pointer.
///
/// See [`Gd::bind`][crate::obj::Gd::bind] for usage.
#[derive(Debug)]
pub struct GdRef<'a, T> {
#[cfg(not(feature = "threads"))]
cell_ref: cell::Ref<'a, T>,

#[cfg(feature = "threads")]
cell_ref: sync::RwLockReadGuard<'a, T>,
}

impl<'a, T> GdRef<'a, T> {
#[cfg(not(feature = "threads"))]
pub(crate) fn from_cell(cell_ref: cell::Ref<'a, T>) -> Self {
Self { cell_ref }
}

#[cfg(feature = "threads")]
pub(crate) fn from_cell(cell_ref: sync::RwLockReadGuard<'a, T>) -> Self {
Self { cell_ref }
}
}

impl<T> Deref for GdRef<'_, T> {
Expand All @@ -39,13 +52,23 @@ impl<T> Deref for GdRef<'_, T> {
/// See [`Gd::bind_mut`][crate::obj::Gd::bind_mut] for usage.
#[derive(Debug)]
pub struct GdMut<'a, T> {
#[cfg(not(feature = "threads"))]
cell_ref: cell::RefMut<'a, T>,

#[cfg(feature = "threads")]
cell_ref: sync::RwLockWriteGuard<'a, T>,
}

impl<'a, T> GdMut<'a, T> {
#[cfg(not(feature = "threads"))]
pub(crate) fn from_cell(cell_ref: cell::RefMut<'a, T>) -> Self {
Self { cell_ref }
}

#[cfg(feature = "threads")]
pub(crate) fn from_cell(cell_ref: sync::RwLockWriteGuard<'a, T>) -> Self {
Self { cell_ref }
}
}

impl<T> Deref for GdMut<'_, T> {
Expand Down
Loading

0 comments on commit bf7f29b

Please sign in to comment.