Changeset 5c76cc61 in mainline


Ignore:
Timestamp:
2018-06-19T19:46:03Z (6 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3bd1d7d4
Parents:
9f272d9
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-05-31 16:37:35)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-06-19 19:46:03)
Message:

async: Lock interface hash table with a dedicated interface_futex, and remove redundant per-interface futexes.

File:
1 edited

Legend:

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

    r9f272d9 r5c76cc61  
    6060        iface_t iface;
    6161
    62         /** Futex protecting the hash table */
    63         futex_t futex;
    64 
    6562        /** Interface ports */
    6663        hash_table_t port_hash_table;
     
    104101static void *fallback_port_data = NULL;
    105102
     103/** Futex guarding the interface hash table. */
     104static futex_t interface_futex = FUTEX_INITIALIZER;
    106105static hash_table_t interface_hash_table;
    107106
     
    177176
    178177        interface->iface = iface;
    179         futex_initialize(&interface->futex, 1);
    180178        interface->port_id_avail = 0;
    181179
     
    188186    async_port_handler_t handler, void *data)
    189187{
     188        // TODO: Move the malloc out of critical section.
    190189        port_t *port = (port_t *) malloc(sizeof(port_t));
    191190        if (!port)
    192191                return NULL;
    193192
    194         futex_down(&interface->futex);
    195 
    196193        port_id_t id = interface->port_id_avail;
    197194        interface->port_id_avail++;
     
    203200        hash_table_insert(&interface->port_hash_table, &port->link);
    204201
    205         futex_up(&interface->futex);
    206 
    207202        return port;
    208203}
     
    213208        interface_t *interface;
    214209
    215         futex_down(&async_futex);
     210        futex_lock(&interface_futex);
    216211
    217212        ht_link_t *link = hash_table_find(&interface_hash_table, &iface);
     
    222217
    223218        if (!interface) {
    224                 futex_up(&async_futex);
     219                futex_unlock(&interface_futex);
    225220                return ENOMEM;
    226221        }
     
    228223        port_t *port = async_new_port(interface, handler, data);
    229224        if (!port) {
    230                 futex_up(&async_futex);
     225                futex_unlock(&interface_futex);
    231226                return ENOMEM;
    232227        }
     
    234229        *port_id = port->id;
    235230
    236         futex_up(&async_futex);
     231        futex_unlock(&interface_futex);
    237232
    238233        return EOK;
     
    260255        port_t *port = NULL;
    261256
    262         futex_down(&async_futex);
     257        futex_lock(&interface_futex);
    263258
    264259        ht_link_t *link = hash_table_find(&interface_hash_table, &iface);
     
    272267        }
    273268
    274         futex_up(&async_futex);
     269        futex_unlock(&interface_futex);
    275270
    276271        return port;
Note: See TracChangeset for help on using the changeset viewer.