Changeset ca48672 in mainline for uspace/lib/c


Ignore:
Timestamp:
2025-06-20T15:18:27Z (4 weeks ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
cb20b05
Parents:
3951046
Message:

loc_service_register() needs to take a port ID argument.

Location:
uspace/lib/c
Files:
6 edited

Legend:

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

    r3951046 rca48672  
    197197}
    198198
     199static bool destroy_if(ht_link_t *link, void *arg)
     200{
     201        port_t *port = (port_t *)arg;
     202
     203        hash_table_remove_item(&port->interface_hash_table, link);
     204        return false;
     205}
     206
     207static void async_delete_port(port_t *port)
     208{
     209        /* Destroy interfaces */
     210        hash_table_apply(&port->interface_hash_table, destroy_if, NULL);
     211
     212        hash_table_destroy(&port->interface_hash_table);
     213        free(port);
     214}
     215
    199216errno_t async_create_port_internal(iface_t iface, async_port_handler_t handler,
    200217    void *data, port_id_t *port_id)
     
    212229        interface = async_new_interface(port, iface, handler, data);
    213230        if (interface == NULL) {
    214                 // XXX delete port
     231                async_delete_port(port);
    215232                fibril_rmutex_unlock(&port_mutex);
    216233                return ENOMEM;
     
    218235
    219236        *port_id = port->id;
     237        fibril_rmutex_unlock(&port_mutex);
     238        return EOK;
     239}
     240
     241errno_t async_port_create_interface(port_id_t port_id, iface_t iface,
     242    async_port_handler_t handler, void *data)
     243{
     244        ht_link_t *link;
     245        port_t *port;
     246        interface_t *interface;
     247
     248        fibril_rmutex_lock(&port_mutex);
     249        link = hash_table_find(&port_hash_table, &port_id);
     250        assert(link != NULL);
     251        port = hash_table_get_inst(link, port_t, link);
     252
     253        interface = async_new_interface(port, iface, handler, data);
     254        if (interface == NULL) {
     255                fibril_rmutex_unlock(&port_mutex);
     256                return ENOMEM;
     257        }
     258
    220259        fibril_rmutex_unlock(&port_mutex);
    221260        return EOK;
     
    306345}
    307346
     347void async_port_destroy(port_id_t port_id)
     348{
     349        ht_link_t *link;
     350        port_t *port;
     351
     352        fibril_rmutex_lock(&port_mutex);
     353        link = hash_table_find(&port_hash_table, &port_id);
     354        assert(link != NULL);
     355        port = hash_table_get_inst(link, port_t, link);
     356        async_delete_port(port);
     357        fibril_rmutex_unlock(&port_mutex);
     358}
     359
    308360/** Initialize the async framework ports.
    309361 *
  • uspace/lib/c/generic/loc.c

    r3951046 rca48672  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * Copyright (c) 2007 Josef Cejka
    44 * All rights reserved.
     
    258258 * @param srv Server object
    259259 * @param fqsn Fully qualified service name
     260 * @param portid ID of port providing the service
    260261 * @param sid  Service ID of new service
    261262 *
    262263 */
    263264errno_t loc_service_register(loc_srv_t *srv, const char *fqsn,
    264     service_id_t *sid)
     265    port_id_t portid, service_id_t *sid)
    265266{
    266267        async_exch_t *exch = async_exchange_begin(srv->sess);
    267268        ipc_call_t answer;
    268         aid_t req = async_send_0(exch, LOC_SERVICE_REGISTER, &answer);
     269        aid_t req = async_send_1(exch, LOC_SERVICE_REGISTER, portid, &answer);
    269270        errno_t retval = async_data_write_start(exch, fqsn, str_size(fqsn));
    270271
  • uspace/lib/c/generic/ns.c

    r3951046 rca48672  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2011 Martin Decky
    34 * All rights reserved.
     
    6869
    6970        if (rc != EOK) {
     71                async_port_destroy(port);
    7072                async_forget(req);
    7173                return rc;
     
    7476        errno_t retval;
    7577        async_wait_for(req, &retval);
     78
     79        if (rc != EOK)
     80                async_port_destroy(port);
    7681        return rc;
    7782}
  • uspace/lib/c/include/async.h

    r3951046 rca48672  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2006 Ondrej Palkovsky
    34 * All rights reserved.
     
    99100} exch_mgmt_t;
    100101
     102enum {
     103        fallback_port_id = 0
     104};
     105
    101106/** Forward declarations */
    102107struct async_exch;
     
    134139extern errno_t async_create_port(iface_t, async_port_handler_t, void *,
    135140    port_id_t *);
     141extern void async_port_destroy(port_id_t);
     142extern errno_t async_port_create_interface(port_id_t, iface_t,
     143    async_port_handler_t, void *);
    136144extern void async_set_fallback_port_handler(async_port_handler_t, void *);
    137145extern errno_t async_create_callback_port(async_exch_t *, iface_t, sysarg_t,
  • uspace/lib/c/include/loc.h

    r3951046 rca48672  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4949extern errno_t loc_server_register(const char *, loc_srv_t **);
    5050extern void loc_server_unregister(loc_srv_t *);
    51 extern errno_t loc_service_register(loc_srv_t *, const char *, service_id_t *);
     51extern errno_t loc_service_register(loc_srv_t *, const char *, port_id_t,
     52    service_id_t *);
    5253extern errno_t loc_service_unregister(loc_srv_t *, service_id_t);
    5354extern errno_t loc_service_add_to_cat(loc_srv_t *, service_id_t, category_id_t);
  • uspace/lib/c/test/loc.c

    r3951046 rca48672  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5151
    5252        // XXX Without a unique name this is not reentrant
    53         rc = loc_service_register(sa, "test/libc-service-a", &svca);
     53        rc = loc_service_register(sa, "test/libc-service-a",
     54            fallback_port_id, &svca);
    5455        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    5556
    5657        // XXX Without a unique name this is not reentrant
    57         rc = loc_service_register(sb, "test/libc-service-b", &svcb);
     58        rc = loc_service_register(sb, "test/libc-service-b",
     59            fallback_port_id, &svcb);
    5860        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    5961
Note: See TracChangeset for help on using the changeset viewer.