Changeset 584 for trunk/kernel/syscalls/sys_thread_exit.c
- Timestamp:
- Nov 1, 2018, 12:13:45 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_thread_exit.c
r566 r584 36 36 int sys_thread_exit( void * exit_value ) 37 37 { 38 reg_t save_sr; // required to enable IRQs39 xptr_t owner_xp; // extended pointer on owner process40 41 38 thread_t * this = CURRENT_THREAD; 42 39 trdid_t trdid = this->trdid; 43 40 process_t * process = this->process; 44 41 pid_t pid = process->pid; 45 cxy_t owner_cxy = CXY_FROM_PID( pid );46 42 47 43 // check exit_value argument … … 57 53 } 58 54 59 #if DEBUG_SYS_THREAD_EXIT60 uint64_t tm_start;61 uint64_t tm_end;62 tm_start = hal_get_cycles();63 if( DEBUG_SYS_THREAD_EXIT < tm_start )64 printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n",65 __FUNCTION__ , this->trdid, pid , (uint32_t)tm_start );66 #endif67 55 68 56 // If calling thread is the main thread, the process must be deleted. 69 // This require to delete all process threads and synchronise with parent process 70 if( (local_cxy == owner_cxy) && (LTID_FROM_TRDID(trdid) == 0) ) 57 // => delete all process threads and synchronise with parent process. 58 // If calling thread is not the main thread, it must be deleted. 59 // => block the thread and mark it for delete. 60 if( (CXY_FROM_PID( pid ) == local_cxy) && (LTID_FROM_TRDID(trdid) == 0) ) 71 61 { 72 // get extended pointer on owner cluster73 owner_xp = cluster_get_owner_process_from_pid( pid );74 62 75 // mark for delete all threads but the main 76 hal_enable_irq( &save_sr ); 77 process_sigaction( pid , DELETE_ALL_THREADS ); 78 hal_restore_irq( save_sr ); 79 80 // remove process from TXT list 81 process_txt_detach( owner_xp ); 82 83 // block the main thread 84 thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_GLOBAL ); 85 86 // atomically update owner process descriptor term_state to ask 87 // the parent process sys_wait() function to delete the main thread 88 hal_remote_atomic_or( XPTR( local_cxy , &process->term_state ) , 89 PROCESS_TERM_EXIT ); 63 #if DEBUG_SYS_THREAD_EXIT 64 uint64_t tm_start = hal_get_cycles(); 65 if( DEBUG_SYS_THREAD_EXIT < tm_start ) 66 printk("\n[DBG] %s : thread[%x,%x] / main => delete process / cycle %d\n", 67 __FUNCTION__ , pid , trdid , (uint32_t)tm_start ); 68 #endif 69 // delete process 70 sys_exit( 0 ); 90 71 } 91 72 else 92 73 { 74 75 #if DEBUG_SYS_THREAD_EXIT 76 uint64_t tm_start = hal_get_cycles(); 77 if( DEBUG_SYS_THREAD_EXIT < tm_start ) 78 printk("\n[DBG] %s : thread[%x,%x] / not main => delete thread / cycle %d\n", 79 __FUNCTION__ , pid , trdid , (uint32_t)tm_start ); 80 #endif 93 81 // block calling thread and mark it for delete, 94 82 thread_delete( XPTR( local_cxy , this ) , pid , false ); 83 84 // deschedule 85 sched_yield( "suicide after thread_exit" ); 95 86 } 96 87 97 #if DEBUG_SYS_THREAD_EXIT98 tm_end = hal_get_cycles();99 if( DEBUG_SYS_THREAD_EXIT < tm_end )100 printk("\n[DBG] %s : thread %x in process %x exit / cost %d / cycle %d\n",101 __FUNCTION__, this->trdid, pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );102 #endif103 104 // deschedule <=> suicide, because blocked by thread_delete()105 sched_yield( "suicide after thread_exit" );106 107 88 return 0; // never executed but required by compiler 108 89
Note: See TracChangeset
for help on using the changeset viewer.