Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 1317cbf

Browse files
committed
Pluralize process flag structs and method
It was confusing that they hold multiple flags, but are called `*ProcessFlag` and that `is_set` could check multiple flags at once.
1 parent 03f4e23 commit 1317cbf

File tree

4 files changed

+51
-51
lines changed

4 files changed

+51
-51
lines changed

liblumen_alloc/src/erts/process.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub struct ProcessControlBlock {
7272
/// The priority of the process in `scheduler`.
7373
pub priority: Priority,
7474
/// Process flags, e.g. `Process.flag/1`
75-
flags: AtomicProcessFlag,
75+
flags: AtomicProcessFlags,
7676
/// Minimum size of the heap that this process will start with
7777
min_heap_size: usize,
7878
/// The maximum size of the heap allowed for this process
@@ -122,7 +122,7 @@ impl ProcessControlBlock {
122122
let pid = pid::next();
123123

124124
Self {
125-
flags: AtomicProcessFlag::new(ProcessFlag::Default),
125+
flags: AtomicProcessFlags::new(ProcessFlags::Default),
126126
min_heap_size: heap_size,
127127
max_heap_size: 0,
128128
min_vheap_size: 0,
@@ -161,13 +161,13 @@ impl ProcessControlBlock {
161161

162162
/// Set the given process flag
163163
#[inline]
164-
pub fn set_flags(&self, flags: ProcessFlag) {
164+
pub fn set_flags(&self, flags: ProcessFlags) {
165165
self.flags.set(flags);
166166
}
167167

168168
/// Unset the given process flag
169169
#[inline]
170-
pub fn clear_flags(&self, flags: ProcessFlag) {
170+
pub fn clear_flags(&self, flags: ProcessFlags) {
171171
self.flags.clear(flags);
172172
}
173173

@@ -620,22 +620,22 @@ impl ProcessControlBlock {
620620

621621
#[inline]
622622
fn is_gc_forced(&self) -> bool {
623-
self.flags.is_set(ProcessFlag::ForceGC)
623+
self.flags.are_set(ProcessFlags::ForceGC)
624624
}
625625

626626
#[inline(always)]
627627
fn is_gc_delayed(&self) -> bool {
628-
self.flags.is_set(ProcessFlag::DelayGC)
628+
self.flags.are_set(ProcessFlags::DelayGC)
629629
}
630630

631631
#[inline(always)]
632632
fn is_gc_disabled(&self) -> bool {
633-
self.flags.is_set(ProcessFlag::DisableGC)
633+
self.flags.are_set(ProcessFlags::DisableGC)
634634
}
635635

636636
#[inline(always)]
637637
fn needs_fullsweep(&self) -> bool {
638-
self.flags.is_set(ProcessFlag::NeedFullSweep)
638+
self.flags.are_set(ProcessFlags::NeedFullSweep)
639639
}
640640

641641
/// Performs a garbage collection, using the provided root set

liblumen_alloc/src/erts/process/flags.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use core::sync::atomic::{AtomicU32, Ordering};
66
/// to combine multiple flags in one value.
77
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88
#[repr(transparent)]
9-
pub struct ProcessFlag(u32);
10-
impl ProcessFlag {
9+
pub struct ProcessFlags(u32);
10+
impl ProcessFlags {
1111
#![allow(non_upper_case_globals)]
1212

1313
/// The default value where no flags are set
@@ -27,89 +27,89 @@ impl ProcessFlag {
2727
// Internal value used to validate conversions from raw u32 values
2828
const MAX_VALUE: u32 = 1 << 5;
2929
}
30-
impl Into<u32> for ProcessFlag {
30+
impl Into<u32> for ProcessFlags {
3131
#[inline]
3232
fn into(self) -> u32 {
3333
self.0
3434
}
3535
}
36-
impl From<u32> for ProcessFlag {
36+
impl From<u32> for ProcessFlags {
3737
#[inline]
3838
fn from(n: u32) -> Self {
3939
assert!(n <= Self::MAX_VALUE);
4040
Self(n)
4141
}
4242
}
43-
impl Not for ProcessFlag {
43+
impl Not for ProcessFlags {
4444
type Output = Self;
4545

4646
fn not(self) -> Self {
4747
Self(!self.0)
4848
}
4949
}
50-
impl BitOr for ProcessFlag {
50+
impl BitOr for ProcessFlags {
5151
type Output = Self;
5252

5353
fn bitor(self, rhs: Self) -> Self {
5454
Self(self.0 | rhs.0)
5555
}
5656
}
57-
impl BitOrAssign for ProcessFlag {
57+
impl BitOrAssign for ProcessFlags {
5858
fn bitor_assign(&mut self, rhs: Self) {
5959
self.0 |= rhs.0
6060
}
6161
}
62-
impl BitAnd for ProcessFlag {
62+
impl BitAnd for ProcessFlags {
6363
type Output = Self;
6464

6565
fn bitand(self, rhs: Self) -> Self {
6666
Self(self.0 & rhs.0)
6767
}
6868
}
69-
impl BitAndAssign for ProcessFlag {
69+
impl BitAndAssign for ProcessFlags {
7070
fn bitand_assign(&mut self, rhs: Self) {
7171
self.0 &= rhs.0
7272
}
7373
}
7474

7575
/// This type is a wrapper around `AtomicU32` and provides atomic
76-
/// semantics for the `ProcessFlag` enum type
76+
/// semantics for the `ProcessFlags` enum type
7777
#[repr(transparent)]
78-
pub struct AtomicProcessFlag(AtomicU32);
79-
impl AtomicProcessFlag {
80-
/// Create a new `AtomicProcessFlag`
78+
pub struct AtomicProcessFlags(AtomicU32);
79+
impl AtomicProcessFlags {
80+
/// Create a new `AtomicProcessFlags`
8181
#[inline]
82-
pub fn new(flag: ProcessFlag) -> Self {
82+
pub fn new(flag: ProcessFlags) -> Self {
8383
Self(AtomicU32::new(flag.into()))
8484
}
8585

8686
/// Fetch the current value, with the given `Ordering`
8787
#[inline]
88-
pub fn load(&self, ordering: Ordering) -> ProcessFlag {
88+
pub fn load(&self, ordering: Ordering) -> ProcessFlags {
8989
self.0.load(ordering).into()
9090
}
9191

9292
/// Fetch the current value, using `Relaxed` ordering
9393
#[inline]
94-
pub fn get(&self) -> ProcessFlag {
94+
pub fn get(&self) -> ProcessFlags {
9595
self.0.load(Ordering::Relaxed).into()
9696
}
9797

9898
/// Check if the current value contains the given flags, uses `Relaxed` ordering
9999
#[inline]
100-
pub fn is_set(&self, flags: ProcessFlag) -> bool {
100+
pub fn are_set(&self, flags: ProcessFlags) -> bool {
101101
self.get() & flags == flags
102102
}
103103

104104
/// Set the given flags, uses `AcqRel` ordering
105105
#[inline]
106-
pub fn set(&self, flags: ProcessFlag) -> ProcessFlag {
106+
pub fn set(&self, flags: ProcessFlags) -> ProcessFlags {
107107
self.0.fetch_or(flags.into(), Ordering::AcqRel).into()
108108
}
109109

110110
/// Clear the given flags, uses `AcqRel` ordering
111111
#[inline]
112-
pub fn clear(&self, flags: ProcessFlag) -> ProcessFlag {
112+
pub fn clear(&self, flags: ProcessFlags) -> ProcessFlags {
113113
let cleared = !flags;
114114
self.0.fetch_and(cleared.into(), Ordering::AcqRel).into()
115115
}
@@ -121,34 +121,34 @@ mod tests {
121121

122122
#[test]
123123
fn process_flag_test() {
124-
let mut flags = ProcessFlag::Default;
124+
let mut flags = ProcessFlags::Default;
125125
// Set fullsweep
126-
flags |= ProcessFlag::NeedFullSweep;
127-
assert!(flags & ProcessFlag::NeedFullSweep == ProcessFlag::NeedFullSweep);
126+
flags |= ProcessFlags::NeedFullSweep;
127+
assert!(flags & ProcessFlags::NeedFullSweep == ProcessFlags::NeedFullSweep);
128128
// Set force_gc
129-
flags |= ProcessFlag::ForceGC;
130-
assert!(flags & ProcessFlag::NeedFullSweep == ProcessFlag::NeedFullSweep);
131-
assert!(flags & ProcessFlag::ForceGC == ProcessFlag::ForceGC);
129+
flags |= ProcessFlags::ForceGC;
130+
assert!(flags & ProcessFlags::NeedFullSweep == ProcessFlags::NeedFullSweep);
131+
assert!(flags & ProcessFlags::ForceGC == ProcessFlags::ForceGC);
132132
// Ensure we can check multiple flags at once
133-
let checking = ProcessFlag::ForceGC | ProcessFlag::NeedFullSweep;
133+
let checking = ProcessFlags::ForceGC | ProcessFlags::NeedFullSweep;
134134
assert!(flags & checking == checking);
135135
// Clear force_gc
136-
flags &= !ProcessFlag::ForceGC;
137-
assert!(flags & ProcessFlag::ForceGC != ProcessFlag::ForceGC);
138-
assert!(flags & ProcessFlag::NeedFullSweep == ProcessFlag::NeedFullSweep);
136+
flags &= !ProcessFlags::ForceGC;
137+
assert!(flags & ProcessFlags::ForceGC != ProcessFlags::ForceGC);
138+
assert!(flags & ProcessFlags::NeedFullSweep == ProcessFlags::NeedFullSweep);
139139
}
140140

141141
#[test]
142142
fn atomic_process_flag_test() {
143-
let flags = AtomicProcessFlag::new(ProcessFlag::Default);
144-
flags.set(ProcessFlag::NeedFullSweep);
145-
assert!(flags.is_set(ProcessFlag::NeedFullSweep));
146-
flags.set(ProcessFlag::ForceGC);
147-
assert!(flags.is_set(ProcessFlag::NeedFullSweep));
148-
assert!(flags.is_set(ProcessFlag::ForceGC));
149-
assert!(flags.is_set(ProcessFlag::ForceGC | ProcessFlag::NeedFullSweep));
150-
flags.clear(ProcessFlag::ForceGC);
151-
assert!(flags.is_set(ProcessFlag::NeedFullSweep));
152-
assert!(!flags.is_set(ProcessFlag::ForceGC));
143+
let flags = AtomicProcessFlags::new(ProcessFlags::Default);
144+
flags.set(ProcessFlags::NeedFullSweep);
145+
assert!(flags.are_set(ProcessFlags::NeedFullSweep));
146+
flags.set(ProcessFlags::ForceGC);
147+
assert!(flags.are_set(ProcessFlags::NeedFullSweep));
148+
assert!(flags.are_set(ProcessFlags::ForceGC));
149+
assert!(flags.are_set(ProcessFlags::ForceGC | ProcessFlags::NeedFullSweep));
150+
flags.clear(ProcessFlags::ForceGC);
151+
assert!(flags.are_set(ProcessFlags::NeedFullSweep));
152+
assert!(!flags.are_set(ProcessFlags::ForceGC));
153153
}
154154
}

liblumen_alloc/src/erts/process/gc/collector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'p, 'h> GarbageCollector<'p, 'h> {
129129
// Unset heap_grow and need_fullsweep flags, because we are doing both
130130
self.process
131131
.flags
132-
.clear(ProcessFlag::GrowHeap | ProcessFlag::NeedFullSweep);
132+
.clear(ProcessFlags::GrowHeap | ProcessFlags::NeedFullSweep);
133133
// Allocate new heap
134134
let new_heap_start = alloc::heap(new_size).map_err(|alloc| GcError::Alloc(alloc))?;
135135
let mut new_heap = YoungHeap::new(new_heap_start, new_size);
@@ -247,7 +247,7 @@ impl<'p, 'h> GarbageCollector<'p, 'h> {
247247
panic!("Full sweep finished, but the needed size exceeds even the most pessimistic estimate, this must be a bug");
248248
} else if total_size * 3 < need_after * 4 {
249249
// `need_after` requires more than 75% of the current size, schedule some growth
250-
self.process.flags.set(ProcessFlag::GrowHeap);
250+
self.process.flags.set(ProcessFlags::GrowHeap);
251251
} else if total_size > need_after * 4 && self.process.min_heap_size < total_size {
252252
// We need less than 25% of the current heap, shrink
253253
let wanted = need_after * 2;
@@ -560,7 +560,7 @@ impl<'p, 'h> GarbageCollector<'p, 'h> {
560560
/// Determines if we should try and grow the heap even when not necessary
561561
#[inline]
562562
fn should_force_heap_growth(&self) -> bool {
563-
self.process.flags.is_set(ProcessFlag::GrowHeap)
563+
self.process.flags.are_set(ProcessFlags::GrowHeap)
564564
}
565565

566566
/// Calculates the reduction count cost of a collection

liblumen_alloc/src/erts/process/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::alloc;
1616
fn gc_simple_fullsweep_test() {
1717
// Create process
1818
let process = process();
19-
process.set_flags(ProcessFlag::NeedFullSweep);
19+
process.set_flags(ProcessFlags::NeedFullSweep);
2020
simple_gc_test(process);
2121
}
2222

0 commit comments

Comments
 (0)