fix deadlock when log getting pid
This commit is contained in:
		
							parent
							
								
									3defc8b9aa
								
							
						
					
					
						commit
						6d432b0a03
					
				| @ -1,5 +1,5 @@ | ||||
| pub use self::process::{Status, IDLE_PROCESS}; | ||||
| pub use self::task::{get_current, run_task}; | ||||
| pub use self::task::{get_current, run_task, current_pid}; | ||||
| pub use self::process_table::{get}; | ||||
| pub use self::exit::{do_exit, do_wait4, ChildProcessFilter}; | ||||
| pub use self::spawn::{do_spawn, FileAction}; | ||||
|  | ||||
| @ -68,6 +68,12 @@ thread_local! { | ||||
|     static _CURRENT_PROCESS_PTR: Cell<*const SgxMutex<Process>> = { | ||||
|         Cell::new(0 as *const SgxMutex<Process>) | ||||
|     }; | ||||
|     // for log getting pid without locking process
 | ||||
|     static _PID: Cell<pid_t> = Cell::new(0); | ||||
| } | ||||
| 
 | ||||
| pub fn current_pid() -> pid_t { | ||||
|     _PID.with(|p| p.get()) | ||||
| } | ||||
| 
 | ||||
| pub fn get_current() -> ProcessRef { | ||||
| @ -81,6 +87,9 @@ pub fn get_current() -> ProcessRef { | ||||
| } | ||||
| 
 | ||||
| fn set_current(process: &ProcessRef) { | ||||
|     let pid = process.lock().unwrap().get_pid(); | ||||
|     _PID.with(|p| p.set(pid)); | ||||
| 
 | ||||
|     let process_ref_clone = process.clone(); | ||||
|     let process_ptr = Arc::into_raw(process_ref_clone); | ||||
| 
 | ||||
| @ -90,6 +99,7 @@ fn set_current(process: &ProcessRef) { | ||||
| } | ||||
| 
 | ||||
| fn reset_current() { | ||||
|     _PID.with(|p| p.set(0)); | ||||
|     let mut process_ptr = _CURRENT_PROCESS_PTR.with(|cp| cp.replace(0 as *const SgxMutex<Process>)); | ||||
| 
 | ||||
|     // Prevent memory leakage
 | ||||
|  | ||||
| @ -26,7 +26,7 @@ impl Log for SimpleLogger { | ||||
|                 "\u{1B}[{}m[{:>5}][{}] {}\u{1B}[0m", | ||||
|                 color as u8, | ||||
|                 record.level(), | ||||
|                 crate::process::do_getpid(), | ||||
|                 crate::process::current_pid(), | ||||
|                 record.args() | ||||
|             ); | ||||
|         } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user