Changeset 446 for trunk/kernel/syscalls/sys_exit.c
- Timestamp:
- Jun 19, 2018, 5:12:57 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_exit.c
r445 r446 36 36 int sys_exit( uint32_t status ) 37 37 { 38 reg_t save_sr; // required to enable IRQs 38 reg_t save_sr; // required to enable IRQs 39 40 xptr_t owner_xp; // extended pointer on owner process 41 cxy_t owner_cxy; // owner process cluster 42 process_t * owner_ptr; // local pointer on owner process 43 thread_t * main_ptr; // local pointer on process main thread 44 xptr_t parent_xp; // extended pointer on parent process 45 cxy_t parent_cxy; // parent process cluster 46 process_t * parent_ptr; // local pointer on parent process 47 xptr_t children_lock_xp; // extended pointer on children locki 48 thread_t * parent_main_ptr; // local pointer on parent main thread 49 xptr_t parent_main_xp; // extended pointer on parent main thread 50 uint32_t term_state; // termination status for owner process 39 51 40 52 thread_t * this = CURRENT_THREAD; … … 52 64 53 65 // get owner process descriptor pointers 54 xptr_towner_xp = process->owner_xp;55 cxy_towner_cxy = GET_CXY( owner_xp );56 process_t *owner_ptr = GET_PTR( owner_xp );66 owner_xp = process->owner_xp; 67 owner_cxy = GET_CXY( owner_xp ); 68 owner_ptr = GET_PTR( owner_xp ); 57 69 58 // get pointers on the process main thread 59 thread_t * main = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) ); 60 61 // enable IRQs 62 hal_enable_irq( &save_sr ); 63 64 // mark for delete all process threads in all clusters, 65 // but the main thread and this calling thread 66 process_sigaction( pid , DELETE_ALL_THREADS ); 67 68 // disable IRQs 69 hal_restore_irq( save_sr ); 70 71 #if( DEBUG_SYS_EXIT & 1) 72 if( tm_start > DEBUG_SYS_EXIT ) 73 printk("\n[DBG] %s : thread %x deleted threads / process %x\n", 74 __FUNCTION__ , this, pid ); 70 #if (DEBUG_SYS_EXIT & 1) 71 if( DEBUG_SYS_EXIT < tm_start ) 72 printk("\n[DBG] %s : thread %x get owner process %x in cluster %x\n", 73 __FUNCTION__ , this, owner_ptr, owner_cxy ); 75 74 #endif 76 75 77 // mark for delete this calling thread when it is not the main 78 if( (owner_cxy != local_cxy) || (main != this) ) 79 { 76 // get pointer on the process main thread 77 main_ptr = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) ); 80 78 81 #if( DEBUG_SYS_EXIT & 1) 82 if( tm_start > DEBUG_SYS_EXIT ) 83 printk("\n[DBG] %s : calling thread %x marked iself for delete / process %x\n", 84 __FUNCTION__ , this, pid ); 79 // get parent process descriptor pointers 80 parent_xp = process->parent_xp; 81 parent_cxy = GET_CXY( parent_xp ); 82 parent_ptr = GET_PTR( parent_xp ); 83 84 #if (DEBUG_SYS_EXIT & 1) 85 if( DEBUG_SYS_EXIT < tm_start ) 86 printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n", 87 __FUNCTION__ , this, parent_ptr, parent_cxy ); 85 88 #endif 86 thread_delete( XPTR( local_cxy , this ) , pid , true ); 87 } 89 90 // get extended pointer on lock protecting children list in parent process 91 children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock ); 92 93 // get pointers on the parent process main thread 94 parent_main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) ); 95 parent_main_xp = XPTR( parent_cxy , parent_main_ptr ); 88 96 89 97 // remove process from TXT list … … 96 104 #endif 97 105 98 // block the main thread 99 thread_block( XPTR( owner_cxy , main ) , THREAD_BLOCKED_GLOBAL ); 106 // mark for delete all process threads in all clusters, 107 // but the main thread and this calling thread 108 hal_enable_irq( &save_sr ); 109 process_sigaction( pid , DELETE_ALL_THREADS ); 110 hal_restore_irq( save_sr ); 111 112 #if( DEBUG_SYS_EXIT & 1) 113 if( tm_start > DEBUG_SYS_EXIT ) 114 printk("\n[DBG] %s : thread %x deleted threads for process %x\n", 115 __FUNCTION__ , this, pid ); 116 #endif 117 118 // mark for delete this calling thread when it is not the main 119 if( (owner_cxy != local_cxy) || (main_ptr != this) ) 120 { 121 122 #if( DEBUG_SYS_EXIT & 1) 123 if( tm_start > DEBUG_SYS_EXIT ) 124 printk("\n[DBG] %s : calling thread %x marked iself for delete in process %x\n", 125 __FUNCTION__ , this, pid ); 126 #endif 127 thread_delete( XPTR( local_cxy , this ) , pid , true ); 128 } 129 130 // block this main thread 131 thread_block( XPTR( owner_cxy , main_ptr ) , THREAD_BLOCKED_GLOBAL ); 100 132 101 133 #if( DEBUG_SYS_EXIT & 1) … … 107 139 // atomically update owner process descriptor term_state to ask 108 140 // the parent process sys_wait() function to delete the main thread 109 hal_remote_atomic_or( XPTR( owner_cxy , &process->term_state ) ,110 PROCESS_TERM_EXIT | (status & 0xFF));141 term_state = (status & 0xFF) | PROCESS_TERM_EXIT; 142 hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , term_state ); 111 143 112 144 #if( DEBUG_SYS_EXIT & 1) 113 145 if( tm_start > DEBUG_SYS_EXIT ) 114 printk("\n[DBG] %s : thread %x set exit status in process %x term_state\n", 115 __FUNCTION__ , this, pid ); 146 printk("\n[DBG] %s : thread %x set exit status in process %x / term_state %x\n", 147 __FUNCTION__ , this, pid, term_state ); 148 #endif 149 150 // take the children lock and unblock the parent process main thread 151 remote_spinlock_lock( children_lock_xp ); 152 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 153 remote_spinlock_unlock( children_lock_xp ); 154 155 #if( DEBUG_SYS_EXIT & 1) 156 if( tm_start > DEBUG_SYS_EXIT ) 157 printk("\n[DBG] %s : thread %x in cluster %x unblock parent main thread %x in cluster %x\n", 158 __FUNCTION__ , this, local_cxy, parent_main_ptr, parent_cxy ); 116 159 #endif 117 160
Note: See TracChangeset
for help on using the changeset viewer.