Changeset fe1776c2 in mainline for uspace/srv/ns/task.c


Ignore:
Timestamp:
2011-02-11T12:41:11Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d81ef61c
Parents:
78d1525 (diff), 5d4193c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge from usb/development

File:
1 edited

Legend:

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

    r78d1525 rfe1776c2  
    4343
    4444#define TASK_HASH_TABLE_CHAINS  256
    45 #define P2I_HASH_TABLE_CHAINS  256
    46 
    47 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id);
     45#define P2I_HASH_TABLE_CHAINS   256
    4846
    4947/* TODO:
     
    5755typedef struct {
    5856        link_t link;
    59         task_id_t id;   /**< Task ID. */
    60         bool finished;  /**< Task is done. */
    61         bool have_rval; /**< Task returned a value. */
    62         int retval;     /**< The return value. */
     57       
     58        task_id_t id;    /**< Task ID. */
     59        bool finished;   /**< Task is done. */
     60        bool have_rval;  /**< Task returned a value. */
     61        int retval;      /**< The return value. */
    6362} hashed_task_t;
    6463
     
    7170 *
    7271 */
    73 static hash_index_t task_hash(unsigned long *key)
     72static hash_index_t task_hash(unsigned long key[])
    7473{
    7574        assert(key);
    76         return (LOWER32(*key) % TASK_HASH_TABLE_CHAINS);
     75        return (LOWER32(key[0]) % TASK_HASH_TABLE_CHAINS);
    7776}
    7877
     
    124123typedef struct {
    125124        link_t link;
    126         sysarg_t phash;    /**< Task ID. */
    127         task_id_t id;    /**< Task ID. */
     125        sysarg_t in_phone_hash;  /**< Incoming phone hash. */
     126        task_id_t id;            /**< Task ID. */
    128127} p2i_entry_t;
    129128
     
    131130 *
    132131 * @param key Array of keys.
     132 *
    133133 * @return Hash index corresponding to key[0].
    134134 *
    135135 */
    136 static hash_index_t p2i_hash(unsigned long *key)
     136static hash_index_t p2i_hash(unsigned long key[])
    137137{
    138138        assert(key);
    139         return (*key % TASK_HASH_TABLE_CHAINS);
     139        return (key[0] % TASK_HASH_TABLE_CHAINS);
    140140}
    141141
     
    154154        assert(keys == 1);
    155155        assert(item);
    156 
    157         p2i_entry_t *e = hash_table_get_instance(item, p2i_entry_t, link);
    158 
    159         return (key[0] == e->phash);
     156       
     157        p2i_entry_t *entry = hash_table_get_instance(item, p2i_entry_t, link);
     158       
     159        return (key[0] == entry->in_phone_hash);
    160160}
    161161
     
    197197                return ENOMEM;
    198198        }
    199 
     199       
    200200        if (!hash_table_create(&phone_to_id, P2I_HASH_TABLE_CHAINS,
    201201            1, &p2i_ops)) {
     
    205205       
    206206        list_initialize(&pending_wait);
    207        
    208207        return EOK;
    209208}
     
    238237                            ht->retval);
    239238                }
    240 
     239               
    241240                hash_table_remove(&task_hash_table, keys, 2);
    242241                list_remove(cur);
     
    250249        sysarg_t retval;
    251250        task_exit_t texit;
    252 
     251       
    253252        unsigned long keys[2] = {
    254253                LOWER32(id),
    255254                UPPER32(id)
    256255        };
    257 
     256       
    258257        link_t *link = hash_table_find(&task_hash_table, keys);
    259258        hashed_task_t *ht = (link != NULL) ?
    260259            hash_table_get_instance(link, hashed_task_t, link) : NULL;
    261 
     260       
    262261        if (ht == NULL) {
    263262                /* No such task exists. */
     
    265264                return;
    266265        }
    267 
     266       
    268267        if (!ht->finished) {
    269268                /* Add to pending list */
     
    275274                }
    276275               
     276                link_initialize(&pr->link);
    277277                pr->id = id;
    278278                pr->callid = callid;
     
    293293int ns_task_id_intro(ipc_call_t *call)
    294294{
    295         task_id_t id;
    296295        unsigned long keys[2];
    297         link_t *link;
    298         p2i_entry_t *e;
    299         hashed_task_t *ht;
    300 
    301         id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
    302 
     296       
     297        task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
    303298        keys[0] = call->in_phone_hash;
    304 
    305         link = hash_table_find(&phone_to_id, keys);
     299       
     300        link_t *link = hash_table_find(&phone_to_id, keys);
    306301        if (link != NULL)
    307302                return EEXISTS;
    308 
    309         e = (p2i_entry_t *) malloc(sizeof(p2i_entry_t));
    310         if (e == NULL)
     303       
     304        p2i_entry_t *entry = (p2i_entry_t *) malloc(sizeof(p2i_entry_t));
     305        if (entry == NULL)
    311306                return ENOMEM;
    312 
    313         ht = (hashed_task_t *) malloc(sizeof(hashed_task_t));
     307       
     308        hashed_task_t *ht = (hashed_task_t *) malloc(sizeof(hashed_task_t));
    314309        if (ht == NULL)
    315310                return ENOMEM;
    316 
    317         /* Insert to phone-to-id map. */
    318 
    319         link_initialize(&e->link);
    320         e->phash = call->in_phone_hash;
    321         e->id = id;
    322         hash_table_insert(&phone_to_id, keys, &e->link);
    323 
    324         /* Insert to main table. */
    325 
     311       
     312        /*
     313         * Insert into the phone-to-id map.
     314         */
     315       
     316        link_initialize(&entry->link);
     317        entry->in_phone_hash = call->in_phone_hash;
     318        entry->id = id;
     319        hash_table_insert(&phone_to_id, keys, &entry->link);
     320       
     321        /*
     322         * Insert into the main table.
     323         */
     324       
    326325        keys[0] = LOWER32(id);
    327326        keys[1] = UPPER32(id);
    328 
     327       
    329328        link_initialize(&ht->link);
    330329        ht->id = id;
     
    333332        ht->retval = -1;
    334333        hash_table_insert(&task_hash_table, keys, &ht->link);
    335 
     334       
    336335        return EOK;
    337336}
    338337
     338static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id)
     339{
     340        unsigned long keys[1] = {phone_hash};
     341       
     342        link_t *link = hash_table_find(&phone_to_id, keys);
     343        if (link == NULL)
     344                return ENOENT;
     345       
     346        p2i_entry_t *entry = hash_table_get_instance(link, p2i_entry_t, link);
     347        *id = entry->id;
     348       
     349        return EOK;
     350}
     351
    339352int ns_task_retval(ipc_call_t *call)
    340353{
    341354        task_id_t id;
    342         unsigned long keys[2];
    343         int rc;
    344 
    345         rc = get_id_by_phone(call->in_phone_hash, &id);
     355        int rc = get_id_by_phone(call->in_phone_hash, &id);
    346356        if (rc != EOK)
    347357                return rc;
    348 
    349         keys[0] = LOWER32(id);
    350         keys[1] = UPPER32(id);
     358       
     359        unsigned long keys[2] = {
     360                LOWER32(id),
     361                UPPER32(id)
     362        };
    351363       
    352364        link_t *link = hash_table_find(&task_hash_table, keys);
     
    354366            hash_table_get_instance(link, hashed_task_t, link) : NULL;
    355367       
    356         if ((ht == NULL) || ht->finished)
     368        if ((ht == NULL) || (ht->finished))
    357369                return EINVAL;
    358 
     370       
    359371        ht->finished = true;
    360372        ht->have_rval = true;
    361373        ht->retval = IPC_GET_ARG1(*call);
    362 
     374       
    363375        return EOK;
    364376}
     
    367379{
    368380        unsigned long keys[2];
     381       
    369382        task_id_t id;
    370         int rc;
    371 
    372         rc = get_id_by_phone(call->in_phone_hash, &id);
     383        int rc = get_id_by_phone(call->in_phone_hash, &id);
    373384        if (rc != EOK)
    374385                return rc;
    375 
     386       
    376387        /* Delete from phone-to-id map. */
    377388        keys[0] = call->in_phone_hash;
    378389        hash_table_remove(&phone_to_id, keys, 1);
    379 
     390       
    380391        /* Mark task as finished. */
    381392        keys[0] = LOWER32(id);
    382393        keys[1] = UPPER32(id);
    383 
     394       
    384395        link_t *link = hash_table_find(&task_hash_table, keys);
    385396        hashed_task_t *ht =
     
    387398        if (ht == NULL)
    388399                return EOK;
    389 
     400       
    390401        ht->finished = true;
    391 
    392         return EOK;
    393 }
    394 
    395 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id)
    396 {
    397         unsigned long keys[1];
    398         link_t *link;
    399         p2i_entry_t *e;
    400 
    401         keys[0] = phone_hash;
    402         link = hash_table_find(&phone_to_id, keys);
    403         if (link == NULL)
    404                 return ENOENT;
    405 
    406         e = hash_table_get_instance(link, p2i_entry_t, link);
    407         *id = e->id;
    408 
     402       
    409403        return EOK;
    410404}
Note: See TracChangeset for help on using the changeset viewer.