Changes in uspace/srv/ns/task.c [234f47e:166a1f57] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/ns/task.c
r234f47e r166a1f57 40 40 #include <macros.h> 41 41 #include <malloc.h> 42 #include <types/task.h>43 42 #include "task.h" 44 43 #include "ns.h" 45 44 45 46 /* TODO: 47 * 48 * As there is currently no convention that each task has to be waited 49 * for, the NS can leak memory because of the zombie tasks. 50 * 51 */ 46 52 47 53 /** Task hash table item. */ … … 173 179 174 180 loop: 175 list_foreach(pending_wait, link, pending_wait_t, pr) { 181 list_foreach(pending_wait, cur) { 182 pending_wait_t *pr = list_get_instance(cur, pending_wait_t, link); 183 176 184 ht_link_t *link = hash_table_find(&task_hash_table, &pr->id); 177 185 if (!link) … … 189 197 } 190 198 191 list_remove(&pr->link); 199 hash_table_remove(&task_hash_table, &pr->id); 200 list_remove(cur); 192 201 free(pr); 193 202 goto loop; … … 197 206 void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid) 198 207 { 208 sysarg_t retval; 209 task_exit_t texit; 210 bool remove = false; 211 199 212 ht_link_t *link = hash_table_find(&task_hash_table, &id); 200 213 hashed_task_t *ht = (link != NULL) ? … … 207 220 } 208 221 209 if (ht->finished) { 210 task_exit_t texit = ht->have_rval ? TASK_EXIT_NORMAL : 211 TASK_EXIT_UNEXPECTED; 212 ipc_answer_2(callid, EOK, texit, ht->retval); 222 if (!ht->finished) { 223 /* Add to pending list */ 224 pending_wait_t *pr = 225 (pending_wait_t *) malloc(sizeof(pending_wait_t)); 226 if (!pr) { 227 retval = ENOMEM; 228 goto out; 229 } 230 231 link_initialize(&pr->link); 232 pr->id = id; 233 pr->callid = callid; 234 list_append(&pr->link, &pending_wait); 213 235 return; 214 236 } 215 237 216 /* Add to pending list */ 217 pending_wait_t *pr = 218 (pending_wait_t *) malloc(sizeof(pending_wait_t)); 219 if (!pr) { 220 if (!(callid & IPC_CALLID_NOTIFICATION)) 221 ipc_answer_0(callid, ENOMEM); 222 return; 223 } 224 225 link_initialize(&pr->link); 226 pr->id = id; 227 pr->callid = callid; 228 list_append(&pr->link, &pending_wait); 238 remove = true; 239 retval = EOK; 240 241 out: 242 if (!(callid & IPC_CALLID_NOTIFICATION)) { 243 texit = ht->have_rval ? TASK_EXIT_NORMAL : TASK_EXIT_UNEXPECTED; 244 ipc_answer_2(callid, retval, texit, ht->retval); 245 } 246 if (remove) 247 hash_table_remove_item(&task_hash_table, link); 229 248 } 230 249 231 250 int ns_task_id_intro(ipc_call_t *call) 232 251 { 252 233 253 task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); 234 254 235 255 ht_link_t *link = hash_table_find(&phone_to_id, &call->in_phone_hash); 236 256 if (link != NULL) 237 return EEXIST ;257 return EEXISTS; 238 258 239 259 p2i_entry_t *entry = (p2i_entry_t *) malloc(sizeof(p2i_entry_t)); … … 242 262 243 263 hashed_task_t *ht = (hashed_task_t *) malloc(sizeof(hashed_task_t)); 244 if (ht == NULL) { 245 free(entry); 264 if (ht == NULL) 246 265 return ENOMEM; 247 }248 266 249 267 /* … … 298 316 ht->retval = IPC_GET_ARG1(*call); 299 317 300 process_pending_wait();301 302 318 return EOK; 303 319 } … … 322 338 ht->finished = true; 323 339 324 process_pending_wait();325 hash_table_remove(&task_hash_table, &id);326 327 340 return EOK; 328 341 }
Note:
See TracChangeset
for help on using the changeset viewer.