Move Tid from Thread to PosixThread

This commit is contained in:
Jianfeng Jiang
2024-09-12 04:48:33 +00:00
committed by Tate, Hongliang Tian
parent ceb6e2b242
commit 81b0f265b5
21 changed files with 90 additions and 86 deletions

View File

@ -2,7 +2,7 @@
#![allow(dead_code)]
use core::sync::atomic::Ordering;
use core::sync::atomic::{AtomicU32, Ordering};
use aster_rights::{ReadOp, WriteOp};
use ostd::sync::Waker;
@ -42,6 +42,8 @@ pub use robust_list::RobustListHead;
pub struct PosixThread {
// Immutable part
process: Weak<Process>,
tid: Tid,
// Mutable part
name: Mutex<Option<ThreadName>>,
@ -87,6 +89,11 @@ impl PosixThread {
Weak::clone(&self.process)
}
/// Returns the thread id
pub fn tid(&self) -> Tid {
self.tid
}
pub fn thread_name(&self) -> &Mutex<Option<ThreadName>> {
&self.name
}
@ -292,3 +299,10 @@ impl PosixThread {
self.credentials.dup().restrict()
}
}
static POSIX_TID_ALLOCATOR: AtomicU32 = AtomicU32::new(0);
/// Allocates a new tid for the new posix thread
pub fn allocate_posix_tid() -> Tid {
POSIX_TID_ALLOCATOR.fetch_add(1, Ordering::SeqCst)
}