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


Ignore:
File:
1 edited

Legend:

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

    r166a1f57 r234f47e  
    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         bool remove = false;
    211        
    212199        ht_link_t *link = hash_table_find(&task_hash_table, &id);
    213200        hashed_task_t *ht = (link != NULL) ?
     
    220207        }
    221208       
    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);
     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);
    235213                return;
    236214        }
    237215       
    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);
     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);
    248229}
    249230
    250231int ns_task_id_intro(ipc_call_t *call)
    251232{
    252        
    253233        task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
    254 
     234       
    255235        ht_link_t *link = hash_table_find(&phone_to_id, &call->in_phone_hash);
    256236        if (link != NULL)
    257                 return EEXISTS;
     237                return EEXIST;
    258238       
    259239        p2i_entry_t *entry = (p2i_entry_t *) malloc(sizeof(p2i_entry_t));
     
    262242       
    263243        hashed_task_t *ht = (hashed_task_t *) malloc(sizeof(hashed_task_t));
    264         if (ht == NULL)
     244        if (ht == NULL) {
     245                free(entry);
    265246                return ENOMEM;
     247        }
    266248       
    267249        /*
     
    316298        ht->retval = IPC_GET_ARG1(*call);
    317299       
     300        process_pending_wait();
     301       
    318302        return EOK;
    319303}
     
    338322        ht->finished = true;
    339323       
     324        process_pending_wait();
     325        hash_table_remove(&task_hash_table, &id);
     326       
    340327        return EOK;
    341328}
Note: See TracChangeset for help on using the changeset viewer.