From ebec79c8ed28967fe4ae7052c4e21d9be3f74ea6 Mon Sep 17 00:00:00 2001 From: kl-botsu Date: Thu, 14 Mar 2024 15:04:23 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20khonsula?= =?UTF-8?q?bs/musegc@6453115c32742f67436e2e1fe729abfc65a88c5b=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/help.html | 2 +- main/musegc/all.html | 2 +- main/musegc/fn.collect.html | 4 +- main/musegc/fn.collected.html | 4 +- main/musegc/index.html | 34 +++--- main/musegc/struct.CollectionGuard.html | 12 +-- main/musegc/struct.CollectionStarting.html | 8 +- main/musegc/struct.Ref.html | 20 ++-- main/musegc/struct.Root.html | 22 ++-- main/musegc/struct.Tracer.html | 6 +- main/musegc/trait.Collectable.html | 20 ++-- main/musegc/trait.ContainsNoCollectables.html | 6 +- main/settings.html | 2 +- main/src/musegc/lib.rs.html | 102 ++++++++++++------ 14 files changed, 139 insertions(+), 105 deletions(-) diff --git a/main/help.html b/main/help.html index eb6364d..74df204 100644 --- a/main/help.html +++ b/main/help.html @@ -1,2 +1,2 @@ -Help +Help

Rustdoc help

Back
\ No newline at end of file diff --git a/main/musegc/all.html b/main/musegc/all.html index 759fffc..87eab0f 100644 --- a/main/musegc/all.html +++ b/main/musegc/all.html @@ -1,2 +1,2 @@ -List of all items in this crate +List of all items in this crate
\ No newline at end of file diff --git a/main/musegc/fn.collect.html b/main/musegc/fn.collect.html index 04cfdb0..08147aa 100644 --- a/main/musegc/fn.collect.html +++ b/main/musegc/fn.collect.html @@ -1,5 +1,5 @@ -collect in musegc - Rust -

Function musegc::collect

source ·
pub fn collect()
Expand description

Invokes the garbage collector.

+collect in musegc - Rust +

Function musegc::collect

source ·
pub fn collect()
Expand description

Invokes the garbage collector.

This function will deadlock if any CollectionGuards are held by the current thread when invoked. If a guard is held, consider calling CollectionGuard::collect() instead.

diff --git a/main/musegc/fn.collected.html b/main/musegc/fn.collected.html index 94a4cd3..afa4c01 100644 --- a/main/musegc/fn.collected.html +++ b/main/musegc/fn.collected.html @@ -1,5 +1,5 @@ -collected in musegc - Rust -

Function musegc::collected

source ·
pub fn collected<R>(wrapped: impl FnOnce() -> R) -> R
Expand description

Executes wrapped with garbage collection available.

+collected in musegc - Rust +

Function musegc::collected

source ·
pub fn collected<R>(wrapped: impl FnOnce() -> R) -> R
Expand description

Executes wrapped with garbage collection available.

This function installs a garbage collector for this thread, if needed. Repeated and nested calls are allowed.

Invoking CollectionGuard::acquire() within wrapped will return a diff --git a/main/musegc/index.html b/main/musegc/index.html index 63c3f9c..528e370 100644 --- a/main/musegc/index.html +++ b/main/musegc/index.html @@ -1,6 +1,6 @@ -musegc - Rust

use std::{array, thread}; use ahash::AHashMap; +use crossbeam_utils::sync::{Parker, Unparker}; use flume::{Receiver, RecvError, RecvTimeoutError, Sender}; use intentional::{Assert, Cast}; use kempt::Map; @@ -1715,7 +1733,7 @@

Files

struct CollectorInfo { info: Mutex<CollectorInfoData>, collection_sync: Condvar, - collector_sync: Condvar, + collector_unparker: Unparker, signalled_collector: AtomicBool, reader_state: ReaderState, all_threads: AllThreadBins, @@ -1799,7 +1817,7 @@

Files

} } - fn run(mut self) { + fn run(mut self, parker: &Parker) { thread::scope(|scope| { let (tracer, trace_receiver) = flume::bounded(128); @@ -1829,7 +1847,7 @@

Files

let command = match self.next_command() { Ok(Some(command)) => command, Ok(None) => { - self.collect_and_notify(&channels); + self.collect_and_notify(&channels, parker); continue; } Err(_) => break, @@ -1857,7 +1875,7 @@

Files

let info = self.shared.info.lock(); if info.last_run < requested_at { drop(info); - self.collect_and_notify(&channels); + self.collect_and_notify(&channels, parker); } } CollectorCommand::ScheduleCollect => { @@ -1873,10 +1891,10 @@

Files

}); } - fn collect_and_notify(&mut self, channels: &CollectorThreadChannels) { + fn collect_and_notify(&mut self, channels: &CollectorThreadChannels, parker: &Parker) { self.next_gc = None; let gc_start = Instant::now(); - let collect_result = self.collect(channels); + let collect_result = self.collect(channels, parker); let gc_finish = Instant::now(); let gc_pause = match collect_result { @@ -1917,6 +1935,7 @@

Files

average_collection_locking: Duration, pause_failures: u8, collector: &CollectorInfo, + parker: &Parker, ) -> Option<AHashMap<CollectorThreadId, &'a mut Bins>> { let force_gc = pause_failures >= 5; let lock_wait = (average_collection_locking / 8) @@ -1924,18 +1943,16 @@

Files

let long_lock_deadline = start + lock_wait * 8; if !collector.reader_state.write() { - let mut info_data = collector.info.lock(); while collector.reader_state.readers() > 0 { if force_gc { - collector.collector_sync.wait(&mut info_data); - } else if collector - .collector_sync - .wait_until(&mut info_data, long_lock_deadline) - .timed_out() - { - collector.reader_state.release_write(); - collector.collection_sync.notify_all(); - return None; + parker.park(); + } else { + parker.park_deadline(long_lock_deadline); + if Instant::now() > long_lock_deadline && collector.reader_state.readers() > 0 { + collector.reader_state.release_write(); + collector.collection_sync.notify_all(); + return None; + } } } } @@ -1948,7 +1965,7 @@

Files

) } - fn collect(&mut self, threads: &CollectorThreadChannels) -> CollectResult { + fn collect(&mut self, threads: &CollectorThreadChannels, parker: &Parker) -> CollectResult { self.mark_bits = self.mark_bits.wrapping_add(1); if self.mark_bits == 0 { self.mark_bits = 1; @@ -1961,6 +1978,7 @@

Files

self.average_collection_locking, self.pause_failures, &self.shared, + parker, ) else { self.pause_failures += 1; return CollectResult::CouldntRun; @@ -2067,12 +2085,13 @@

Files

fn get() -> &'static GlobalCollector { COLLECTOR.get_or_init(|| { let (sender, receiver) = flume::bounded(1024); + let parker = Parker::new(); let info = Arc::new(CollectorInfo { info: Mutex::new(CollectorInfoData { last_run: Instant::now(), }), collection_sync: Condvar::new(), - collector_sync: Condvar::new(), + collector_unparker: parker.unparker().clone(), signalled_collector: AtomicBool::new(false), reader_state: ReaderState(AtomicUsize::new(0)), all_threads: AllThreadBins::default(), @@ -2081,7 +2100,7 @@

Files

.name(String::from("collector")) .spawn({ let info = info.clone(); - move || Collector::new(receiver, info).run() + move || Collector::new(receiver, info).run(&parker) }) .expect("error starting collector thread"); GlobalCollector { sender, info } @@ -2183,8 +2202,8 @@

Files

.is_ok() } - fn release_read(&self) { - self.0.fetch_sub(1, Ordering::Acquire); + fn release_read(&self) -> bool { + self.0.fetch_sub(1, Ordering::Acquire) == (Self::COLLECTING_BIT | 1) } fn write(&self) -> bool { @@ -2210,15 +2229,27 @@

Files

self.0.load(Ordering::Acquire) & !Self::COLLECTING_BIT } - fn release_read_if_collecting(&self) -> bool { - self.0 + fn release_read_if_collecting(&self) -> ReleaseReadResult { + match self + .0 .fetch_update(Ordering::Release, Ordering::Acquire, |state| { (state & Self::COLLECTING_BIT != 0).then_some(state - 1) - }) - .is_ok() + }) { + Ok(previous) if previous == (Self::COLLECTING_BIT | 1) => { + ReleaseReadResult::CollectAndUnpark + } + Ok(_) => ReleaseReadResult::Collect, + Err(_) => ReleaseReadResult::Noop, + } } } +enum ReleaseReadResult { + CollectAndUnpark, + Collect, + Noop, +} + struct CollectorReadGuard { global: &'static CollectorInfo, } @@ -2242,17 +2273,20 @@

Files

} fn release_reader(&mut self) { - self.global.reader_state.release_read(); - self.global.collector_sync.notify_one(); + if self.global.reader_state.release_read() { + self.global.collector_unparker.unpark(); + } } fn release_reader_if_collecting(&mut self) -> bool { - if self.global.reader_state.release_read_if_collecting() { - self.global.collector_sync.notify_one(); - true - } else { - false - } + match self.global.reader_state.release_read_if_collecting() { + ReleaseReadResult::CollectAndUnpark => { + self.global.collector_unparker.unpark(); + true + } + ReleaseReadResult::Collect => true, + ReleaseReadResult::Noop => false, + } } }