Changeset 31696b4f in mainline
- 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
- Location:
- kernel/generic
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/ipc/kbox.h
r0aa1665 r31696b4f 38 38 #include <typedefs.h> 39 39 40 /** Kernel answerbox structure. */ 41 typedef struct kbox { 42 /** The answerbox itself. */ 43 answerbox_t box; 44 /** Thread used to service the answerbox. */ 45 struct thread *thread; 46 /** Kbox thread creation vs. begin of cleanup mutual exclusion. */ 47 mutex_t cleanup_lock; 48 /** True if cleanup of kbox has already started. */ 49 bool finished; 50 } kbox_t; 51 40 52 extern int ipc_connect_kbox(task_id_t); 41 53 extern void ipc_kbox_cleanup(void); -
kernel/generic/include/proc/task.h
r0aa1665 r31696b4f 54 54 #include <proc/scheduler.h> 55 55 #include <udebug/udebug.h> 56 #include <ipc/kbox.h> 56 57 57 58 #define TASK_NAME_BUFLEN 20 … … 99 100 100 101 #ifdef CONFIG_UDEBUG 101 /** Debugging stuff */102 /** Debugging stuff. */ 102 103 udebug_task_t udebug; 103 104 104 /** Kernel answerbox */ 105 answerbox_t kernel_box; 106 /** Thread used to service kernel answerbox */ 107 struct thread *kb_thread; 108 /** Kbox thread creation vs. begin of cleanup mutual exclusion */ 109 mutex_t kb_cleanup_lock; 110 /** True if cleanup of kbox has already started */ 111 bool kb_finished; 105 /** Kernel answerbox. */ 106 kbox_t kb; 112 107 #endif 113 108 114 109 /** Architecture specific task data. */ 115 110 task_arch_t arch; -
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; -
kernel/generic/src/proc/task.c
r0aa1665 r31696b4f 165 165 166 166 /* Init kbox stuff */ 167 ipc_answerbox_init(&ta->k ernel_box, ta);168 ta->kb _thread = NULL;169 mutex_initialize(&ta->kb _cleanup_lock, MUTEX_PASSIVE);170 ta->kb _finished = false;167 ipc_answerbox_init(&ta->kb.box, ta); 168 ta->kb.thread = NULL; 169 mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE); 170 ta->kb.finished = false; 171 171 #endif 172 172 -
kernel/generic/src/udebug/udebug_ipc.c
r0aa1665 r31696b4f 74 74 if (rc < 0) { 75 75 IPC_SET_RETVAL(call->data, rc); 76 ipc_answer(&TASK->k ernel_box, call);76 ipc_answer(&TASK->kb.box, call); 77 77 return; 78 78 } … … 84 84 if (rc != 0) { 85 85 IPC_SET_RETVAL(call->data, 0); 86 ipc_answer(&TASK->k ernel_box, call);86 ipc_answer(&TASK->kb.box, call); 87 87 } 88 88 } … … 100 100 101 101 IPC_SET_RETVAL(call->data, rc); 102 ipc_answer(&TASK->k ernel_box, call);102 ipc_answer(&TASK->kb.box, call); 103 103 } 104 104 … … 117 117 118 118 IPC_SET_RETVAL(call->data, rc); 119 ipc_answer(&TASK->k ernel_box, call);119 ipc_answer(&TASK->kb.box, call); 120 120 } 121 121 … … 136 136 if (rc < 0) { 137 137 IPC_SET_RETVAL(call->data, rc); 138 ipc_answer(&TASK->k ernel_box, call);138 ipc_answer(&TASK->kb.box, call); 139 139 return; 140 140 } … … 155 155 rc = udebug_stop(t, call); 156 156 IPC_SET_RETVAL(call->data, rc); 157 ipc_answer(&TASK->k ernel_box, call);157 ipc_answer(&TASK->kb.box, call); 158 158 } 159 159 … … 183 183 if (rc < 0) { 184 184 IPC_SET_RETVAL(call->data, rc); 185 ipc_answer(&TASK->k ernel_box, call);185 ipc_answer(&TASK->kb.box, call); 186 186 return; 187 187 } … … 210 210 call->buffer = buffer; 211 211 212 ipc_answer(&TASK->k ernel_box, call);212 ipc_answer(&TASK->kb.box, call); 213 213 } 214 214 … … 230 230 if (rc != EOK) { 231 231 IPC_SET_RETVAL(call->data, rc); 232 ipc_answer(&TASK->k ernel_box, call);232 ipc_answer(&TASK->kb.box, call); 233 233 return; 234 234 } … … 248 248 call->buffer = buffer; 249 249 250 ipc_answer(&TASK->k ernel_box, call);250 ipc_answer(&TASK->kb.box, call); 251 251 } 252 252 … … 271 271 if (rc < 0) { 272 272 IPC_SET_RETVAL(call->data, rc); 273 ipc_answer(&TASK->k ernel_box, call);273 ipc_answer(&TASK->kb.box, call); 274 274 return; 275 275 } … … 283 283 call->buffer = buffer; 284 284 285 ipc_answer(&TASK->k ernel_box, call);285 ipc_answer(&TASK->kb.box, call); 286 286 } 287 287 … … 307 307 if (TASK->udebug.debugger != call->sender) { 308 308 IPC_SET_RETVAL(call->data, EINVAL); 309 ipc_answer(&TASK->k ernel_box, call);309 ipc_answer(&TASK->kb.box, call); 310 310 return; 311 311 }
Note:
See TracChangeset
for help on using the changeset viewer.