Changes in uspace/srv/ns/task.c [234f47e:166a1f57] in mainline


Ignore:
File:
1 edited

Legend:

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

    r234f47e r166a1f57  
    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. */
     
    173179       
    174180loop:
    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               
    176184                ht_link_t *link = hash_table_find(&task_hash_table, &pr->id);
    177185                if (!link)
     
    189197                }
    190198               
    191                 list_remove(&pr->link);
     199                hash_table_remove(&task_hash_table, &pr->id);
     200                list_remove(cur);
    192201                free(pr);
    193202                goto loop;
     
    197206void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid)
    198207{
     208        sysarg_t retval;
     209        task_exit_t texit;
     210        bool remove = false;
     211       
    199212        ht_link_t *link = hash_table_find(&task_hash_table, &id);
    200213        hashed_task_t *ht = (link != NULL) ?
     
    207220        }
    208221       
    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);
    213235                return;
    214236        }
    215237       
    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       
     241out:
     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);
    229248}
    230249
    231250int ns_task_id_intro(ipc_call_t *call)
    232251{
     252       
    233253        task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
    234        
     254
    235255        ht_link_t *link = hash_table_find(&phone_to_id, &call->in_phone_hash);
    236256        if (link != NULL)
    237                 return EEXIST;
     257                return EEXISTS;
    238258       
    239259        p2i_entry_t *entry = (p2i_entry_t *) malloc(sizeof(p2i_entry_t));
     
    242262       
    243263        hashed_task_t *ht = (hashed_task_t *) malloc(sizeof(hashed_task_t));
    244         if (ht == NULL) {
    245                 free(entry);
     264        if (ht == NULL)
    246265                return ENOMEM;
    247         }
    248266       
    249267        /*
     
    298316        ht->retval = IPC_GET_ARG1(*call);
    299317       
    300         process_pending_wait();
    301        
    302318        return EOK;
    303319}
     
    322338        ht->finished = true;
    323339       
    324         process_pending_wait();
    325         hash_table_remove(&task_hash_table, &id);
    326        
    327340        return EOK;
    328341}
Note: See TracChangeset for help on using the changeset viewer.