Changeset 440 for trunk/kernel/syscalls/sys_thread_cancel.c
- Timestamp:
- May 3, 2018, 5:51:22 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_thread_cancel.c
r438 r440 23 23 24 24 #include <hal_types.h> 25 #include <hal_irqmask.h> 25 26 #include <hal_remote.h> 26 27 #include <hal_special.h> … … 32 33 int sys_thread_cancel( trdid_t trdid ) 33 34 { 35 reg_t save_sr; // required to enable IRQs 34 36 xptr_t target_xp; // target thread extended pointer 37 cxy_t target_cxy; // target thread cluster identifier 38 ltid_t target_ltid; // target thread local index 39 cxy_t owner_cxy; // process owner cluster identifier 40 xptr_t owner_xp; // extended pointer on owner process 35 41 36 42 // get killer thread pointers 37 43 thread_t * this = CURRENT_THREAD; 38 44 process_t * process = this->process; 45 pid_t pid = process->pid; 39 46 40 47 // get extended pointer on target thread 41 target_xp = thread_get_xptr( p rocess->pid , trdid );48 target_xp = thread_get_xptr( pid , trdid ); 42 49 43 50 // check target_xp … … 61 68 #endif 62 69 63 // cal the relevant kernel function 64 thread_kill( target_xp, 65 0, // is_exit 66 0 ); // is forced 70 // get process owner cluster identifier 71 owner_cxy = CXY_FROM_PID( pid ); 72 73 // get target thread ltid and cluster 74 target_cxy = CXY_FROM_TRDID( trdid ); 75 target_ltid = LTID_FROM_TRDID( trdid ); 76 77 // If target thread is the main thread, the process must be deleted, 78 // This require synchronisation with parent process 79 if( (target_cxy == owner_cxy) && (target_ltid == 0) ) 80 { 81 // get extended pointer on owner cluster 82 owner_xp = cluster_get_owner_process_from_pid( pid ); 83 84 // mark for delete all threads but the main 85 hal_enable_irq( &save_sr ); 86 process_sigaction( pid , DELETE_ALL_THREADS ); 87 hal_restore_irq( save_sr ); 88 89 // remove process from TXT list 90 process_txt_detach( owner_xp ); 91 92 // block the main thread 93 thread_block( XPTR( local_cxy ,this ) , THREAD_BLOCKED_GLOBAL ); 94 95 // atomically update owner process descriptor term_state to ask 96 // the parent process sys_wait() function to delete the main thread 97 hal_remote_atomic_or( XPTR( local_cxy , &process->term_state ) , 98 PROCESS_TERM_EXIT ); 99 } 100 else 101 { 102 // block target thread and mark it for delete 103 thread_delete( target_xp , pid , false ); 104 } 67 105 68 106 #if DEBUG_SYS_THREAD_CANCEL
Note: See TracChangeset
for help on using the changeset viewer.