Changeset 853802e in mainline


Ignore:
Timestamp:
2017-08-22T20:11:47Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
58e8646
Parents:
1d81eb6
Message:

Include task ID in connection hash table operations

The task ID must be included in the hash computation because a phone hash alone
might not be unique while the server is still tracking connections for killed
tasks due to kernel's recycling of phone structures.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/async.c

    r1d81eb6 r853802e  
    106106#include <fibril.h>
    107107#include <adt/hash_table.h>
     108#include <adt/hash.h>
    108109#include <adt/list.h>
    109110#include <assert.h>
     
    587588};
    588589
    589 /** Compute hash into the connection hash table based on the source phone hash.
    590  *
    591  * @param key Pointer to source phone hash.
     590typedef struct {
     591        task_id_t task_id;
     592        sysarg_t phone_hash;
     593} conn_key_t;
     594
     595/** Compute hash into the connection hash table
     596 *
     597 * The hash is based on the source task ID and the source phone hash. The task
     598 * ID is included in the hash because a phone hash alone might not be unique
     599 * while we still track connections for killed tasks due to kernel's recycling
     600 * of phone structures.
     601 *
     602 * @param key Pointer to the connection key structure.
    592603 *
    593604 * @return Index into the connection hash table.
     
    596607static size_t conn_key_hash(void *key)
    597608{
    598         sysarg_t in_phone_hash = *(sysarg_t *) key;
    599         return in_phone_hash;
     609        conn_key_t *ck = (conn_key_t *) key;
     610
     611        size_t hash = 0;
     612        hash = hash_combine(hash, LOWER32(ck->task_id));
     613        hash = hash_combine(hash, UPPER32(ck->task_id));
     614        hash = hash_combine(hash, ck->phone_hash);
     615        return hash;
    600616}
    601617
     
    603619{
    604620        connection_t *conn = hash_table_get_inst(item, connection_t, link);
    605         return conn_key_hash(&conn->in_phone_hash);
     621        return conn_key_hash(&(conn_key_t){
     622                .task_id = conn->in_task_id,
     623                .phone_hash = conn->in_phone_hash
     624        });
    606625}
    607626
    608627static bool conn_key_equal(void *key, const ht_link_t *item)
    609628{
    610         sysarg_t in_phone_hash = *(sysarg_t *) key;
     629        conn_key_t *ck = (conn_key_t *) key;
    611630        connection_t *conn = hash_table_get_inst(item, connection_t, link);
    612         return (in_phone_hash == conn->in_phone_hash);
     631        return ((ck->task_id == conn->in_task_id) &&
     632            (ck->phone_hash == conn->in_phone_hash));
    613633}
    614634
     
    716736         */
    717737        futex_down(&async_futex);
    718         hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash);
     738        hash_table_remove(&conn_hash_table, &(conn_key_t){
     739                .task_id = fibril_connection->in_task_id,
     740                .phone_hash = fibril_connection->in_phone_hash
     741        });
    719742        futex_up(&async_futex);
    720743       
     
    951974        futex_down(&async_futex);
    952975       
    953         ht_link_t *link = hash_table_find(&conn_hash_table, &call->in_phone_hash);
     976        ht_link_t *link = hash_table_find(&conn_hash_table, &(conn_key_t){
     977                .task_id = call->in_task_id,
     978                .phone_hash = call->in_phone_hash
     979        });
    954980        if (!link) {
    955981                futex_up(&async_futex);
Note: See TracChangeset for help on using the changeset viewer.