Skip to main content

Ledger

Struct Ledger 

Source
pub struct Ledger {
    cur: [AtomicU8; 4],
    bytes: [AtomicI64; 32],
    owner: [AtomicUsize; 32],
    low: AtomicBool,
    killing: AtomicU8,
    next: AtomicU8,
    threads: [AtomicU32; 32],
}
Expand description

アプリごとのメモリの帳簿。allocator に 1 個だけ置く(allocator::MEM_LEDGER)。

Fields§

§cur: [AtomicU8; 4]

コアごとの「今動いているスレッドの組」。

§bytes: [AtomicI64; 32]

組ごとの「確保 − 解放」のバイト数(狂いで負になりうる)。

§owner: [AtomicUsize; 32]

組ごとの持ち主(アプリのスレッドのプロセス ID + 1。0 は空き)。

§low: AtomicBool

ヒープの空きが LOW_FREE を下回っているか。

§killing: AtomicU8

止めている最中の組(0 は無し)。

§next: AtomicU8

次に配る組の番号の候補(同じ番号をすぐ使い回さないよう、順に回す)。

§threads: [AtomicU32; 32]

組ごとの「生きているスレッドの数」(TODO R2 (c)、2026-11-17 続報)。スレッドを起こすと足し (Ledger::thread_enter)、scheduler::exit で引く(Ledger::thread_leave)。 閉じた組でもスレッドが残っている間は、その番号を新しいアプリに配らない(Ledger::open_group)。 でないと、止めたアプリの背景のスレッドが新しいアプリの組に紛れ、止まる合図を見失う。

Implementations§

Source§

impl Ledger

Source

pub const fn new() -> Self

Source

pub fn is_closed(&self, g: u8) -> bool

組 g が「閉じた」(そのアプリのスレッドが止まり、組が片付けられた)か。組 0(OS)は閉じない。

止めたアプリの背景のスレッドへの「止まれ」の合図はこれ(TODO R2 (c))。合図のために別の印は持たず、 組の持ち主の欄が空いたことをそのまま使う(アトミックの読み出し 1 回)。

Source

pub fn thread_enter(&self, g: u8)

組 g のスレッドが 1 本増えた(スレッドを起こした、または組を移した)。

Source

pub fn thread_leave(&self, g: u8) -> u32

組 g のスレッドが 1 本減った。残りの本数を返す(組 0 は常に 0)。

Source

pub fn move_thread(&self, from: u8, to: u8)

スレッドを組 from から組 to へ移す(数だけ。scheduler::set_current_mem_group)。

Source

pub fn threads_of(&self, g: u8) -> u32

組 g の生きているスレッドの数。

Source

pub fn core_group(&self, core: usize) -> u8

コア core の今の組。

Source

pub fn set_core_group(&self, core: usize, group: u8)

コア core で動くスレッドが変わった(scheduler::schedule)。

Source

pub fn on_alloc(&self, core: usize, size: usize, free_after: usize)

確保の後に呼ぶ(アロケータの錠の中。書き手は錠で 1 人なので読み出し+書き込みで足りる)。 free_after は確保の後のヒープの空き。

Source

pub fn on_dealloc(&self, core: usize, size: usize, free_after: usize)

解放の後に呼ぶ(アロケータの錠の中)。free_after は解放の後のヒープの空き。

Source

fn update_low(&self, free_after: usize)

値が変わるときだけ書く(毎回書くと 4 コアの間でキャッシュの行が行き来する)。

Source

pub fn is_low(&self) -> bool

ヒープの空きが尽きかけているか。

Source

pub fn bytes_of(&self, g: u8) -> i64

組 g が持っている量(0 未満は 0)。

Source

pub fn owner_of(&self, g: u8) -> Option<usize>

組 g の持ち主のプロセス ID(空きなら None)。

Source

pub fn killing(&self) -> u8

止めている最中の組(0 は無し)。

Source

pub fn open_group(&self, pid: usize) -> u8

アプリのスレッド pid に新しい組を配る(量は 0 から)。空きが無ければ 0(数えない)。

Source

pub fn close_group_of(&self, pid: usize) -> Option<u8>

プロセス pid の組を閉じる(アプリ本体を解放した後に呼ぶ)。閉じた組の番号を返す。

Source

pub fn close_group(&self, g: u8)

組 g を閉じる。止めている最中の組なら、その印も外す。

Source

pub fn verdict(&self, g: u8, total: usize) -> Verdict

組 g(呼ぶのはその組のアプリのスレッド)を止めるべきか。total はヒープ全体の大きさ。

ふだんの道(尽きかけでなく上限の内)は、アトミックの読み出し 2 回で Keep を返す。

Source

pub fn begin_kill(&self, g: u8) -> bool

組 g を止めると決めた印を立てる(ほかの組が同時に止めに入らないように)。 既に別の組を止めている最中なら false。

Trait Implementations§

Source§

impl Default for Ledger

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.