anki/rslib
Aleksa Sarai 312393e825
rs: remove most &mut references in BackendService
The previous implementation had some slightly questionable memory safety
properties (older versions of PyO3 didn't uphold the Rust aliasing rules
and would thus create multiple &mut references to #[pyclass] objects).
This explains why Backend has internal Mutex<T>s even though all of its
methods took &mut self.

The solution is to simply make all methods take &self, which luckily
doesn't pose too make issues -- most of the code inside Backend already
has sufficient locking. The only two things which needed to be
explicitly handled where:

1. "self.runtime" which was fairly easy to handle. All usages of
   the Runtime only require an immutable reference to create a new
   Handle, so we could switch to OnceCell which provides
   lazy-initialisation semantics without needing a more heavy-handed
   Mutex<tokio::runtime::Handle>.

2. "self.sync_abort" was simply wrapped in a Mutex<>, though some of the
   odd semantics of sync_abort (not being able to handle multiple
   processes synchronising at the same time) become pretty obvious with
   this change (for now we just log a warning in that case). In
   addition, switch to an RAII-style guard to make sure we don't forget
   to clear the abort_handle.

As a result, we now no longer break Rust's aliasing rules and we can
build with newer versions of PyO3 which have runtime checks for these
things (and build on stable Rust).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2020-09-05 19:37:59 +10:00
..
ftl log manual reschedule, but ignore the log entry in the stats 2020-09-02 17:56:23 +10:00
src rs: remove most &mut references in BackendService 2020-09-05 19:37:59 +10:00
templates migrate card stats to backend 2020-06-15 17:22:16 +10:00
tests/support fix missing newline in ftl files 2020-03-09 18:58:41 +10:00
.gitignore tweaking the folder names again 2020-01-03 07:48:38 +10:00
build.rs rs: remove most &mut references in BackendService 2020-09-05 19:37:59 +10:00
Cargo.toml rs: remove most &mut references in BackendService 2020-09-05 19:37:59 +10:00
Makefile Also bump rslib version on make_check 2020-05-11 13:29:12 -03:00
README.md use support URL and point to source repo 2020-04-03 08:44:59 +10:00
rust-toolchain bump rust nightly version 2020-06-29 15:48:01 +10:00

To build from scratch, please see https://github.com/ankitects/anki