Changeset 31696b4f in mainline for kernel/generic/src/ipc/kbox.c
- Timestamp:
- 2008-11-23T10:59:21Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 50e5b25
- Parents:
- 0aa1665
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ipc/kbox.c
r0aa1665 r31696b4f 49 49 bool have_kb_thread; 50 50 51 /* Only hold kb_cleanup_lock while setting kb_finished - this is enough */ 52 mutex_lock(&TASK->kb_cleanup_lock); 53 TASK->kb_finished = true; 54 mutex_unlock(&TASK->kb_cleanup_lock); 55 56 have_kb_thread = (TASK->kb_thread != NULL); 57 58 /* From now on nobody will try to connect phones or attach kbox threads */ 51 /* 52 * Only hold kb.cleanup_lock while setting kb.finished - 53 * this is enough. 54 */ 55 mutex_lock(&TASK->kb.cleanup_lock); 56 TASK->kb.finished = true; 57 mutex_unlock(&TASK->kb.cleanup_lock); 58 59 have_kb_thread = (TASK->kb.thread != NULL); 60 61 /* 62 * From now on nobody will try to connect phones or attach 63 * kbox threads 64 */ 59 65 60 66 /* … … 64 70 * wake up and terminate. 65 71 */ 66 ipc_answerbox_slam_phones(&TASK->k ernel_box, have_kb_thread);72 ipc_answerbox_slam_phones(&TASK->kb.box, have_kb_thread); 67 73 68 74 /* … … 78 84 79 85 if (have_kb_thread) { 80 LOG("join kb _thread..\n");81 thread_join(TASK->kb _thread);82 thread_detach(TASK->kb _thread);86 LOG("join kb.thread..\n"); 87 thread_join(TASK->kb.thread); 88 thread_detach(TASK->kb.thread); 83 89 LOG("join done\n"); 84 TASK->kb _thread = NULL;85 } 86 87 /* Answer all messages in 'calls' and 'dispatched_calls' queues */88 spinlock_lock(&TASK->k ernel_box.lock);89 ipc_cleanup_call_list(&TASK->k ernel_box.dispatched_calls);90 ipc_cleanup_call_list(&TASK->k ernel_box.calls);91 spinlock_unlock(&TASK->k ernel_box.lock);90 TASK->kb.thread = NULL; 91 } 92 93 /* Answer all messages in 'calls' and 'dispatched_calls' queues. */ 94 spinlock_lock(&TASK->kb.box.lock); 95 ipc_cleanup_call_list(&TASK->kb.box.dispatched_calls); 96 ipc_cleanup_call_list(&TASK->kb.box.calls); 97 spinlock_unlock(&TASK->kb.box.lock); 92 98 } 93 99 … … 106 112 /* Was it our debugger, who hung up? */ 107 113 if (call->sender == TASK->udebug.debugger) { 108 /* Terminate debugging session (if any) */114 /* Terminate debugging session (if any). */ 109 115 LOG("kbox: terminate debug session\n"); 110 116 ipl = interrupts_disable(); … … 119 125 LOG("kbox: continue with hangup message\n"); 120 126 IPC_SET_RETVAL(call->data, 0); 121 ipc_answer(&TASK->k ernel_box, call);127 ipc_answer(&TASK->kb.box, call); 122 128 123 129 ipl = interrupts_disable(); … … 131 137 132 138 /* Only detach kbox thread unless already terminating. */ 133 mutex_lock(&TASK->kb _cleanup_lock);134 if (&TASK->kb _finished == false) {139 mutex_lock(&TASK->kb.cleanup_lock); 140 if (&TASK->kb.finished == false) { 135 141 /* Detach kbox thread so it gets freed from memory. */ 136 thread_detach(TASK->kb _thread);137 TASK->kb _thread = NULL;142 thread_detach(TASK->kb.thread); 143 TASK->kb.thread = NULL; 138 144 } 139 mutex_unlock(&TASK->kb _cleanup_lock);145 mutex_unlock(&TASK->kb.cleanup_lock); 140 146 141 147 LOG("phone list is empty\n"); … … 167 173 168 174 while (!done) { 169 call = ipc_wait_for_call(&TASK->k ernel_box, SYNCH_NO_TIMEOUT,175 call = ipc_wait_for_call(&TASK->kb.box, SYNCH_NO_TIMEOUT, 170 176 SYNCH_FLAGS_NONE); 171 177 … … 202 208 * Connect phone to a task kernel-box specified by id. 203 209 * 204 * Note that this is not completely atomic. For optimisation reasons, 205 * The task might start cleaning up kbox after the phone has been connected206 * a nd before a kbox thread has been created. This must be taken into account207 * in thecleanup code.210 * Note that this is not completely atomic. For optimisation reasons, the task 211 * might start cleaning up kbox after the phone has been connected and before 212 * a kbox thread has been created. This must be taken into account in the 213 * cleanup code. 208 214 * 209 215 * @return Phone id on success, or negative error code. … … 231 237 interrupts_restore(ipl); 232 238 233 mutex_lock(&ta->kb _cleanup_lock);239 mutex_lock(&ta->kb.cleanup_lock); 234 240 235 241 if (atomic_predec(&ta->refcount) == 0) { 236 mutex_unlock(&ta->kb _cleanup_lock);242 mutex_unlock(&ta->kb.cleanup_lock); 237 243 task_destroy(ta); 238 244 return ENOENT; 239 245 } 240 246 241 if (ta->kb _finished != false) {242 mutex_unlock(&ta->kb _cleanup_lock);247 if (ta->kb.finished != false) { 248 mutex_unlock(&ta->kb.cleanup_lock); 243 249 return EINVAL; 244 250 } … … 246 252 newphid = phone_alloc(); 247 253 if (newphid < 0) { 248 mutex_unlock(&ta->kb _cleanup_lock);254 mutex_unlock(&ta->kb.cleanup_lock); 249 255 return ELIMIT; 250 256 } 251 257 252 258 /* Connect the newly allocated phone to the kbox */ 253 ipc_phone_connect(&TASK->phones[newphid], &ta->k ernel_box);254 255 if (ta->kb _thread != NULL) {256 mutex_unlock(&ta->kb _cleanup_lock);259 ipc_phone_connect(&TASK->phones[newphid], &ta->kb.box); 260 261 if (ta->kb.thread != NULL) { 262 mutex_unlock(&ta->kb.cleanup_lock); 257 263 return newphid; 258 264 } 259 265 260 266 /* Create a kbox thread */ 261 kb_thread = thread_create(kbox_thread_proc, NULL, ta, 0, "kbox", false); 267 kb_thread = thread_create(kbox_thread_proc, NULL, ta, 0, 268 "kbox", false); 262 269 if (!kb_thread) { 263 mutex_unlock(&ta->kb _cleanup_lock);270 mutex_unlock(&ta->kb.cleanup_lock); 264 271 return ENOMEM; 265 272 } 266 273 267 ta->kb _thread = kb_thread;274 ta->kb.thread = kb_thread; 268 275 thread_ready(kb_thread); 269 276 270 mutex_unlock(&ta->kb _cleanup_lock);277 mutex_unlock(&ta->kb.cleanup_lock); 271 278 272 279 return newphid;
Note:
See TracChangeset
for help on using the changeset viewer.