move nextpid into atomic i32 in rust
This commit is contained in:
parent
50448eb307
commit
bae37aa507
@ -10,9 +10,6 @@ struct proc proc[NPROC];
|
|||||||
|
|
||||||
struct proc *initproc;
|
struct proc *initproc;
|
||||||
|
|
||||||
int nextpid = 1;
|
|
||||||
struct spinlock pid_lock;
|
|
||||||
|
|
||||||
extern void forkret(void);
|
extern void forkret(void);
|
||||||
void freeproc(struct proc *p);
|
void freeproc(struct proc *p);
|
||||||
|
|
||||||
@ -47,7 +44,6 @@ procinit(void)
|
|||||||
{
|
{
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
|
|
||||||
initlock(&pid_lock, "nextpid");
|
|
||||||
initlock(&wait_lock, "wait_lock");
|
initlock(&wait_lock, "wait_lock");
|
||||||
for(p = proc; p < &proc[NPROC]; p++) {
|
for(p = proc; p < &proc[NPROC]; p++) {
|
||||||
initlock(&p->lock, "proc");
|
initlock(&p->lock, "proc");
|
||||||
|
@ -10,6 +10,7 @@ use crate::{
|
|||||||
use core::{
|
use core::{
|
||||||
ffi::{c_char, c_void},
|
ffi::{c_char, c_void},
|
||||||
ptr::{addr_of_mut, null_mut},
|
ptr::{addr_of_mut, null_mut},
|
||||||
|
sync::atomic::{AtomicI32, Ordering},
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -45,6 +46,8 @@ extern "C" {
|
|||||||
pub fn swtch(a: *mut Context, b: *mut Context);
|
pub fn swtch(a: *mut Context, b: *mut Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub static NEXT_PID: AtomicI32 = AtomicI32::new(1);
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(PartialEq, Default)]
|
#[derive(PartialEq, Default)]
|
||||||
pub enum ProcState {
|
pub enum ProcState {
|
||||||
@ -164,7 +167,7 @@ impl Proc {
|
|||||||
|
|
||||||
/// Return the current struct proc *, or zero if none.
|
/// Return the current struct proc *, or zero if none.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn myproc() -> *mut Proc {
|
pub extern "C" fn myproc() -> *mut Proc {
|
||||||
if let Some(p) = Proc::current() {
|
if let Some(p) = Proc::current() {
|
||||||
p as *mut Proc
|
p as *mut Proc
|
||||||
} else {
|
} else {
|
||||||
@ -173,11 +176,8 @@ pub unsafe extern "C" fn myproc() -> *mut Proc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn allocpid() -> i32 {
|
pub extern "C" fn allocpid() -> i32 {
|
||||||
let _guard = pid_lock.lock();
|
NEXT_PID.fetch_add(1, Ordering::SeqCst)
|
||||||
let pid = nextpid;
|
|
||||||
nextpid += 1;
|
|
||||||
pid
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Free a proc structure and the data hanging from it, including user pages.
|
/// Free a proc structure and the data hanging from it, including user pages.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user