Ignore:
File:
1 edited

Legend:

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

    r9c31643 r23882034  
    4343 * framework will automatically take care of most synchronization problems.
    4444 *
     45 * Default semantics:
     46 * - async_send_*(): Send asynchronously. If the kernel refuses to send
     47 *                   more messages, [ try to get responses from kernel, if
     48 *                   nothing found, might try synchronous ]
     49 *
    4550 * Example of use (pseudo C):
    4651 *
     
    5358 *   int fibril1(void *arg)
    5459 *   {
    55  *     conn = async_connect_me_to();
     60 *     conn = ipc_connect_me_to();
    5661 *     c1 = async_send(conn);
    5762 *     c2 = async_send(conn);
     
    7277 *   {
    7378 *     if (want_refuse) {
    74  *       async_answer_0(icallid, ELIMIT);
     79 *       ipc_answer_0(icallid, ELIMIT);
    7580 *       return;
    7681 *     }
    77  *     async_answer_0(icallid, EOK);
     82 *     ipc_answer_0(icallid, EOK);
    7883 *
    7984 *     callid = async_get_call(&call);
    8085 *     somehow_handle_the_call(callid, call);
    81  *     async_answer_2(callid, 1, 2, 3);
     86 *     ipc_answer_2(callid, 1, 2, 3);
    8287 *
    8388 *     callid = async_get_call(&call);
     
    8792 */
    8893
    89 #define LIBC_ASYNC_C_
    90 #include <ipc/ipc.h>
     94#include <futex.h>
    9195#include <async.h>
    92 #undef LIBC_ASYNC_C_
    93 
    94 #include <futex.h>
     96#include <async_priv.h>
    9597#include <fibril.h>
    9698#include <stdio.h>
    9799#include <adt/hash_table.h>
    98100#include <adt/list.h>
     101#include <ipc/ipc.h>
    99102#include <assert.h>
    100103#include <errno.h>
     
    102105#include <arch/barrier.h>
    103106#include <bool.h>
    104 #include "private/async.h"
    105107
    106108atomic_t async_futex = FUTEX_INITIALIZER;
     
    122124
    123125/**
    124  * Structures of this type are used to group information about
    125  * a call and about a message queue link.
     126 * Structures of this type are used to group information about a call and a
     127 * message queue link.
    126128 */
    127129typedef struct {
     
    151153        /** Link to the client tracking structure. */
    152154        client_t *client;
    153        
     155
    154156        /** Messages that should be delivered to this fibril. */
    155157        link_t msg_queue;
     
    168170
    169171/** Identifier of the incoming connection handled by the current fibril. */
    170 static fibril_local connection_t *FIBRIL_connection;
     172fibril_local connection_t *FIBRIL_connection;
    171173
    172174static void *default_client_data_constructor(void)
     
    197199{
    198200        assert(FIBRIL_connection);
     201
    199202        return FIBRIL_connection->client->data;
    200203}
    201204
    202 /** Default fibril function that gets called to handle new connection.
    203  *
    204  * This function is defined as a weak symbol - to be redefined in user code.
    205  *
    206  * @param callid Hash of the incoming call.
    207  * @param call   Data of the incoming call.
    208  *
    209  */
    210 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)
    211 {
    212         ipc_answer_0(callid, ENOENT);
    213 }
     205static void default_client_connection(ipc_callid_t callid, ipc_call_t *call);
     206static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call);
    214207
    215208/**
     
    217210 */
    218211static async_client_conn_t client_connection = default_client_connection;
    219 
    220 /** Default fibril function that gets called to handle interrupt notifications.
    221  *
    222  * This function is defined as a weak symbol - to be redefined in user code.
    223  *
    224  * @param callid Hash of the incoming call.
    225  * @param call   Data of the incoming call.
    226  *
    227  */
    228 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
    229 {
    230 }
    231212
    232213/**
     
    240221static LIST_INITIALIZE(timeout_list);
    241222
    242 #define CLIENT_HASH_TABLE_BUCKETS  32
    243 #define CONN_HASH_TABLE_BUCKETS    32
    244 
    245 static hash_index_t client_hash(unsigned long key[])
     223#define CLIENT_HASH_TABLE_BUCKETS       32
     224#define CONN_HASH_TABLE_BUCKETS         32
     225
     226static hash_index_t client_hash(unsigned long *key)
    246227{
    247228        assert(key);
    248         return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
     229        return (((*key) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
    249230}
    250231
    251232static int client_compare(unsigned long key[], hash_count_t keys, link_t *item)
    252233{
    253         client_t *client = hash_table_get_instance(item, client_t, link);
    254         return (key[0] == client->in_task_hash);
     234        client_t *cl = hash_table_get_instance(item, client_t, link);
     235        return (key[0] == cl->in_task_hash);
    255236}
    256237
     
    273254 *
    274255 */
    275 static hash_index_t conn_hash(unsigned long key[])
     256static hash_index_t conn_hash(unsigned long *key)
    276257{
    277258        assert(key);
    278         return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS);
     259        return (((*key) >> 4) % CONN_HASH_TABLE_BUCKETS);
    279260}
    280261
     
    290271static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item)
    291272{
    292         connection_t *conn = hash_table_get_instance(item, connection_t, link);
    293         return (key[0] == conn->in_phone_hash);
    294 }
    295 
     273        connection_t *hs = hash_table_get_instance(item, connection_t, link);
     274        return (key[0] == hs->in_phone_hash);
     275}
     276
     277/** Connection hash table removal callback function.
     278 *
     279 * This function is called whenever a connection is removed from the connection
     280 * hash table.
     281 *
     282 * @param item Connection hash table item being removed.
     283 *
     284 */
    296285static void conn_remove(link_t *item)
    297286{
    298 }
     287        free(hash_table_get_instance(item, connection_t, link));
     288}
     289
    299290
    300291/** Operations for the connection hash table. */
     
    317308        link_t *tmp = timeout_list.next;
    318309        while (tmp != &timeout_list) {
    319                 awaiter_t *cur
    320                     = list_get_instance(tmp, awaiter_t, to_event.link);
     310                awaiter_t *cur;
    321311               
     312                cur = list_get_instance(tmp, awaiter_t, to_event.link);
    322313                if (tv_gteq(&cur->to_event.expires, &wd->to_event.expires))
    323314                        break;
    324                
    325315                tmp = tmp->next;
    326316        }
     
    339329 *
    340330 * @return False if the call doesn't match any connection.
    341  * @return True if the call was passed to the respective connection fibril.
     331 *         True if the call was passed to the respective connection fibril.
    342332 *
    343333 */
     
    476466                         * the first IPC_M_PHONE_HUNGUP call and continues to
    477467                         * call async_get_call_timeout(). Repeat
    478                          * IPC_M_PHONE_HUNGUP until the caller notices.
     468                         * IPC_M_PHONE_HUNGUP until the caller notices. 
    479469                         */
    480470                        memset(call, 0, sizeof(ipc_call_t));
     
    483473                        return conn->close_callid;
    484474                }
    485                
     475
    486476                if (usecs)
    487477                        async_insert_timeout(&conn->wdata);
     
    521511}
    522512
     513/** Default fibril function that gets called to handle new connection.
     514 *
     515 * This function is defined as a weak symbol - to be redefined in user code.
     516 *
     517 * @param callid Hash of the incoming call.
     518 * @param call   Data of the incoming call.
     519 *
     520 */
     521static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)
     522{
     523        ipc_answer_0(callid, ENOENT);
     524}
     525
     526/** Default fibril function that gets called to handle interrupt notifications.
     527 *
     528 * This function is defined as a weak symbol - to be redefined in user code.
     529 *
     530 * @param callid Hash of the incoming call.
     531 * @param call   Data of the incoming call.
     532 *
     533 */
     534static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
     535{
     536}
     537
    523538/** Wrapper for client connection fibril.
    524539 *
     
    533548static int connection_fibril(void *arg)
    534549{
     550        unsigned long key;
     551        client_t *cl;
     552        link_t *lnk;
     553        bool destroy = false;
     554
    535555        /*
    536556         * Setup fibril-local connection pointer.
    537557         */
    538558        FIBRIL_connection = (connection_t *) arg;
    539        
    540         futex_down(&async_futex);
    541        
     559
    542560        /*
    543561         * Add our reference for the current connection in the client task
     
    545563         * hash in a new tracking structure.
    546564         */
    547        
    548         unsigned long key = FIBRIL_connection->in_task_hash;
    549         link_t *lnk = hash_table_find(&client_hash_table, &key);
    550        
    551         client_t *client;
    552        
     565        futex_down(&async_futex);
     566        key = FIBRIL_connection->in_task_hash;
     567        lnk = hash_table_find(&client_hash_table, &key);
    553568        if (lnk) {
    554                 client = hash_table_get_instance(lnk, client_t, link);
    555                 client->refcnt++;
     569                cl = hash_table_get_instance(lnk, client_t, link);
     570                cl->refcnt++;
    556571        } else {
    557                 client = malloc(sizeof(client_t));
    558                 if (!client) {
     572                cl = malloc(sizeof(client_t));
     573                if (!cl) {
    559574                        ipc_answer_0(FIBRIL_connection->callid, ENOMEM);
    560575                        futex_up(&async_futex);
    561576                        return 0;
    562577                }
    563                
    564                 client->in_task_hash = FIBRIL_connection->in_task_hash;
    565                
     578                cl->in_task_hash = FIBRIL_connection->in_task_hash;
    566579                async_serialize_start();
    567                 client->data = async_client_data_create();
     580                cl->data = async_client_data_create();
    568581                async_serialize_end();
    569                
    570                 client->refcnt = 1;
    571                 hash_table_insert(&client_hash_table, &key, &client->link);
    572         }
    573        
     582                cl->refcnt = 1;
     583                hash_table_insert(&client_hash_table, &key, &cl->link);
     584        }
    574585        futex_up(&async_futex);
    575        
    576         FIBRIL_connection->client = client;
    577        
     586
     587        FIBRIL_connection->client = cl;
     588
    578589        /*
    579590         * Call the connection handler function.
     
    585596         * Remove the reference for this client task connection.
    586597         */
    587         bool destroy;
    588        
    589598        futex_down(&async_futex);
    590        
    591         if (--client->refcnt == 0) {
     599        if (--cl->refcnt == 0) {
    592600                hash_table_remove(&client_hash_table, &key, 1);
    593601                destroy = true;
    594         } else
    595                 destroy = false;
    596        
     602        }
    597603        futex_up(&async_futex);
    598        
     604
    599605        if (destroy) {
    600                 if (client->data)
    601                         async_client_data_destroy(client->data);
    602                
    603                 free(client);
    604         }
    605        
     606                if (cl->data)
     607                        async_client_data_destroy(cl->data);
     608                free(cl);
     609        }
     610
    606611        /*
    607612         * Remove myself from the connection hash table.
     
    616621         */
    617622        while (!list_empty(&FIBRIL_connection->msg_queue)) {
    618                 msg_t *msg =
    619                     list_get_instance(FIBRIL_connection->msg_queue.next, msg_t,
    620                     link);
     623                msg_t *msg;
    621624               
     625                msg = list_get_instance(FIBRIL_connection->msg_queue.next,
     626                    msg_t, link);
    622627                list_remove(&msg->link);
    623628                ipc_answer_0(msg->callid, EHANGUP);
     
    632637                ipc_answer_0(FIBRIL_connection->close_callid, EOK);
    633638       
    634         free(FIBRIL_connection);
    635639        return 0;
    636640}
     
    663667                if (callid)
    664668                        ipc_answer_0(callid, ENOMEM);
    665                
    666669                return (uintptr_t) NULL;
    667670        }
     
    711714static void handle_call(ipc_callid_t callid, ipc_call_t *call)
    712715{
    713         /* Unrouted call - take some default action */
     716        /* Unrouted call - do some default behaviour */
    714717        if ((callid & IPC_CALLID_NOTIFICATION)) {
    715718                process_notification(callid, call);
    716                 return;
     719                goto out;
    717720        }
    718721       
     
    720723        case IPC_M_CONNECT_ME:
    721724        case IPC_M_CONNECT_ME_TO:
    722                 /* Open new connection with fibril, etc. */
     725                /* Open new connection with fibril etc. */
    723726                async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call),
    724727                    callid, call, client_connection);
    725                 return;
     728                goto out;
    726729        }
    727730       
    728731        /* Try to route the call through the connection hash table */
    729732        if (route_call(callid, call))
    730                 return;
     733                goto out;
    731734       
    732735        /* Unknown call from unknown phone - hang it up */
    733736        ipc_answer_0(callid, EHANGUP);
     737        return;
     738       
     739out:
     740        ;
    734741}
    735742
     
    744751        link_t *cur = timeout_list.next;
    745752        while (cur != &timeout_list) {
    746                 awaiter_t *waiter =
    747                     list_get_instance(cur, awaiter_t, to_event.link);
     753                awaiter_t *waiter;
    748754               
     755                waiter = list_get_instance(cur, awaiter_t, to_event.link);
    749756                if (tv_gt(&waiter->to_event.expires, &tv))
    750757                        break;
    751                
     758
    752759                cur = cur->next;
    753                
     760
    754761                list_remove(&waiter->to_event.link);
    755762                waiter->to_event.inlist = false;
     
    778785        while (true) {
    779786                if (fibril_switch(FIBRIL_FROM_MANAGER)) {
    780                         futex_up(&async_futex);
     787                        futex_up(&async_futex); 
    781788                        /*
    782789                         * async_futex is always held when entering a manager
     
    801808                                continue;
    802809                        } else
    803                                 timeout = tv_sub(&waiter->to_event.expires, &tv);
     810                                timeout = tv_sub(&waiter->to_event.expires,
     811                                    &tv);
    804812                } else
    805813                        timeout = SYNCH_NO_TIMEOUT;
    806814               
    807815                futex_up(&async_futex);
    808                
     816
    809817                atomic_inc(&threads_in_ipc_wait);
    810818               
     
    814822               
    815823                atomic_dec(&threads_in_ipc_wait);
    816                
     824
    817825                if (!callid) {
    818826                        handle_expired_timeouts();
     
    864872/** Initialize the async framework.
    865873 *
    866  */
    867 void __async_init(void)
     874 * @return Zero on success or an error code.
     875 */
     876int __async_init(void)
    868877{
    869878        if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1,
    870             &client_hash_table_ops))
    871                 abort();
    872        
    873         if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS, 1,
    874             &conn_hash_table_ops))
    875                 abort();
     879            &client_hash_table_ops) || !hash_table_create(&conn_hash_table,
     880            CONN_HASH_TABLE_BUCKETS, 1, &conn_hash_table_ops)) {
     881                return ENOMEM;
     882        }
     883
     884        _async_sess_init();
     885       
     886        return 0;
    876887}
    877888
     
    886897 * @param retval Value returned in the answer.
    887898 * @param data   Call data of the answer.
    888  *
    889899 */
    890900static void reply_received(void *arg, int retval, ipc_call_t *data)
     
    934944    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
    935945{
    936         amsg_t *msg = malloc(sizeof(amsg_t));
     946        amsg_t *msg = malloc(sizeof(*msg));
    937947       
    938948        if (!msg)
     
    943953       
    944954        msg->wdata.to_event.inlist = false;
    945        
    946         /*
    947          * We may sleep in the next method,
    948          * but it will use its own means
    949          */
     955        /* We may sleep in the next method, but it will use its own mechanism */
    950956        msg->wdata.active = true;
    951957       
     
    978984    ipc_call_t *dataptr)
    979985{
    980         amsg_t *msg = malloc(sizeof(amsg_t));
     986        amsg_t *msg = malloc(sizeof(*msg));
    981987       
    982988        if (!msg)
     
    987993       
    988994        msg->wdata.to_event.inlist = false;
    989        
    990         /*
    991          * We may sleep in the next method,
    992          * but it will use its own means
    993          */
     995        /* We may sleep in next method, but it will use its own mechanism */
    994996        msg->wdata.active = true;
    995997       
     
    10901092void async_usleep(suseconds_t timeout)
    10911093{
    1092         amsg_t *msg = malloc(sizeof(amsg_t));
     1094        amsg_t *msg = malloc(sizeof(*msg));
    10931095       
    10941096        if (!msg)
     
    12331235}
    12341236
    1235 void async_msg_0(int phone, sysarg_t imethod)
    1236 {
    1237         ipc_call_async_0(phone, imethod, NULL, NULL, true);
    1238 }
    1239 
    1240 void async_msg_1(int phone, sysarg_t imethod, sysarg_t arg1)
    1241 {
    1242         ipc_call_async_1(phone, imethod, arg1, NULL, NULL, true);
    1243 }
    1244 
    1245 void async_msg_2(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2)
    1246 {
    1247         ipc_call_async_2(phone, imethod, arg1, arg2, NULL, NULL, true);
    1248 }
    1249 
    1250 void async_msg_3(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
    1251     sysarg_t arg3)
    1252 {
    1253         ipc_call_async_3(phone, imethod, arg1, arg2, arg3, NULL, NULL, true);
    1254 }
    1255 
    1256 void async_msg_4(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
    1257     sysarg_t arg3, sysarg_t arg4)
    1258 {
    1259         ipc_call_async_4(phone, imethod, arg1, arg2, arg3, arg4, NULL, NULL,
    1260             true);
    1261 }
    1262 
    1263 void async_msg_5(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
    1264     sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
    1265 {
    1266         ipc_call_async_5(phone, imethod, arg1, arg2, arg3, arg4, arg5, NULL,
    1267             NULL, true);
    1268 }
    1269 
    1270 sysarg_t async_answer_0(ipc_callid_t callid, sysarg_t retval)
    1271 {
    1272         return ipc_answer_0(callid, retval);
    1273 }
    1274 
    1275 sysarg_t async_answer_1(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1)
    1276 {
    1277         return ipc_answer_1(callid, retval, arg1);
    1278 }
    1279 
    1280 sysarg_t async_answer_2(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
    1281     sysarg_t arg2)
    1282 {
    1283         return ipc_answer_2(callid, retval, arg1, arg2);
    1284 }
    1285 
    1286 sysarg_t async_answer_3(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
    1287     sysarg_t arg2, sysarg_t arg3)
    1288 {
    1289         return ipc_answer_3(callid, retval, arg1, arg2, arg3);
    1290 }
    1291 
    1292 sysarg_t async_answer_4(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
    1293     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
    1294 {
    1295         return ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4);
    1296 }
    1297 
    1298 sysarg_t async_answer_5(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
    1299     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
    1300 {
    1301         return ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5);
    1302 }
    1303 
    1304 int async_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
    1305     sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    1306 {
    1307         return ipc_forward_fast(callid, phoneid, imethod, arg1, arg2, mode);
    1308 }
    1309 
    1310 int async_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
    1311     sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
    1312     unsigned int mode)
    1313 {
    1314         return ipc_forward_slow(callid, phoneid, imethod, arg1, arg2, arg3, arg4,
    1315             arg5, mode);
    1316 }
    1317 
    1318 /** Wrapper for making IPC_M_CONNECT_TO_ME calls using the async framework.
    1319  *
     1237/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
     1238 *
    13201239 * Ask through phone for a new connection to some service.
    13211240 *
    1322  * @param phone           Phone handle used for contacting the other side.
    1323  * @param arg1            User defined argument.
    1324  * @param arg2            User defined argument.
    1325  * @param arg3            User defined argument.
    1326  * @param client_receiver Connection handing routine.
    1327  *
    1328  * @return New phone handle on success or a negative error code.
    1329  *
    1330  */
    1331 int async_connect_to_me(int phone, sysarg_t arg1, sysarg_t arg2,
    1332     sysarg_t arg3, async_client_conn_t client_receiver)
    1333 {
    1334         sysarg_t task_hash;
    1335         sysarg_t phone_hash;
    1336         int rc = async_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
    1337             NULL, NULL, NULL, &task_hash, &phone_hash);
    1338         if (rc != EOK)
     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 */
     1248int
     1249async_connect_me_to(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3)
     1250{
     1251        int rc;
     1252        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) 
    13391258                return rc;
    1340        
    1341         if (client_receiver != NULL)
    1342                 async_new_connection(task_hash, phone_hash, 0, NULL,
    1343                     client_receiver);
    1344        
    1345         return EOK;
     1259
     1260        return newphid;
    13461261}
    13471262
    13481263/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
    1349  *
    1350  * Ask through phone for a new connection to some service.
    1351  *
    1352  * @param phone Phone handle used for contacting the other side.
    1353  * @param arg1  User defined argument.
    1354  * @param arg2  User defined argument.
    1355  * @param arg3  User defined argument.
    1356  *
    1357  * @return New phone handle on success or a negative error code.
    1358  *
    1359  */
    1360 int async_connect_me_to(int phone, sysarg_t arg1, sysarg_t arg2,
    1361     sysarg_t arg3)
    1362 {
    1363         sysarg_t newphid;
    1364         int rc = async_req_3_5(phone, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
    1365             NULL, NULL, NULL, NULL, &newphid);
    1366        
    1367         if (rc != EOK)
    1368                 return rc;
    1369        
    1370         return newphid;
    1371 }
    1372 
    1373 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
    1374  *
     1264 *
    13751265 * Ask through phone for a new connection to some service and block until
    13761266 * success.
    13771267 *
    1378  * @param phoneid Phone handle used for contacting the other side.
    1379  * @param arg1    User defined argument.
    1380  * @param arg2    User defined argument.
    1381  * @param arg3    User defined argument.
    1382  *
    1383  * @return New phone handle on success or a negative error code.
    1384  *
    1385  */
    1386 int async_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,
     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 */
     1275int
     1276async_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,
    13871277    sysarg_t arg3)
    13881278{
     1279        int rc;
    13891280        sysarg_t newphid;
    1390         int rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     1281
     1282        rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
    13911283            IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
    13921284       
    1393         if (rc != EOK)
     1285        if (rc != EOK) 
    13941286                return rc;
    1395        
     1287
    13961288        return newphid;
    13971289}
    13981290
    1399 /** Connect to a task specified by id.
    1400  *
    1401  */
    1402 int async_connect_kbox(task_id_t id)
    1403 {
    1404         return ipc_connect_kbox(id);
    1405 }
    1406 
    1407 /** Wrapper for ipc_hangup.
    1408  *
    1409  * @param phone Phone handle to hung up.
    1410  *
    1411  * @return Zero on success or a negative error code.
    1412  *
    1413  */
    1414 int async_hangup(int phone)
    1415 {
    1416         return ipc_hangup(phone);
    1417 }
    1418 
    1419 /** Interrupt one thread of this task from waiting for IPC. */
    1420 void async_poke(void)
    1421 {
    1422         ipc_poke();
    1423 }
    1424 
    1425 /** Wrapper for IPC_M_SHARE_IN calls using the async framework.
    1426  *
    1427  * @param phoneid Phone that will be used to contact the receiving side.
    1428  * @param dst     Destination address space area base.
    1429  * @param size    Size of the destination address space area.
    1430  * @param arg     User defined argument.
    1431  * @param flags   Storage for the received flags. Can be NULL.
    1432  *
    1433  * @return Zero on success or a negative error code from errno.h.
    1434  *
     1291/** Wrapper for making IPC_M_SHARE_IN calls using the async framework.
     1292 *
     1293 * @param phoneid       Phone that will be used to contact the receiving side.
     1294 * @param dst           Destination address space area base.
     1295 * @param size          Size of the destination address space area.
     1296 * @param arg           User defined argument.
     1297 * @param flags         Storage where the received flags will be stored. Can be
     1298 *                      NULL.
     1299 *
     1300 * @return              Zero on success or a negative error code from errno.h.
    14351301 */
    14361302int async_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
    1437     unsigned int *flags)
    1438 {
     1303    int *flags)
     1304{
     1305        int res;
    14391306        sysarg_t tmp_flags;
    1440         int res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
     1307        res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
    14411308            (sysarg_t) size, arg, NULL, &tmp_flags);
    1442        
    14431309        if (flags)
    1444                 *flags = (unsigned int) tmp_flags;
    1445        
     1310                *flags = tmp_flags;
    14461311        return res;
    14471312}
     
    14491314/** Wrapper for receiving the IPC_M_SHARE_IN calls using the async framework.
    14501315 *
    1451  * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN
    1452  * calls so that the user doesn't have to remember the meaning of each IPC
    1453  * argument.
     1316 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN calls
     1317 * so that the user doesn't have to remember the meaning of each IPC argument.
    14541318 *
    14551319 * So far, this wrapper is to be used from within a connection fibril.
    14561320 *
    1457  * @param callid Storage for the hash of the IPC_M_SHARE_IN call.
    1458  * @param size   Destination address space area size.
    1459  *
    1460  * @return True on success, false on failure.
    1461  *
    1462  */
    1463 bool async_share_in_receive(ipc_callid_t *callid, size_t *size)
    1464 {
     1321 * @param callid        Storage where the hash of the IPC_M_SHARE_IN call will
     1322 *                      be stored.
     1323 * @param size          Destination address space area size.   
     1324 *
     1325 * @return              Non-zero on success, zero on failure.
     1326 */
     1327int async_share_in_receive(ipc_callid_t *callid, size_t *size)
     1328{
     1329        ipc_call_t data;
     1330       
    14651331        assert(callid);
    14661332        assert(size);
    1467        
    1468         ipc_call_t data;
     1333
    14691334        *callid = async_get_call(&data);
    1470        
    14711335        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
    1472                 return false;
    1473        
     1336                return 0;
    14741337        *size = (size_t) IPC_GET_ARG2(data);
    1475         return true;
     1338        return 1;
    14761339}
    14771340
    14781341/** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework.
    14791342 *
    1480  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
    1481  * calls so that the user doesn't have to remember the meaning of each IPC
    1482  * argument.
    1483  *
    1484  * @param callid Hash of the IPC_M_DATA_READ call to answer.
    1485  * @param src    Source address space base.
    1486  * @param flags  Flags to be used for sharing. Bits can be only cleared.
    1487  *
    1488  * @return Zero on success or a value from @ref errno.h on failure.
    1489  *
    1490  */
    1491 int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
     1343 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
     1344 * so that the user doesn't have to remember the meaning of each IPC argument.
     1345 *
     1346 * @param callid        Hash of the IPC_M_DATA_READ call to answer.
     1347 * @param src           Source address space base.
     1348 * @param flags         Flags to be used for sharing. Bits can be only cleared.
     1349 *
     1350 * @return              Zero on success or a value from @ref errno.h on failure.
     1351 */
     1352int async_share_in_finalize(ipc_callid_t callid, void *src, int flags)
    14921353{
    14931354        return ipc_share_in_finalize(callid, src, flags);
    14941355}
    14951356
    1496 /** Wrapper for IPC_M_SHARE_OUT calls using the async framework.
    1497  *
    1498  * @param phoneid Phone that will be used to contact the receiving side.
    1499  * @param src     Source address space area base address.
    1500  * @param flags   Flags to be used for sharing. Bits can be only cleared.
    1501  *
    1502  * @return Zero on success or a negative error code from errno.h.
    1503  *
    1504  */
    1505 int async_share_out_start(int phoneid, void *src, unsigned int flags)
     1357/** Wrapper for making IPC_M_SHARE_OUT calls using the async framework.
     1358 *
     1359 * @param phoneid       Phone that will be used to contact the receiving side.
     1360 * @param src           Source address space area base address.
     1361 * @param flags         Flags to be used for sharing. Bits can be only cleared.
     1362 *
     1363 * @return              Zero on success or a negative error code from errno.h.
     1364 */
     1365int async_share_out_start(int phoneid, void *src, int flags)
    15061366{
    15071367        return async_req_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
     
    15111371/** Wrapper for receiving the IPC_M_SHARE_OUT calls using the async framework.
    15121372 *
    1513  * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT
    1514  * calls so that the user doesn't have to remember the meaning of each IPC
    1515  * argument.
     1373 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT calls
     1374 * so that the user doesn't have to remember the meaning of each IPC argument.
    15161375 *
    15171376 * So far, this wrapper is to be used from within a connection fibril.
    15181377 *
    1519  * @param callid Storage for the hash of the IPC_M_SHARE_OUT call.
    1520  * @param size   Storage for the source address space area size.
    1521  * @param flags  Storage for the sharing flags.
    1522  *
    1523  * @return True on success, false on failure.
    1524  *
    1525  */
    1526 bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags)
    1527 {
     1378 * @param callid        Storage where the hash of the IPC_M_SHARE_OUT call will
     1379 *                      be stored.
     1380 * @param size          Storage where the source address space area size will be
     1381 *                      stored.
     1382 * @param flags         Storage where the sharing flags will be stored.
     1383 *
     1384 * @return              Non-zero on success, zero on failure.
     1385 */
     1386int async_share_out_receive(ipc_callid_t *callid, size_t *size, int *flags)
     1387{
     1388        ipc_call_t data;
     1389       
    15281390        assert(callid);
    15291391        assert(size);
    15301392        assert(flags);
    1531        
    1532         ipc_call_t data;
     1393
    15331394        *callid = async_get_call(&data);
    1534        
    15351395        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
    1536                 return false;
    1537        
     1396                return 0;
    15381397        *size = (size_t) IPC_GET_ARG2(data);
    1539         *flags = (unsigned int) IPC_GET_ARG3(data);
    1540         return true;
     1398        *flags = (int) IPC_GET_ARG3(data);
     1399        return 1;
    15411400}
    15421401
    15431402/** Wrapper for answering the IPC_M_SHARE_OUT calls using the async framework.
    15441403 *
    1545  * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT
    1546  * calls so that the user doesn't have to remember the meaning of each IPC
    1547  * argument.
    1548  *
    1549  * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
    1550  * @param dst    Destination address space area base address.
    1551  *
    1552  * @return Zero on success or a value from @ref errno.h on failure.
    1553  *
     1404 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT calls
     1405 * so that the user doesn't have to remember the meaning of each IPC argument.
     1406 *
     1407 * @param callid        Hash of the IPC_M_DATA_WRITE call to answer.
     1408 * @param dst           Destination address space area base address.   
     1409 *
     1410 * @return              Zero on success or a value from @ref errno.h on failure.
    15541411 */
    15551412int async_share_out_finalize(ipc_callid_t callid, void *dst)
     
    15581415}
    15591416
    1560 /** Wrapper for IPC_M_DATA_READ calls using the async framework.
    1561  *
    1562  * @param phoneid Phone that will be used to contact the receiving side.
    1563  * @param dst     Address of the beginning of the destination buffer.
    1564  * @param size    Size of the destination buffer.
    1565  *
    1566  * @return Zero on success or a negative error code from errno.h.
    1567  *
     1417
     1418/** Wrapper for making IPC_M_DATA_READ calls using the async framework.
     1419 *
     1420 * @param phoneid       Phone that will be used to contact the receiving side.
     1421 * @param dst           Address of the beginning of the destination buffer.
     1422 * @param size          Size of the destination buffer.
     1423 *
     1424 * @return              Zero on success or a negative error code from errno.h.
    15681425 */
    15691426int async_data_read_start(int phoneid, void *dst, size_t size)
     
    15751432/** Wrapper for receiving the IPC_M_DATA_READ calls using the async framework.
    15761433 *
    1577  * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ
    1578  * calls so that the user doesn't have to remember the meaning of each IPC
    1579  * argument.
     1434 * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ calls
     1435 * so that the user doesn't have to remember the meaning of each IPC argument.
    15801436 *
    15811437 * So far, this wrapper is to be used from within a connection fibril.
    15821438 *
    1583  * @param callid Storage for the hash of the IPC_M_DATA_READ.
    1584  * @param size   Storage for the maximum size. Can be NULL.
    1585  *
    1586  * @return True on success, false on failure.
    1587  *
    1588  */
    1589 bool async_data_read_receive(ipc_callid_t *callid, size_t *size)
    1590 {
     1439 * @param callid        Storage where the hash of the IPC_M_DATA_READ call will
     1440 *                      be stored.
     1441 * @param size          Storage where the maximum size will be stored. Can be
     1442 *                      NULL.
     1443 *
     1444 * @return              Non-zero on success, zero on failure.
     1445 */
     1446int async_data_read_receive(ipc_callid_t *callid, size_t *size)
     1447{
     1448        ipc_call_t data;
     1449       
    15911450        assert(callid);
    1592        
    1593         ipc_call_t data;
     1451
    15941452        *callid = async_get_call(&data);
    1595        
    15961453        if (IPC_GET_IMETHOD(data) != IPC_M_DATA_READ)
    1597                 return false;
    1598        
     1454                return 0;
    15991455        if (size)
    16001456                *size = (size_t) IPC_GET_ARG2(data);
    1601        
    1602         return true;
     1457        return 1;
    16031458}
    16041459
    16051460/** Wrapper for answering the IPC_M_DATA_READ calls using the async framework.
    16061461 *
    1607  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
    1608  * calls so that the user doesn't have to remember the meaning of each IPC
    1609  * argument.
    1610  *
    1611  * @param callid Hash of the IPC_M_DATA_READ call to answer.
    1612  * @param src    Source address for the IPC_M_DATA_READ call.
    1613  * @param size   Size for the IPC_M_DATA_READ call. Can be smaller than
    1614  *               the maximum size announced by the sender.
    1615  *
    1616  * @return Zero on success or a value from @ref errno.h on failure.
    1617  *
     1462 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
     1463 * so that the user doesn't have to remember the meaning of each IPC argument.
     1464 *
     1465 * @param callid        Hash of the IPC_M_DATA_READ call to answer.
     1466 * @param src           Source address for the IPC_M_DATA_READ call.
     1467 * @param size          Size for the IPC_M_DATA_READ call. Can be smaller than
     1468 *                      the maximum size announced by the sender.
     1469 *
     1470 * @return              Zero on success or a value from @ref errno.h on failure.
    16181471 */
    16191472int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
     
    16231476
    16241477/** Wrapper for forwarding any read request
     1478 *
    16251479 *
    16261480 */
     
    16551509}
    16561510
    1657 /** Wrapper for IPC_M_DATA_WRITE calls using the async framework.
     1511/** Wrapper for making IPC_M_DATA_WRITE calls using the async framework.
    16581512 *
    16591513 * @param phoneid Phone that will be used to contact the receiving side.
     
    16721526/** Wrapper for receiving the IPC_M_DATA_WRITE calls using the async framework.
    16731527 *
    1674  * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE
    1675  * calls so that the user doesn't have to remember the meaning of each IPC
    1676  * argument.
     1528 * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE calls
     1529 * so that the user doesn't have to remember the meaning of each IPC argument.
    16771530 *
    16781531 * So far, this wrapper is to be used from within a connection fibril.
    16791532 *
    1680  * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
    1681  * @param size   Storage for the suggested size. May be NULL.
    1682  *
    1683  * @return True on success, false on failure.
    1684  *
    1685  */
    1686 bool async_data_write_receive(ipc_callid_t *callid, size_t *size)
    1687 {
     1533 * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will
     1534 *               be stored.
     1535 * @param size   Storage where the suggested size will be stored. May be
     1536 *               NULL
     1537 *
     1538 * @return Non-zero on success, zero on failure.
     1539 *
     1540 */
     1541int async_data_write_receive(ipc_callid_t *callid, size_t *size)
     1542{
     1543        ipc_call_t data;
     1544       
    16881545        assert(callid);
    16891546       
    1690         ipc_call_t data;
    16911547        *callid = async_get_call(&data);
    1692        
    16931548        if (IPC_GET_IMETHOD(data) != IPC_M_DATA_WRITE)
    1694                 return false;
     1549                return 0;
    16951550       
    16961551        if (size)
    16971552                *size = (size_t) IPC_GET_ARG2(data);
    16981553       
    1699         return true;
     1554        return 1;
    17001555}
    17011556
    17021557/** Wrapper for answering the IPC_M_DATA_WRITE calls using the async framework.
    17031558 *
    1704  * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE
    1705  * calls so that the user doesn't have to remember the meaning of each IPC
    1706  * argument.
     1559 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE calls
     1560 * so that the user doesn't have to remember the meaning of each IPC argument.
    17071561 *
    17081562 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
     
    18001654 *
    18011655 */
    1802 void async_data_write_void(sysarg_t retval)
     1656void async_data_write_void(const int retval)
    18031657{
    18041658        ipc_callid_t callid;
     
    18081662
    18091663/** Wrapper for forwarding any data that is about to be received
     1664 *
    18101665 *
    18111666 */
Note: See TracChangeset for help on using the changeset viewer.