job_group: reuse RelaxedAtomicBool

This commit is contained in:
Johannes Altmanninger 2023-10-08 18:48:15 +02:00
parent d764625069
commit 575c271461
2 changed files with 7 additions and 5 deletions

View file

@ -1,5 +1,6 @@
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
#[derive(Debug)]
pub struct RelaxedAtomicBool(AtomicBool); pub struct RelaxedAtomicBool(AtomicBool);
impl RelaxedAtomicBool { impl RelaxedAtomicBool {

View file

@ -1,11 +1,12 @@
use self::ffi::pgid_t; use self::ffi::pgid_t;
use crate::common::{assert_send, assert_sync}; use crate::common::{assert_send, assert_sync};
use crate::global_safety::RelaxedAtomicBool;
use crate::signal::Signal; use crate::signal::Signal;
use crate::wchar::prelude::*; use crate::wchar::prelude::*;
use crate::wchar_ffi::{WCharFromFFI, WCharToFFI}; use crate::wchar_ffi::{WCharFromFFI, WCharToFFI};
use cxx::{CxxWString, UniquePtr}; use cxx::{CxxWString, UniquePtr};
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering}; use std::sync::atomic::{AtomicI32, Ordering};
use std::sync::Mutex; use std::sync::Mutex;
#[cxx::bridge] #[cxx::bridge]
@ -129,7 +130,7 @@ pub struct JobGroup {
/// via [`Self::wants_terminal()`] only. /// via [`Self::wants_terminal()`] only.
wants_term: bool, wants_term: bool,
/// Whether we are in the foreground, meaning the user is waiting for this job to complete. /// Whether we are in the foreground, meaning the user is waiting for this job to complete.
pub is_foreground: AtomicBool, pub is_foreground: RelaxedAtomicBool,
/// The pgid leading our group. This is only ever set if [`job_control`](Self::JobControl) is /// The pgid leading our group. This is only ever set if [`job_control`](Self::JobControl) is
/// true. We ensure the value (when set) is always non-negative. /// true. We ensure the value (when set) is always non-negative.
pgid: Option<libc::pid_t>, pgid: Option<libc::pid_t>,
@ -161,12 +162,12 @@ impl JobGroup {
/// Whether we are the currently the foreground group. Should never be true for more than one /// Whether we are the currently the foreground group. Should never be true for more than one
/// `JobGroup` at any given moment. /// `JobGroup` at any given moment.
pub fn is_foreground(&self) -> bool { pub fn is_foreground(&self) -> bool {
self.is_foreground.load(Ordering::Relaxed) self.is_foreground.load()
} }
/// Mark whether we are in the foreground. /// Mark whether we are in the foreground.
pub fn set_is_foreground(&self, in_foreground: bool) { pub fn set_is_foreground(&self, in_foreground: bool) {
self.is_foreground.store(in_foreground, Ordering::Relaxed); self.is_foreground.store(in_foreground);
} }
/// Return the command which produced this job tree. /// Return the command which produced this job tree.
@ -347,7 +348,7 @@ impl JobGroup {
command, command,
tmodes: None, tmodes: None,
signal: 0.into(), signal: 0.into(),
is_foreground: false.into(), is_foreground: RelaxedAtomicBool::new(false),
pgid: None, pgid: None,
} }
} }