Changeset 566 for trunk/kernel/syscalls/sys_mutex.c
- Timestamp:
- Oct 4, 2018, 11:50:21 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_mutex.c
r508 r566 32 32 33 33 34 #if DEBUG_SYS_MUTEX 35 //////////////////////////////////////////////////// 36 static char * sys_mutex_op_str( uint32_t operation ) 37 { 38 if ( operation == MUTEX_INIT ) return "INIT"; 39 else if( operation == MUTEX_LOCK ) return "LOCK"; 40 else if( operation == MUTEX_UNLOCK ) return "UNLOCK"; 41 else if( operation == MUTEX_TRYLOCK ) return "TRYLOCK"; 42 else if( operation == MUTEX_DESTROY ) return "DESTROY"; 43 else return "undefined"; 44 } 45 #endif 46 34 47 ///////////////////////////////// 35 48 int sys_mutex( void * vaddr, … … 38 51 { 39 52 error_t error; 40 vseg_t * vseg; 53 vseg_t * vseg; // for vaddr check 41 54 42 55 thread_t * this = CURRENT_THREAD; 43 56 process_t * process = this->process; 57 58 #if DEBUG_SYS_MUTEX 59 uint64_t tm_start; 60 uint64_t tm_end; 61 tm_start = hal_get_cycles(); 62 if( DEBUG_SYS_MUTEX < tm_start ) 63 printk("\n[DBG] %s : thread %x in process %x enter for %s / cycle %d\n", 64 __FUNCTION__, this->trdid, process->pid, sys_mutex_op_str( operation ), (uint32_t)tm_start ); 65 #endif 44 66 45 67 // check vaddr in user vspace … … 148 170 else // success 149 171 { 150 remote_mutex_unlock( mutex_xp ); 172 error = remote_mutex_unlock( mutex_xp ); 173 174 if( error ) 175 { 176 177 #if DEBUG_SYSCALLS_ERROR 178 printk("\n[ERROR] in %s : mutex %x not owned in UNLOCK / thread %x / process %x\n", 179 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid ); 180 #endif 181 this->errno = EINVAL; 182 return -1; 183 } 184 } 185 break; 186 } 187 /////////////////// 188 case MUTEX_TRYLOCK: 189 { 190 xptr_t mutex_xp = remote_mutex_from_ident( (intptr_t)vaddr ); 191 192 if( mutex_xp == XPTR_NULL ) // user error 193 { 194 195 #if DEBUG_SYSCALLS_ERROR 196 printk("\n[ERROR] in %s : mutex %x not registered / thread %x / process %x\n", 197 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid ); 198 #endif 199 this->errno = EINVAL; 200 return -1; 201 } 202 else // success 203 { 204 error = remote_mutex_trylock( mutex_xp ); 205 206 if( error ) // non fatal : mutex already taken 207 { 208 this->errno = EBUSY; 209 return -1; 210 } 151 211 } 152 212 break; 153 213 } 154 214 //////// 155 default: { 215 default: 216 { 156 217 assert ( false, "illegal operation type <%x>", operation ); 157 218 } 158 219 } 159 220 221 hal_fence(); 222 223 #if DEBUG_SYS_MUTEX 224 tm_end = hal_get_cycles(); 225 if( DEBUG_SYS_MUTEX < tm_start ) 226 printk("\n[DBG] %s : thread %x in process %x exit for %s / cost %d / cycle %d\n", 227 __FUNCTION__, this->trdid, process->pid, sys_mutex_op_str( operation ), 228 (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 229 #endif 230 160 231 return 0; 161 232
Note: See TracChangeset
for help on using the changeset viewer.