Changes in kernel/generic/src/ipc/kbox.c [07d4271:fafb8e5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ipc/kbox.c
r07d4271 rfafb8e5 90 90 LOG("Join kb.thread."); 91 91 thread_join(TASK->kb.thread); 92 thread_detach(TASK->kb.thread); 92 93 LOG("...join done."); 93 94 TASK->kb.thread = NULL; … … 135 136 /* Only detach kbox thread unless already terminating. */ 136 137 if (TASK->kb.finished == false) { 137 /* Releasekbox thread so it gets freed from memory. */138 thread_ put(TASK->kb.thread);138 /* Detach kbox thread so it gets freed from memory. */ 139 thread_detach(TASK->kb.thread); 139 140 TASK->kb.thread = NULL; 140 141 } … … 200 201 /** Connect phone to a task kernel-box specified by id. 201 202 * 203 * Note that this is not completely atomic. For optimisation reasons, the task 204 * might start cleaning up kbox after the phone has been connected and before 205 * a kbox thread has been created. This must be taken into account in the 206 * cleanup code. 207 * 202 208 * @param[out] out_phone Phone capability handle on success. 203 209 * @return Error code. … … 206 212 errno_t ipc_connect_kbox(task_id_t taskid, cap_phone_handle_t *out_phone) 207 213 { 214 irq_spinlock_lock(&tasks_lock, true); 215 208 216 task_t *task = task_find_by_id(taskid); 209 if (!task) 217 if (task == NULL) { 218 irq_spinlock_unlock(&tasks_lock, true); 210 219 return ENOENT; 220 } 221 222 atomic_inc(&task->refcount); 223 224 irq_spinlock_unlock(&tasks_lock, true); 211 225 212 226 mutex_lock(&task->kb.cleanup_lock); 227 228 if (atomic_predec(&task->refcount) == 0) { 229 mutex_unlock(&task->kb.cleanup_lock); 230 task_destroy(task); 231 return ENOENT; 232 } 213 233 214 234 if (task->kb.finished) { 215 235 mutex_unlock(&task->kb.cleanup_lock); 216 task_release(task);217 236 return EINVAL; 218 237 } … … 225 244 if (!kb_thread) { 226 245 mutex_unlock(&task->kb.cleanup_lock); 227 task_release(task);228 246 return ENOMEM; 229 247 } 230 248 231 249 task->kb.thread = kb_thread; 232 thread_ start(kb_thread);250 thread_ready(kb_thread); 233 251 } 234 252 … … 238 256 if (rc != EOK) { 239 257 mutex_unlock(&task->kb.cleanup_lock); 240 task_release(task);241 258 return rc; 242 259 } … … 249 266 250 267 mutex_unlock(&task->kb.cleanup_lock); 251 task_release(task);252 268 *out_phone = phone_handle; 253 269 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.