Changeset 007e6efa in mainline


Ignore:
Timestamp:
2011-01-28T15:44:39Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4db1fbf
Parents:
ae0300b5
Message:
  • libc routines for registering services and connecting to services via NS
  • async_connect_to_me()
Location:
uspace
Files:
1 added
29 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/klog/klog.c

    rae0300b5 r007e6efa  
    3737#include <stdio.h>
    3838#include <ipc/ipc.h>
     39#include <ipc/ns.h>
    3940#include <async.h>
    4041#include <ipc/services.h>
     
    7980int main(int argc, char *argv[])
    8081{
    81         size_t klog_pages;
    82         if (sysinfo_get_value("klog.pages", &klog_pages) != EOK) {
    83                 printf("%s: Error getting klog address\n", NAME);
    84                 return -1;
    85         }
    86        
    87         size_t klog_size = klog_pages * PAGE_SIZE;
    88         klog_length = klog_size / sizeof(wchar_t);
    89        
    90         klog = (wchar_t *) as_get_mappable_page(klog_size);
     82        klog = service_klog_share_in(&klog_length);
    9183        if (klog == NULL) {
    92                 printf("%s: Error allocating memory area\n", NAME);
    93                 return -1;
    94         }
    95        
    96         int res = async_share_in_start_1_0(PHONE_NS, (void *) klog,
    97             klog_size, SERVICE_MEM_KLOG);
    98         if (res != EOK) {
    99                 printf("%s: Error initializing memory area\n", NAME);
     84                printf("%s: Error accessing to klog\n", NAME);
    10085                return -1;
    10186        }
     
    10994         * Mode "a" would be definitively much better here, but it is
    11095         * not well supported by the FAT driver.
    111          *
    11296         */
    11397        log = fopen(LOG_FNAME, "w");
  • uspace/lib/c/Makefile

    rae0300b5 r007e6efa  
    8383        generic/io/console.c \
    8484        generic/io/screenbuffer.c \
     85        generic/ipc/ns.c \
    8586        generic/malloc.c \
    8687        generic/sysinfo.c \
  • uspace/lib/c/generic/async.c

    rae0300b5 r007e6efa  
    5858 *   int fibril1(void *arg)
    5959 *   {
    60  *     conn = ipc_connect_me_to();
     60 *     conn = async_connect_me_to();
    6161 *     c1 = async_send(conn);
    6262 *     c2 = async_send(conn);
     
    12351235}
    12361236
     1237/** Wrapper for making IPC_M_CONNECT_TO_ME calls using the async framework.
     1238 *
     1239 * Ask through phone for a new connection to some service.
     1240 *
     1241 * @param phone           Phone handle used for contacting the other side.
     1242 * @param arg1            User defined argument.
     1243 * @param arg2            User defined argument.
     1244 * @param arg3            User defined argument.
     1245 * @param client_receiver Connection handing routine.
     1246 *
     1247 * @return New phone handle on success or a negative error code.
     1248 *
     1249 */
     1250int async_connect_to_me(int phone, sysarg_t arg1, sysarg_t arg2,
     1251    sysarg_t arg3, async_client_conn_t client_receiver)
     1252{
     1253        sysarg_t task_hash;
     1254        sysarg_t phone_hash;
     1255        int rc = async_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
     1256            NULL, NULL, NULL, &task_hash, &phone_hash);
     1257        if (rc != EOK)
     1258                return rc;
     1259       
     1260        if (client_receiver != NULL)
     1261                async_new_connection(task_hash, phone_hash, 0, NULL,
     1262                    client_receiver);
     1263       
     1264        return EOK;
     1265}
     1266
    12371267/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
    1238  * 
     1268 *
    12391269 * Ask through phone for a new connection to some service.
    12401270 *
    1241  * @param phoneid       Phone handle used for contacting the other side.
    1242  * @param arg1          User defined argument.
    1243  * @param arg2          User defined argument.
    1244  * @param arg3          User defined argument.
    1245  *
    1246  * @return              New phone handle on success or a negative error code.
    1247  */
    1248 int
    1249 async_connect_me_to(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3)
    1250 {
    1251         int rc;
     1271 * @param phone Phone handle used for contacting the other side.
     1272 * @param arg1  User defined argument.
     1273 * @param arg2  User defined argument.
     1274 * @param arg3  User defined argument.
     1275 *
     1276 * @return New phone handle on success or a negative error code.
     1277 *
     1278 */
     1279int async_connect_me_to(int phone, sysarg_t arg1, sysarg_t arg2,
     1280    sysarg_t arg3)
     1281{
    12521282        sysarg_t newphid;
    1253 
    1254         rc = async_req_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, NULL,
    1255             NULL, NULL, NULL, &newphid);
    1256        
    1257         if (rc != EOK) 
     1283        int rc = async_req_3_5(phone, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     1284            NULL, NULL, NULL, NULL, &newphid);
     1285       
     1286        if (rc != EOK)
    12581287                return rc;
    1259 
     1288       
    12601289        return newphid;
    12611290}
    12621291
    12631292/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
    1264  * 
     1293 *
    12651294 * Ask through phone for a new connection to some service and block until
    12661295 * success.
    12671296 *
    1268  * @param phoneid       Phone handle used for contacting the other side.
    1269  * @param arg1          User defined argument.
    1270  * @param arg2          User defined argument.
    1271  * @param arg3          User defined argument.
    1272  *
    1273  * @return              New phone handle on success or a negative error code.
    1274  */
    1275 int
    1276 async_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,
     1297 * @param phoneid Phone handle used for contacting the other side.
     1298 * @param arg1    User defined argument.
     1299 * @param arg2    User defined argument.
     1300 * @param arg3    User defined argument.
     1301 *
     1302 * @return New phone handle on success or a negative error code.
     1303 *
     1304 */
     1305int async_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,
    12771306    sysarg_t arg3)
    12781307{
    1279         int rc;
    12801308        sysarg_t newphid;
    1281 
    1282         rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     1309        int rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
    12831310            IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
    12841311       
    1285         if (rc != EOK) 
     1312        if (rc != EOK)
    12861313                return rc;
    1287 
     1314       
    12881315        return newphid;
    12891316}
  • uspace/lib/c/generic/clipboard.c

    rae0300b5 r007e6efa  
    3939
    4040#include <clipboard.h>
     41#include <ipc/ns.h>
    4142#include <ipc/services.h>
    4243#include <ipc/clipboard.h>
     
    5455{
    5556        while (clip_phone < 0)
    56                 clip_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_CLIPBOARD, 0, 0);
     57                clip_phone = service_connect_blocking(SERVICE_CLIPBOARD, 0, 0);
    5758}
    5859
  • uspace/lib/c/generic/devmap.c

    rae0300b5 r007e6efa  
    3131#include <ipc/ipc.h>
    3232#include <ipc/services.h>
     33#include <ipc/ns.h>
    3334#include <ipc/devmap.h>
    3435#include <devmap.h>
     
    5051               
    5152                if (flags & IPC_FLAG_BLOCKING)
    52                         devmap_phone_driver = ipc_connect_me_to_blocking(PHONE_NS,
    53                             SERVICE_DEVMAP, DEVMAP_DRIVER, 0);
     53                        devmap_phone_driver = service_connect_blocking(SERVICE_DEVMAP,
     54                            DEVMAP_DRIVER, 0);
    5455                else
    55                         devmap_phone_driver = ipc_connect_me_to(PHONE_NS,
    56                             SERVICE_DEVMAP, DEVMAP_DRIVER, 0);
     56                        devmap_phone_driver = service_connect(SERVICE_DEVMAP,
     57                            DEVMAP_DRIVER, 0);
    5758               
    5859                return devmap_phone_driver;
     
    6263               
    6364                if (flags & IPC_FLAG_BLOCKING)
    64                         devmap_phone_client = ipc_connect_me_to_blocking(PHONE_NS,
    65                             SERVICE_DEVMAP, DEVMAP_CLIENT, 0);
     65                        devmap_phone_client = service_connect_blocking(SERVICE_DEVMAP,
     66                            DEVMAP_CLIENT, 0);
    6667                else
    67                         devmap_phone_client = ipc_connect_me_to(PHONE_NS,
    68                             SERVICE_DEVMAP, DEVMAP_CLIENT, 0);
     68                        devmap_phone_client = service_connect(SERVICE_DEVMAP,
     69                            DEVMAP_CLIENT, 0);
    6970               
    7071                return devmap_phone_client;
  • uspace/lib/c/generic/loader.c

    rae0300b5 r007e6efa  
    3636#include <ipc/loader.h>
    3737#include <ipc/services.h>
     38#include <ipc/ns.h>
    3839#include <libc.h>
    3940#include <task.h>
     
    6364loader_t *loader_connect(void)
    6465{
    65         int phone_id = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_LOAD, 0, 0);
     66        int phone_id = service_connect_blocking(SERVICE_LOAD, 0, 0);
    6667        if (phone_id < 0)
    6768                return NULL;
  • uspace/lib/c/generic/vfs/vfs.c

    rae0300b5 r007e6efa  
    4545#include <ipc/ipc.h>
    4646#include <ipc/services.h>
     47#include <ipc/ns.h>
    4748#include <async.h>
    4849#include <fibril_synch.h>
     
    118119static void vfs_connect(void)
    119120{
    120         while (vfs_phone < 0) {
    121                 vfs_phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_VFS,
    122                     0, 0);
    123         }
     121        while (vfs_phone < 0)
     122                vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
    124123       
    125124        async_session_create(&vfs_session, vfs_phone, 0);
  • uspace/lib/c/include/async.h

    rae0300b5 r007e6efa  
    266266}
    267267
     268extern int async_connect_to_me(int, sysarg_t, sysarg_t, sysarg_t,
     269    async_client_conn_t);
    268270extern int async_connect_me_to(int, sysarg_t, sysarg_t, sysarg_t);
    269271extern int async_connect_me_to_blocking(int, sysarg_t, sysarg_t, sysarg_t);
  • uspace/lib/c/include/ipc/ns.h

    rae0300b5 r007e6efa  
    3636#define LIBIPC_NS_H_
    3737
     38#include <sys/types.h>
    3839#include <ipc/ipc.h>
    3940
     
    4546} ns_request_t;
    4647
     48extern int service_register(sysarg_t);
     49extern int service_connect(sysarg_t, sysarg_t, sysarg_t);
     50extern int service_connect_blocking(sysarg_t, sysarg_t, sysarg_t);
     51
     52extern wchar_t *service_klog_share_in(size_t *);
     53
    4754#endif
    4855
  • uspace/srv/clip/clip.c

    rae0300b5 r007e6efa  
    2929#include <stdio.h>
    3030#include <bool.h>
     31#include <async.h>
    3132#include <ipc/ipc.h>
    32 #include <async.h>
     33#include <ipc/ns.h>
    3334#include <ipc/services.h>
    3435#include <ipc/clipboard.h>
     
    183184        async_set_client_connection(clip_connection);
    184185       
    185         if (ipc_connect_to_me(PHONE_NS, SERVICE_CLIPBOARD, 0, 0, NULL, NULL))
     186        if (service_register(SERVICE_CLIPBOARD) != EOK)
    186187                return -1;
    187188       
  • uspace/srv/devman/main.c

    rae0300b5 r007e6efa  
    586586
    587587        /* Register device manager at naming service. */
    588         if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, NULL, NULL) != 0)
     588        if (service_register(SERVICE_DEVMAN) != EOK)
    589589                return -1;
    590590
  • uspace/srv/devmap/devmap.c

    rae0300b5 r007e6efa  
    11501150       
    11511151        /* Register device mapper at naming service */
    1152         if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAP, 0, 0, NULL, NULL) != 0)
     1152        if (service_register(SERVICE_DEVMAP) != EOK)
    11531153                return -1;
    11541154       
  • uspace/srv/fs/devfs/devfs.c

    rae0300b5 r007e6efa  
    4242#include <ipc/ipc.h>
    4343#include <ipc/services.h>
     44#include <ipc/ns.h>
    4445#include <async.h>
    4546#include <errno.h>
     
    126127        }
    127128       
    128         int vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
     129        int vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
    129130        if (vfs_phone < EOK) {
    130131                printf(NAME ": Unable to connect to VFS\n");
  • uspace/srv/fs/fat/fat.c

    rae0300b5 r007e6efa  
    4040#include <ipc/ipc.h>
    4141#include <ipc/services.h>
     42#include <ipc/ns.h>
    4243#include <async.h>
    4344#include <errno.h>
     
    153154                goto err;
    154155
    155         vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
     156        vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
    156157        if (vfs_phone < EOK) {
    157158                printf(NAME ": failed to connect to VFS\n");
  • uspace/srv/fs/tmpfs/tmpfs.c

    rae0300b5 r007e6efa  
    4444#include <ipc/ipc.h>
    4545#include <ipc/services.h>
     46#include <ipc/ns.h>
    4647#include <async.h>
    4748#include <errno.h>
     
    157158        }
    158159
    159         int vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
     160        int vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
    160161        if (vfs_phone < EOK) {
    161162                printf(NAME ": Unable to connect to VFS\n");
  • uspace/srv/hid/console/console.c

    rae0300b5 r007e6efa  
    4040#include <ipc/fb.h>
    4141#include <ipc/services.h>
     42#include <ipc/ns.h>
    4243#include <errno.h>
    4344#include <ipc/console.h>
     
    762763       
    763764        /* Connect to framebuffer driver */
    764         fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
     765        fb_info.phone = service_connect_blocking(SERVICE_VIDEO, 0, 0);
    765766        if (fb_info.phone < 0) {
    766767                printf(NAME ": Failed to connect to video service\n");
     
    838839       
    839840        /* Receive kernel notifications */
     841        async_set_interrupt_received(interrupt_received);
    840842        if (event_subscribe(EVENT_KCONSOLE, 0) != EOK)
    841843                printf(NAME ": Error registering kconsole notifications\n");
    842        
    843         async_set_interrupt_received(interrupt_received);
    844844       
    845845        return true;
  • uspace/srv/hid/fb/main.c

    rae0300b5 r007e6efa  
    2929#include <ipc/ipc.h>
    3030#include <ipc/services.h>
     31#include <ipc/ns.h>
    3132#include <sysinfo.h>
    3233#include <async.h>
     
    114115                return -1;
    115116       
    116         if (ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, 0, NULL, NULL) != 0)
     117        if (service_register(SERVICE_VIDEO) != EOK)
    117118                return -1;
    118119       
  • uspace/srv/hid/kbd/generic/kbd.c

    rae0300b5 r007e6efa  
    223223       
    224224        if (cir_service) {
    225                 while (cir_phone < 0) {
    226                         cir_phone = ipc_connect_me_to_blocking(PHONE_NS, cir_service,
    227                             0, 0);
    228                 }
     225                while (cir_phone < 0)
     226                        cir_phone = service_connect_blocking(cir_service, 0, 0);
    229227        }
    230228       
  • uspace/srv/hw/irc/apic/apic.c

    rae0300b5 r007e6efa  
    108108       
    109109        async_set_client_connection(apic_connection);
    110         ipc_connect_to_me(PHONE_NS, SERVICE_APIC, 0, 0, NULL, NULL);
     110        service_register(SERVICE_APIC);
    111111       
    112112        return true;
  • uspace/srv/hw/irc/fhc/fhc.c

    rae0300b5 r007e6efa  
    137137       
    138138        async_set_client_connection(fhc_connection);
    139         ipc_connect_to_me(PHONE_NS, SERVICE_FHC, 0, 0, NULL, NULL);
     139        service_register(SERVICE_FHC);
    140140       
    141141        return true;
  • uspace/srv/hw/irc/i8259/i8259.c

    rae0300b5 r007e6efa  
    150150       
    151151        async_set_client_connection(i8259_connection);
    152         ipc_connect_to_me(PHONE_NS, SERVICE_I8259, 0, 0, NULL, NULL);
     152        service_register(SERVICE_I8259);
    153153       
    154154        return true;
  • uspace/srv/hw/irc/obio/obio.c

    rae0300b5 r007e6efa  
    138138       
    139139        async_set_client_connection(obio_connection);
    140         ipc_connect_to_me(PHONE_NS, SERVICE_OBIO, 0, 0, NULL, NULL);
     140        service_register(SERVICE_OBIO);
    141141       
    142142        return true;
  • uspace/srv/hw/netif/ne2000/ne2000.c

    rae0300b5 r007e6efa  
    4545#include <ipc/ipc.h>
    4646#include <ipc/services.h>
     47#include <ipc/ns.h>
    4748#include <ipc/irc.h>
    4849#include <net/modules.h>
     
    389390       
    390391        if (irc_service) {
    391                 while (irc_phone < 0) {
    392                         irc_phone = ipc_connect_me_to_blocking(PHONE_NS, irc_service,
    393                             0, 0);
    394                 }
     392                while (irc_phone < 0)
     393                        irc_phone = service_connect_blocking(irc_service, 0, 0);
    395394        }
    396395       
  • uspace/srv/loader/main.c

    rae0300b5 r007e6efa  
    9595
    9696/** Used to limit number of connections to one. */
    97 static bool connected;
     97static bool connected = false;
    9898
    9999static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request)
     
    423423int main(int argc, char *argv[])
    424424{
    425         task_id_t id;
    426         int rc;
    427 
    428         connected = false;
    429 
     425        /* Set a handler of incomming connections. */
     426        async_set_client_connection(ldr_connection);
     427       
    430428        /* Introduce this task to the NS (give it our task ID). */
    431         id = task_get_id();
    432         rc = async_req_2_0(PHONE_NS, NS_ID_INTRO, LOWER32(id), UPPER32(id));
     429        task_id_t id = task_get_id();
     430        int rc = async_req_2_0(PHONE_NS, NS_ID_INTRO, LOWER32(id), UPPER32(id));
    433431        if (rc != EOK)
    434432                return -1;
    435 
    436         /* Set a handler of incomming connections. */
    437         async_set_client_connection(ldr_connection);
    438433       
    439434        /* Register at naming service. */
    440         if (ipc_connect_to_me(PHONE_NS, SERVICE_LOAD, 0, 0, NULL, NULL) != 0)
     435        if (service_register(SERVICE_LOAD) != EOK)
    441436                return -2;
    442 
     437       
    443438        async_manager();
    444439       
  • uspace/srv/ns/clonable.c

    rae0300b5 r007e6efa  
    9292       
    9393        ipc_forward_fast(csr->callid, phone, IPC_GET_ARG2(csr->call),
    94                 IPC_GET_ARG3(csr->call), 0, IPC_FF_NONE);
     94            IPC_GET_ARG3(csr->call), 0, IPC_FF_NONE);
    9595       
    9696        free(csr);
     
    127127        }
    128128       
     129        link_initialize(&csr->link);
    129130        csr->service = service;
    130131        csr->call = *call;
  • uspace/srv/ns/service.c

    rae0300b5 r007e6efa  
    4343typedef struct {
    4444        link_t link;
    45         sysarg_t service;        /**< Number of the service. */
     45        sysarg_t service;        /**< Service ID. */
    4646        sysarg_t phone;          /**< Phone registered with the service. */
    4747        sysarg_t in_phone_hash;  /**< Incoming phone hash. */
     
    5656 *
    5757 */
    58 static hash_index_t service_hash(unsigned long *key)
     58static hash_index_t service_hash(unsigned long key[])
    5959{
    6060        assert(key);
    61         return (*key % SERVICE_HASH_TABLE_CHAINS);
     61        return (key[0] % SERVICE_HASH_TABLE_CHAINS);
    6262}
    6363
     
    8686       
    8787        if (keys == 2)
    88                 return (key[1] == hs->in_phone_hash);
     88                return ((key[0] == hs->service) && (key[1] == hs->in_phone_hash));
    8989        else
    9090                return (key[0] == hs->service);
     
    195195        hash_table_insert(&service_hash_table, keys, &hs->link);
    196196       
    197         return 0;
     197        return EOK;
    198198}
    199199
     
    227227                        }
    228228                       
     229                        link_initialize(&pr->link);
    229230                        pr->service = service;
    230231                        pr->callid = callid;
  • uspace/srv/ns/task.c

    rae0300b5 r007e6efa  
    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}
  • uspace/srv/ns/task.h

    rae0300b5 r007e6efa  
    3939extern void process_pending_wait(void);
    4040
    41 extern void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid);
     41extern void wait_for_task(task_id_t, ipc_call_t *, ipc_callid_t);
    4242
    43 extern int ns_task_id_intro(ipc_call_t *call);
    44 extern int ns_task_disconnect(ipc_call_t *call);
    45 extern int ns_task_retval(ipc_call_t *call);
     43extern int ns_task_id_intro(ipc_call_t *);
     44extern int ns_task_disconnect(ipc_call_t *);
     45extern int ns_task_retval(ipc_call_t *);
    4646
    4747
  • uspace/srv/vfs/vfs.c

    rae0300b5 r007e6efa  
    3838#include <ipc/ipc.h>
    3939#include <ipc/services.h>
     40#include <ipc/ns.h>
    4041#include <async.h>
    4142#include <errno.h>
     
    4748#include "vfs.h"
    4849
    49 #define NAME "vfs"
     50#define NAME  "vfs"
    5051
    5152static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall)
     
    172173         * Register at the naming service.
    173174         */
    174         ipc_connect_to_me(PHONE_NS, SERVICE_VFS, 0, 0, NULL, NULL);
     175        if (service_register(SERVICE_VFS) != EOK) {
     176                printf("%s: Cannot register VFS service\n", NAME);
     177                return EINVAL;
     178        }
    175179       
    176180        /*
Note: See TracChangeset for help on using the changeset viewer.