@@ -50,7 +50,7 @@ pub struct Process {
5050 /// The display name of this process.
5151 name : String ,
5252 /// The parent of this process, or [`None`], if this is the init process.
53- parent : Option < Weak < Process > > ,
53+ parent : SpinMutex < Option < Weak < Process > > > ,
5454 /// A list of [`Task`]s associated with this process.
5555 pub threads : SpinMutex < Vec < Arc < Task > > > ,
5656 /// The address space for this process.
@@ -123,12 +123,7 @@ impl Process {
123123 /// Gets the parent process of this process.
124124 /// Returns [`None`], if it is the init process.
125125 pub fn get_parent ( & self ) -> Option < Arc < Self > > {
126- // TODO: The upgrade should never fail.
127- // If it does, then somehow the child was alive but the parent was not.
128- self . parent . as_ref ( ) . map ( |x| {
129- x. upgrade ( )
130- . expect ( "FIXME: Child process was alive for longer than the parent" )
131- } )
126+ self . parent . lock ( ) . as_ref ( ) . and_then ( Weak :: upgrade)
132127 }
133128
134129 pub fn new ( name : String , parent : Option < Arc < Self > > ) -> EResult < Self > {
@@ -139,7 +134,7 @@ impl Process {
139134 let forked = Arc :: new ( Self {
140135 id : PID_COUNTER . fetch_add ( 1 , Ordering :: Acquire ) as _ ,
141136 name : self . name . clone ( ) ,
142- parent : Some ( Arc :: downgrade ( & self ) ) ,
137+ parent : SpinMutex :: new ( Some ( Arc :: downgrade ( & self ) ) ) ,
143138 threads : SpinMutex :: new ( Vec :: new ( ) ) ,
144139 address_space : Arc :: new ( SpinMutex :: new ( self . address_space . lock ( ) . fork ( ) ?) ) ,
145140 root_dir : SpinMutex :: new ( self . root_dir . lock ( ) . clone ( ) ) ,
@@ -215,7 +210,7 @@ impl Process {
215210 Ok ( Self {
216211 id,
217212 name,
218- parent : parent. map ( |x| Arc :: downgrade ( & x) ) ,
213+ parent : SpinMutex :: new ( parent. map ( |x| Arc :: downgrade ( & x) ) ) ,
219214 threads : SpinMutex :: new ( Vec :: new ( ) ) ,
220215 address_space : Arc :: new ( SpinMutex :: new ( space) ) ,
221216 status : SpinMutex :: new ( ProcessState :: Running ) ,
0 commit comments