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


Ignore:
File:
1 edited

Legend:

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

    r4e00f87 r1c635d6  
    3434#include <ipc/ipc.h>
    3535#include <adt/hash_table.h>
    36 #include <bool.h>
     36#include <stdbool.h>
    3737#include <errno.h>
    3838#include <assert.h>
     
    4040#include <macros.h>
    4141#include <malloc.h>
     42#include <types/task.h>
    4243#include "task.h"
    4344#include "ns.h"
    4445
    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  */
    5246
    5347/** Task hash table item. */
     
    179173       
    180174loop:
    181         list_foreach(pending_wait, cur) {
    182                 pending_wait_t *pr = list_get_instance(cur, pending_wait_t, link);
    183                
     175        list_foreach(pending_wait, link, pending_wait_t, pr) {
    184176                ht_link_t *link = hash_table_find(&task_hash_table, &pr->id);
    185177                if (!link)
     
    197189                }
    198190               
    199                 hash_table_remove(&task_hash_table, &pr->id);
    200                 list_remove(cur);
     191                list_remove(&pr->link);
    201192                free(pr);
    202193                goto loop;
     
    206197void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid)
    207198{
    208         sysarg_t retval;
    209         task_exit_t texit;
    210        
    211199        ht_link_t *link = hash_table_find(&task_hash_table, &id);
    212200        hashed_task_t *ht = (link != NULL) ?
     
    219207        }
    220208       
    221         if (!ht->finished) {
    222                 /* Add to pending list */
    223                 pending_wait_t *pr =
    224                     (pending_wait_t *) malloc(sizeof(pending_wait_t));
    225                 if (!pr) {
    226                         retval = ENOMEM;
    227                         goto out;
    228                 }
    229                
    230                 link_initialize(&pr->link);
    231                 pr->id = id;
    232                 pr->callid = callid;
    233                 list_append(&pr->link, &pending_wait);
     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);
    234213                return;
    235214        }
    236215       
    237         hash_table_remove_item(&task_hash_table, link);
    238         retval = EOK;
    239        
    240 out:
    241         if (!(callid & IPC_CALLID_NOTIFICATION)) {
    242                 texit = ht->have_rval ? TASK_EXIT_NORMAL : TASK_EXIT_UNEXPECTED;
    243                 ipc_answer_2(callid, retval, texit, ht->retval);
    244         }
     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);
    245229}
    246230
     
    313297        ht->retval = IPC_GET_ARG1(*call);
    314298       
     299        process_pending_wait();
     300       
    315301        return EOK;
    316302}
     
    335321        ht->finished = true;
    336322       
     323        process_pending_wait();
     324        hash_table_remove(&task_hash_table, &id);
     325       
    337326        return EOK;
    338327}
Note: See TracChangeset for help on using the changeset viewer.