Changeset 651 for trunk/kernel/syscalls/sys_thread_join.c
- Timestamp:
- Nov 14, 2019, 11:50:09 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_thread_join.c
r637 r651 1 1 /* 2 * sys_thread_join.c - passive wait on the end of a giventhread.2 * sys_thread_join.c - wait termination of of an attached thread. 3 3 * 4 4 * Authors Alain Greiner (2016,2017,2018,2019) … … 26 26 #include <hal_special.h> 27 27 #include <hal_irqmask.h> 28 #include <hal_uspace.h> 28 29 #include <thread.h> 29 30 #include <vmm.h> … … 37 38 /////////////////////////////////////// 38 39 int sys_thread_join ( trdid_t trdid, 39 void ** exit_ value)40 void ** exit_status ) 40 41 { 42 error_t error; 41 43 reg_t save_sr; 42 44 xptr_t target_xp; … … 47 49 xptr_t target_flags_xp; 48 50 xptr_t target_join_xp_xp; 51 xptr_t target_exit_status_xp; 49 52 xptr_t killer_xp; 50 53 xptr_t joining_xp; 51 54 thread_t * joining_ptr; 52 55 process_t * process; 56 vseg_t * vseg; 57 void * status; 53 58 54 59 // get joining thread pointers … … 62 67 63 68 #if DEBUG_SYS_THREAD_JOIN 64 uint64_t tm_start; 65 uint64_t tm_end; 66 tm_start = hal_get_cycles(); 69 uint64_t tm_start = hal_get_cycles(); 67 70 if( DEBUG_SYS_THREAD_JOIN < tm_start ) 68 printk("\n[ DBG] %s :joining thread[%x,%x] enter / target thread[%x,%x] / cycle %d\n",71 printk("\n[%s] joining thread[%x,%x] enter / target thread[%x,%x] / cycle %d\n", 69 72 __FUNCTION__ , process->pid, joining_ptr->trdid, 70 73 process->pid, trdid, (uint32_t)tm_start ); … … 77 80 78 81 #if DEBUG_SYSCALLS_ERROR 79 printk("\n[ERROR] in %s : illegal trdid argument %x \n",80 __FUNCTION__, trdid );82 printk("\n[ERROR] in %s : illegal trdid argument %x / joining thread[%x,%x]\n", 83 __FUNCTION__, trdid, joining_ptr->process->pid, joining_ptr-trdid ); 81 84 #endif 82 85 joining_ptr->errno = EINVAL; … … 84 87 } 85 88 86 // check exit_value argument 87 if( exit_value != NULL ) 89 // check exit_value argument in user space 90 error = vmm_get_vseg( process , (intptr_t)exit_status , &vseg ); 91 if( error ) 88 92 { 89 93 90 94 #if DEBUG_SYSCALLS_ERROR 91 printk("\n[ERROR] in %s : exit_ value argument must be NULL\n",92 __FUNCTION__ );95 printk("\n[ERROR] in %s : exit_status argument %x not mapped / joining thread[%x,%x]\n", 96 __FUNCTION__, exit_status, joining_ptr->process->pid, joining_ptr-trdid ); 93 97 #endif 94 98 joining_ptr->errno = EINVAL; … … 101 105 102 106 #if DEBUG_SYSCALLS_ERROR 103 printk("\n[ERROR] in %s : this thread (%x) == target thread(%x)\n",104 __FUNCTION__, joining_ptr-> trdid,trdid );107 printk("\n[ERROR] in %s : joinig thread[%x,%x] == target thread\n", 108 __FUNCTION__, joining_ptr->process->pid, joining_ptr->trdid ); 105 109 #endif 106 110 joining_ptr->errno = EDEADLK; … … 116 120 117 121 #if DEBUG_SYSCALLS_ERROR 118 printk("\n[ERROR] in %s : target thread %x not found\n",119 __FUNCTION__, trdid );122 printk("\n[ERROR] in %s : target thread[%x,%x] not found / joining_thread[%x,%x]\n", 123 __FUNCTION__, process->pid, trdid, joining_ptr->process->pid, joining_ptr-trdid ); 120 124 #endif 121 125 joining_ptr->errno = ESRCH; … … 124 128 125 129 // get extended pointers on various fields in target thread 126 target_join_lock_xp = XPTR( target_cxy , &target_ptr->join_lock ); 127 target_flags_xp = XPTR( target_cxy , &target_ptr->flags ); 128 target_join_xp_xp = XPTR( target_cxy , &target_ptr->join_xp ); 130 target_join_lock_xp = XPTR( target_cxy , &target_ptr->join_lock ); 131 target_flags_xp = XPTR( target_cxy , &target_ptr->flags ); 132 target_join_xp_xp = XPTR( target_cxy , &target_ptr->join_xp ); 133 target_exit_status_xp = XPTR( target_cxy , &target_ptr->exit_status ); 129 134 130 135 // check target thread joinable … … 133 138 134 139 #if DEBUG_SYSCALLS_ERROR 135 printk("\n[ERROR] in %s : target thread %x not joinable\n", __FUNCTION__, trdid ); 140 printk("\n[ERROR] in %s : target thread[%x,‰x] not attached / joining thread[%x,%x]\n", 141 __FUNCTION__, process->pid, trdid, joining_ptr->process->pid, joining_ptr-trdid ); 136 142 #endif 137 143 joining_ptr->errno = EINVAL; … … 146 152 147 153 // test the kill_done flag from the target thread 148 if( hal_remote_l32( target_flags_xp ) & THREAD_FLAG_KILL_DONE ) // killer thread is first 149 { 154 if( hal_remote_l32( target_flags_xp ) & THREAD_FLAG_KILL_DONE ) // killer is first 155 { 156 // get exit_status from target thread 157 status = (void*)hal_remote_lpt( target_exit_status_xp ); 158 150 159 // get pointers on killer thread 151 160 killer_xp = (xptr_t)hal_remote_l64( target_join_xp_xp ); … … 159 168 // release the lock protecting join 160 169 remote_busylock_release( target_join_lock_xp ); 161 162 #if DEBUG_SYS_THREAD_JOIN 163 tm_end = hal_get_cycles(); 164 if( DEBUG_SYS_THREAD_JOIN < tm_end ) 165 printk("\n[DBG] %s : joining thread[%x,%x] exit / target thread[%x,%x] completed / cycle %d\n", 166 __FUNCTION__, process->pid, joining_ptr->trdid, process->pid, trdid, (uint32_t)tm_end ); 167 #endif 168 169 } 170 else // joining thread is first 170 } 171 else // joining is first 171 172 { 172 173 // set the join_done flag in target thread … … 184 185 #if DEBUG_SYS_THREAD_JOIN 185 186 if( DEBUG_SYS_THREAD_JOIN < tm_start ) 186 printk("\n[ DBG] %s :joining thread[%x,%x] deschedules / target thread[%x,%x] not completed\n",187 printk("\n[%s] joining thread[%x,%x] deschedules / target thread[%x,%x] not completed\n", 187 188 __FUNCTION__ , process->pid, joining_ptr->trdid, process->pid, trdid ); 188 189 #endif 189 190 // deschedule 190 191 sched_yield( "joining thread waiting killer thread" ); 192 193 // returns exit_status from joining thread 194 status = joining_ptr->exit_status; 195 } 191 196 197 // returns exit_status to user space 198 hal_copy_to_uspace( exit_status, 199 XPTR( local_cxy , &status ), 200 sizeof( void* ) ); 201 202 // restore IRQs 203 hal_restore_irq( save_sr ); 204 205 hal_fence(); 206 207 #if (DEBUG_SYS_THREAD_JOIN || CONFIG_INSTRUMENTATION_SYSCALLS) 208 uint64_t tm_end = hal_get_cycles(); 209 #endif 210 211 #if CONFIG_INSTRUMENTATION_SYSCALLS 212 hal_atomic_add( &syscalls_cumul_cost[SYS_THREAD_JOIN] , tm_end - tm_start ); 213 hal_atomic_add( &syscalls_occurences[SYS_THREAD_JOIN] , 1 ); 214 #endif 215 192 216 #if DEBUG_SYS_THREAD_JOIN 193 217 tm_end = hal_get_cycles(); 194 218 if( DEBUG_SYS_THREAD_JOIN < tm_end ) 195 printk("\n[ DBG] %s :joining thread[%x,%x] exit / target thread[%x,%x] completed / cycle %d\n",219 printk("\n[%s] joining thread[%x,%x] exit / target thread[%x,%x] completed / cycle %d\n", 196 220 __FUNCTION__ , process->pid, joining_ptr->trdid, process->pid, trdid, (uint32_t)tm_end ); 197 221 #endif 198 222 199 }200 201 // restore IRQs202 hal_restore_irq( save_sr );203 204 223 return 0; 205 224
Note: See TracChangeset
for help on using the changeset viewer.