Changes in uspace/srv/ns/task.c [1c635d6:feeac0d] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/ns/task.c

    r1c635d6 rfeeac0d  
    4040#include <macros.h>
    4141#include <malloc.h>
    42 #include <types/task.h>
    4342#include "task.h"
    4443#include "ns.h"
    4544
     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 */
    4652
    4753/** Task hash table item. */
     
    189195                }
    190196               
     197                hash_table_remove(&task_hash_table, &pr->id);
    191198                list_remove(&pr->link);
    192199                free(pr);
     
    197204void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid)
    198205{
     206        sysarg_t retval;
     207        task_exit_t texit;
     208        bool remove = false;
     209       
    199210        ht_link_t *link = hash_table_find(&task_hash_table, &id);
    200211        hashed_task_t *ht = (link != NULL) ?
     
    207218        }
    208219       
    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);
     220        if (!ht->finished) {
     221                /* Add to pending list */
     222                pending_wait_t *pr =
     223                    (pending_wait_t *) malloc(sizeof(pending_wait_t));
     224                if (!pr) {
     225                        retval = ENOMEM;
     226                        goto out;
     227                }
     228               
     229                link_initialize(&pr->link);
     230                pr->id = id;
     231                pr->callid = callid;
     232                list_append(&pr->link, &pending_wait);
    213233                return;
    214234        }
    215235       
    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);
     236        remove = true;
     237        retval = EOK;
     238       
     239out:
     240        if (!(callid & IPC_CALLID_NOTIFICATION)) {
     241                texit = ht->have_rval ? TASK_EXIT_NORMAL : TASK_EXIT_UNEXPECTED;
     242                ipc_answer_2(callid, retval, texit, ht->retval);
     243        }
     244        if (remove)
     245                hash_table_remove_item(&task_hash_table, link);
    229246}
    230247
     
    297314        ht->retval = IPC_GET_ARG1(*call);
    298315       
    299         process_pending_wait();
    300        
    301316        return EOK;
    302317}
     
    321336        ht->finished = true;
    322337       
    323         process_pending_wait();
    324         hash_table_remove(&task_hash_table, &id);
    325        
    326338        return EOK;
    327339}
Note: See TracChangeset for help on using the changeset viewer.