Changeset cd50486 in mainline for uspace/lib/c/generic/async.c


Ignore:
Timestamp:
2011-02-06T22:03:55Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
25971d2
Parents:
1110ebd (diff), 960ff451 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge development/ changes

File:
1 edited

Legend:

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

    r1110ebd rcd50486  
    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  *
    5045 * Example of use (pseudo C):
    5146 *
     
    5853 *   int fibril1(void *arg)
    5954 *   {
    60  *     conn = ipc_connect_me_to();
     55 *     conn = async_connect_me_to();
    6156 *     c1 = async_send(conn);
    6257 *     c2 = async_send(conn);
     
    7772 *   {
    7873 *     if (want_refuse) {
    79  *       ipc_answer_0(icallid, ELIMIT);
     74 *       async_answer_0(icallid, ELIMIT);
    8075 *       return;
    8176 *     }
    82  *     ipc_answer_0(icallid, EOK);
     77 *     async_answer_0(icallid, EOK);
    8378 *
    8479 *     callid = async_get_call(&call);
    8580 *     somehow_handle_the_call(callid, call);
    86  *     ipc_answer_2(callid, 1, 2, 3);
     81 *     async_answer_2(callid, 1, 2, 3);
    8782 *
    8883 *     callid = async_get_call(&call);
     
    9287 */
    9388
     89#define LIBC_ASYNC_C_
     90#include <ipc/ipc.h>
     91#include <async.h>
     92#undef LIBC_ASYNC_C_
     93
    9494#include <futex.h>
    95 #include <async.h>
    96 #include <async_priv.h>
    9795#include <fibril.h>
    9896#include <stdio.h>
    9997#include <adt/hash_table.h>
    10098#include <adt/list.h>
    101 #include <ipc/ipc.h>
    10299#include <assert.h>
    103100#include <errno.h>
     
    105102#include <arch/barrier.h>
    106103#include <bool.h>
     104#include "private/async.h"
    107105
    108106atomic_t async_futex = FUTEX_INITIALIZER;
     
    124122
    125123/**
    126  * Structures of this type are used to group information about a call and a
    127  * message queue link.
     124 * Structures of this type are used to group information about
     125 * a call and about a message queue link.
    128126 */
    129127typedef struct {
     
    153151        /** Link to the client tracking structure. */
    154152        client_t *client;
    155 
     153       
    156154        /** Messages that should be delivered to this fibril. */
    157155        link_t msg_queue;
     
    170168
    171169/** Identifier of the incoming connection handled by the current fibril. */
    172 fibril_local connection_t *FIBRIL_connection;
     170static fibril_local connection_t *FIBRIL_connection;
    173171
    174172static void *default_client_data_constructor(void)
     
    199197{
    200198        assert(FIBRIL_connection);
    201 
    202199        return FIBRIL_connection->client->data;
    203200}
    204201
    205 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call);
    206 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call);
     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 */
     210static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)
     211{
     212        ipc_answer_0(callid, ENOENT);
     213}
    207214
    208215/**
     
    210217 */
    211218static 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 */
     228static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
     229{
     230}
    212231
    213232/**
     
    221240static LIST_INITIALIZE(timeout_list);
    222241
    223 #define CLIENT_HASH_TABLE_BUCKETS       32
    224 #define CONN_HASH_TABLE_BUCKETS         32
    225 
    226 static hash_index_t client_hash(unsigned long *key)
     242#define CLIENT_HASH_TABLE_BUCKETS  32
     243#define CONN_HASH_TABLE_BUCKETS    32
     244
     245static hash_index_t client_hash(unsigned long key[])
    227246{
    228247        assert(key);
    229         return (((*key) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
     248        return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
    230249}
    231250
    232251static int client_compare(unsigned long key[], hash_count_t keys, link_t *item)
    233252{
    234         client_t *cl = hash_table_get_instance(item, client_t, link);
    235         return (key[0] == cl->in_task_hash);
     253        client_t *client = hash_table_get_instance(item, client_t, link);
     254        return (key[0] == client->in_task_hash);
    236255}
    237256
     
    254273 *
    255274 */
    256 static hash_index_t conn_hash(unsigned long *key)
     275static hash_index_t conn_hash(unsigned long key[])
    257276{
    258277        assert(key);
    259         return (((*key) >> 4) % CONN_HASH_TABLE_BUCKETS);
     278        return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS);
    260279}
    261280
     
    271290static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item)
    272291{
    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  */
     292        connection_t *conn = hash_table_get_instance(item, connection_t, link);
     293        return (key[0] == conn->in_phone_hash);
     294}
     295
    285296static void conn_remove(link_t *item)
    286297{
    287         free(hash_table_get_instance(item, connection_t, link));
    288 }
    289 
     298}
    290299
    291300/** Operations for the connection hash table. */
     
    308317        link_t *tmp = timeout_list.next;
    309318        while (tmp != &timeout_list) {
    310                 awaiter_t *cur;
    311                
    312                 cur = list_get_instance(tmp, awaiter_t, to_event.link);
     319                awaiter_t *cur
     320                    = list_get_instance(tmp, awaiter_t, to_event.link);
     321               
    313322                if (tv_gteq(&cur->to_event.expires, &wd->to_event.expires))
    314323                        break;
     324               
    315325                tmp = tmp->next;
    316326        }
     
    329339 *
    330340 * @return False if the call doesn't match any connection.
    331  *         True if the call was passed to the respective connection fibril.
     341 * @return True if the call was passed to the respective connection fibril.
    332342 *
    333343 */
     
    420430       
    421431        fid_t fid = fibril_create(notification_fibril, msg);
     432        if (fid == 0) {
     433                free(msg);
     434                futex_up(&async_futex);
     435                return false;
     436        }
     437       
    422438        fibril_add_ready(fid);
    423439       
     
    466482                         * the first IPC_M_PHONE_HUNGUP call and continues to
    467483                         * call async_get_call_timeout(). Repeat
    468                          * IPC_M_PHONE_HUNGUP until the caller notices. 
     484                         * IPC_M_PHONE_HUNGUP until the caller notices.
    469485                         */
    470486                        memset(call, 0, sizeof(ipc_call_t));
     
    473489                        return conn->close_callid;
    474490                }
    475 
     491               
    476492                if (usecs)
    477493                        async_insert_timeout(&conn->wdata);
     
    511527}
    512528
    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  */
    521 static 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  */
    534 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
    535 {
    536 }
    537 
    538529/** Wrapper for client connection fibril.
    539530 *
     
    548539static int connection_fibril(void *arg)
    549540{
    550         unsigned long key;
    551         client_t *cl;
    552         link_t *lnk;
    553         bool destroy = false;
    554 
    555541        /*
    556542         * Setup fibril-local connection pointer.
    557543         */
    558544        FIBRIL_connection = (connection_t *) arg;
    559 
     545       
     546        futex_down(&async_futex);
     547       
    560548        /*
    561549         * Add our reference for the current connection in the client task
     
    563551         * hash in a new tracking structure.
    564552         */
    565         futex_down(&async_futex);
    566         key = FIBRIL_connection->in_task_hash;
    567         lnk = hash_table_find(&client_hash_table, &key);
     553       
     554        unsigned long key = FIBRIL_connection->in_task_hash;
     555        link_t *lnk = hash_table_find(&client_hash_table, &key);
     556       
     557        client_t *client;
     558       
    568559        if (lnk) {
    569                 cl = hash_table_get_instance(lnk, client_t, link);
    570                 cl->refcnt++;
     560                client = hash_table_get_instance(lnk, client_t, link);
     561                client->refcnt++;
    571562        } else {
    572                 cl = malloc(sizeof(client_t));
    573                 if (!cl) {
     563                client = malloc(sizeof(client_t));
     564                if (!client) {
    574565                        ipc_answer_0(FIBRIL_connection->callid, ENOMEM);
    575566                        futex_up(&async_futex);
    576567                        return 0;
    577568                }
    578                 cl->in_task_hash = FIBRIL_connection->in_task_hash;
     569               
     570                client->in_task_hash = FIBRIL_connection->in_task_hash;
     571               
    579572                async_serialize_start();
    580                 cl->data = async_client_data_create();
     573                client->data = async_client_data_create();
    581574                async_serialize_end();
    582                 cl->refcnt = 1;
    583                 hash_table_insert(&client_hash_table, &key, &cl->link);
    584         }
     575               
     576                client->refcnt = 1;
     577                hash_table_insert(&client_hash_table, &key, &client->link);
     578        }
     579       
    585580        futex_up(&async_futex);
    586 
    587         FIBRIL_connection->client = cl;
    588 
     581       
     582        FIBRIL_connection->client = client;
     583       
    589584        /*
    590585         * Call the connection handler function.
     
    596591         * Remove the reference for this client task connection.
    597592         */
     593        bool destroy;
     594       
    598595        futex_down(&async_futex);
    599         if (--cl->refcnt == 0) {
     596       
     597        if (--client->refcnt == 0) {
    600598                hash_table_remove(&client_hash_table, &key, 1);
    601599                destroy = true;
    602         }
     600        } else
     601                destroy = false;
     602       
    603603        futex_up(&async_futex);
    604 
     604       
    605605        if (destroy) {
    606                 if (cl->data)
    607                         async_client_data_destroy(cl->data);
    608                 free(cl);
    609         }
    610 
     606                if (client->data)
     607                        async_client_data_destroy(client->data);
     608               
     609                free(client);
     610        }
     611       
    611612        /*
    612613         * Remove myself from the connection hash table.
     
    621622         */
    622623        while (!list_empty(&FIBRIL_connection->msg_queue)) {
    623                 msg_t *msg;
    624                
    625                 msg = list_get_instance(FIBRIL_connection->msg_queue.next,
    626                     msg_t, link);
     624                msg_t *msg =
     625                    list_get_instance(FIBRIL_connection->msg_queue.next, msg_t,
     626                    link);
     627               
    627628                list_remove(&msg->link);
    628629                ipc_answer_0(msg->callid, EHANGUP);
     
    637638                ipc_answer_0(FIBRIL_connection->close_callid, EOK);
    638639       
     640        free(FIBRIL_connection);
    639641        return 0;
    640642}
     
    667669                if (callid)
    668670                        ipc_answer_0(callid, ENOMEM);
     671               
    669672                return (uintptr_t) NULL;
    670673        }
     
    684687        conn->wdata.fid = fibril_create(connection_fibril, conn);
    685688       
    686         if (!conn->wdata.fid) {
     689        if (conn->wdata.fid == 0) {
    687690                free(conn);
     691               
    688692                if (callid)
    689693                        ipc_answer_0(callid, ENOMEM);
     694               
    690695                return (uintptr_t) NULL;
    691696        }
     
    714719static void handle_call(ipc_callid_t callid, ipc_call_t *call)
    715720{
    716         /* Unrouted call - do some default behaviour */
     721        /* Unrouted call - take some default action */
    717722        if ((callid & IPC_CALLID_NOTIFICATION)) {
    718723                process_notification(callid, call);
    719                 goto out;
     724                return;
    720725        }
    721726       
     
    723728        case IPC_M_CONNECT_ME:
    724729        case IPC_M_CONNECT_ME_TO:
    725                 /* Open new connection with fibril etc. */
     730                /* Open new connection with fibril, etc. */
    726731                async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call),
    727732                    callid, call, client_connection);
    728                 goto out;
     733                return;
    729734        }
    730735       
    731736        /* Try to route the call through the connection hash table */
    732737        if (route_call(callid, call))
    733                 goto out;
     738                return;
    734739       
    735740        /* Unknown call from unknown phone - hang it up */
    736741        ipc_answer_0(callid, EHANGUP);
    737         return;
    738        
    739 out:
    740         ;
    741742}
    742743
     
    751752        link_t *cur = timeout_list.next;
    752753        while (cur != &timeout_list) {
    753                 awaiter_t *waiter;
    754                
    755                 waiter = list_get_instance(cur, awaiter_t, to_event.link);
     754                awaiter_t *waiter =
     755                    list_get_instance(cur, awaiter_t, to_event.link);
     756               
    756757                if (tv_gt(&waiter->to_event.expires, &tv))
    757758                        break;
    758 
     759               
    759760                cur = cur->next;
    760 
     761               
    761762                list_remove(&waiter->to_event.link);
    762763                waiter->to_event.inlist = false;
     
    785786        while (true) {
    786787                if (fibril_switch(FIBRIL_FROM_MANAGER)) {
    787                         futex_up(&async_futex); 
     788                        futex_up(&async_futex);
    788789                        /*
    789790                         * async_futex is always held when entering a manager
     
    808809                                continue;
    809810                        } else
    810                                 timeout = tv_sub(&waiter->to_event.expires,
    811                                     &tv);
     811                                timeout = tv_sub(&waiter->to_event.expires, &tv);
    812812                } else
    813813                        timeout = SYNCH_NO_TIMEOUT;
    814814               
    815815                futex_up(&async_futex);
    816 
     816               
    817817                atomic_inc(&threads_in_ipc_wait);
    818818               
     
    822822               
    823823                atomic_dec(&threads_in_ipc_wait);
    824 
     824               
    825825                if (!callid) {
    826826                        handle_expired_timeouts();
     
    861861{
    862862        fid_t fid = fibril_create(async_manager_fibril, NULL);
    863         fibril_add_manager(fid);
     863        if (fid != 0)
     864                fibril_add_manager(fid);
    864865}
    865866
     
    872873/** Initialize the async framework.
    873874 *
    874  * @return Zero on success or an error code.
    875  */
    876 int __async_init(void)
     875 */
     876void __async_init(void)
    877877{
    878878        if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1,
    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;
     879            &client_hash_table_ops))
     880                abort();
     881       
     882        if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS, 1,
     883            &conn_hash_table_ops))
     884                abort();
    887885}
    888886
     
    897895 * @param retval Value returned in the answer.
    898896 * @param data   Call data of the answer.
     897 *
    899898 */
    900899static void reply_received(void *arg, int retval, ipc_call_t *data)
     
    944943    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
    945944{
    946         amsg_t *msg = malloc(sizeof(*msg));
     945        amsg_t *msg = malloc(sizeof(amsg_t));
    947946       
    948947        if (!msg)
     
    953952       
    954953        msg->wdata.to_event.inlist = false;
    955         /* We may sleep in the next method, but it will use its own mechanism */
     954       
     955        /*
     956         * We may sleep in the next method,
     957         * but it will use its own means
     958         */
    956959        msg->wdata.active = true;
    957960       
     
    984987    ipc_call_t *dataptr)
    985988{
    986         amsg_t *msg = malloc(sizeof(*msg));
     989        amsg_t *msg = malloc(sizeof(amsg_t));
    987990       
    988991        if (!msg)
     
    993996       
    994997        msg->wdata.to_event.inlist = false;
    995         /* We may sleep in next method, but it will use its own mechanism */
     998       
     999        /*
     1000         * We may sleep in the next method,
     1001         * but it will use its own means
     1002         */
    9961003        msg->wdata.active = true;
    9971004       
     
    10921099void async_usleep(suseconds_t timeout)
    10931100{
    1094         amsg_t *msg = malloc(sizeof(*msg));
     1101        amsg_t *msg = malloc(sizeof(amsg_t));
    10951102       
    10961103        if (!msg)
     
    12351242}
    12361243
     1244void async_msg_0(int phone, sysarg_t imethod)
     1245{
     1246        ipc_call_async_0(phone, imethod, NULL, NULL, true);
     1247}
     1248
     1249void async_msg_1(int phone, sysarg_t imethod, sysarg_t arg1)
     1250{
     1251        ipc_call_async_1(phone, imethod, arg1, NULL, NULL, true);
     1252}
     1253
     1254void async_msg_2(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2)
     1255{
     1256        ipc_call_async_2(phone, imethod, arg1, arg2, NULL, NULL, true);
     1257}
     1258
     1259void async_msg_3(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
     1260    sysarg_t arg3)
     1261{
     1262        ipc_call_async_3(phone, imethod, arg1, arg2, arg3, NULL, NULL, true);
     1263}
     1264
     1265void async_msg_4(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
     1266    sysarg_t arg3, sysarg_t arg4)
     1267{
     1268        ipc_call_async_4(phone, imethod, arg1, arg2, arg3, arg4, NULL, NULL,
     1269            true);
     1270}
     1271
     1272void async_msg_5(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
     1273    sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
     1274{
     1275        ipc_call_async_5(phone, imethod, arg1, arg2, arg3, arg4, arg5, NULL,
     1276            NULL, true);
     1277}
     1278
     1279sysarg_t async_answer_0(ipc_callid_t callid, sysarg_t retval)
     1280{
     1281        return ipc_answer_0(callid, retval);
     1282}
     1283
     1284sysarg_t async_answer_1(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1)
     1285{
     1286        return ipc_answer_1(callid, retval, arg1);
     1287}
     1288
     1289sysarg_t async_answer_2(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     1290    sysarg_t arg2)
     1291{
     1292        return ipc_answer_2(callid, retval, arg1, arg2);
     1293}
     1294
     1295sysarg_t async_answer_3(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     1296    sysarg_t arg2, sysarg_t arg3)
     1297{
     1298        return ipc_answer_3(callid, retval, arg1, arg2, arg3);
     1299}
     1300
     1301sysarg_t async_answer_4(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     1302    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
     1303{
     1304        return ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4);
     1305}
     1306
     1307sysarg_t async_answer_5(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     1308    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
     1309{
     1310        return ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5);
     1311}
     1312
     1313int async_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
     1314    sysarg_t arg1, sysarg_t arg2, unsigned int mode)
     1315{
     1316        return ipc_forward_fast(callid, phoneid, imethod, arg1, arg2, mode);
     1317}
     1318
     1319int async_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
     1320    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
     1321    unsigned int mode)
     1322{
     1323        return ipc_forward_slow(callid, phoneid, imethod, arg1, arg2, arg3, arg4,
     1324            arg5, mode);
     1325}
     1326
     1327/** Wrapper for making IPC_M_CONNECT_TO_ME calls using the async framework.
     1328 *
     1329 * Ask through phone for a new connection to some service.
     1330 *
     1331 * @param phone           Phone handle used for contacting the other side.
     1332 * @param arg1            User defined argument.
     1333 * @param arg2            User defined argument.
     1334 * @param arg3            User defined argument.
     1335 * @param client_receiver Connection handing routine.
     1336 *
     1337 * @return New phone handle on success or a negative error code.
     1338 *
     1339 */
     1340int async_connect_to_me(int phone, sysarg_t arg1, sysarg_t arg2,
     1341    sysarg_t arg3, async_client_conn_t client_receiver)
     1342{
     1343        sysarg_t task_hash;
     1344        sysarg_t phone_hash;
     1345        int rc = async_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
     1346            NULL, NULL, NULL, &task_hash, &phone_hash);
     1347        if (rc != EOK)
     1348                return rc;
     1349       
     1350        if (client_receiver != NULL)
     1351                async_new_connection(task_hash, phone_hash, 0, NULL,
     1352                    client_receiver);
     1353       
     1354        return EOK;
     1355}
     1356
    12371357/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
    1238  * 
     1358 *
    12391359 * Ask through phone for a new connection to some service.
    12401360 *
    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;
     1361 * @param phone Phone handle used for contacting the other side.
     1362 * @param arg1  User defined argument.
     1363 * @param arg2  User defined argument.
     1364 * @param arg3  User defined argument.
     1365 *
     1366 * @return New phone handle on success or a negative error code.
     1367 *
     1368 */
     1369int async_connect_me_to(int phone, sysarg_t arg1, sysarg_t arg2,
     1370    sysarg_t arg3)
     1371{
    12521372        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) 
     1373        int rc = async_req_3_5(phone, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     1374            NULL, NULL, NULL, NULL, &newphid);
     1375       
     1376        if (rc != EOK)
    12581377                return rc;
    1259 
     1378       
    12601379        return newphid;
    12611380}
    12621381
    12631382/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
    1264  * 
     1383 *
    12651384 * Ask through phone for a new connection to some service and block until
    12661385 * success.
    12671386 *
    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,
     1387 * @param phoneid Phone handle used for contacting the other side.
     1388 * @param arg1    User defined argument.
     1389 * @param arg2    User defined argument.
     1390 * @param arg3    User defined argument.
     1391 *
     1392 * @return New phone handle on success or a negative error code.
     1393 *
     1394 */
     1395int async_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,
    12771396    sysarg_t arg3)
    12781397{
    1279         int rc;
    12801398        sysarg_t newphid;
    1281 
    1282         rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     1399        int rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
    12831400            IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
    12841401       
    1285         if (rc != EOK) 
     1402        if (rc != EOK)
    12861403                return rc;
    1287 
     1404       
    12881405        return newphid;
    12891406}
    12901407
    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.
     1408/** Connect to a task specified by id.
     1409 *
     1410 */
     1411int async_connect_kbox(task_id_t id)
     1412{
     1413        return ipc_connect_kbox(id);
     1414}
     1415
     1416/** Wrapper for ipc_hangup.
     1417 *
     1418 * @param phone Phone handle to hung up.
     1419 *
     1420 * @return Zero on success or a negative error code.
     1421 *
     1422 */
     1423int async_hangup(int phone)
     1424{
     1425        return ipc_hangup(phone);
     1426}
     1427
     1428/** Interrupt one thread of this task from waiting for IPC. */
     1429void async_poke(void)
     1430{
     1431        ipc_poke();
     1432}
     1433
     1434/** Wrapper for IPC_M_SHARE_IN calls using the async framework.
     1435 *
     1436 * @param phoneid Phone that will be used to contact the receiving side.
     1437 * @param dst     Destination address space area base.
     1438 * @param size    Size of the destination address space area.
     1439 * @param arg     User defined argument.
     1440 * @param flags   Storage for the received flags. Can be NULL.
     1441 *
     1442 * @return Zero on success or a negative error code from errno.h.
     1443 *
    13011444 */
    13021445int async_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
    1303     int *flags)
    1304 {
    1305         int res;
     1446    unsigned int *flags)
     1447{
    13061448        sysarg_t tmp_flags;
    1307         res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
     1449        int res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
    13081450            (sysarg_t) size, arg, NULL, &tmp_flags);
     1451       
    13091452        if (flags)
    1310                 *flags = tmp_flags;
     1453                *flags = (unsigned int) tmp_flags;
     1454       
    13111455        return res;
    13121456}
     
    13141458/** Wrapper for receiving the IPC_M_SHARE_IN calls using the async framework.
    13151459 *
    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.
     1460 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN
     1461 * calls so that the user doesn't have to remember the meaning of each IPC
     1462 * argument.
    13181463 *
    13191464 * So far, this wrapper is to be used from within a connection fibril.
    13201465 *
    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  */
    1327 int async_share_in_receive(ipc_callid_t *callid, size_t *size)
    1328 {
    1329         ipc_call_t data;
    1330        
     1466 * @param callid Storage for the hash of the IPC_M_SHARE_IN call.
     1467 * @param size   Destination address space area size.
     1468 *
     1469 * @return True on success, false on failure.
     1470 *
     1471 */
     1472bool async_share_in_receive(ipc_callid_t *callid, size_t *size)
     1473{
    13311474        assert(callid);
    13321475        assert(size);
    1333 
     1476       
     1477        ipc_call_t data;
    13341478        *callid = async_get_call(&data);
     1479       
    13351480        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
    1336                 return 0;
     1481                return false;
     1482       
    13371483        *size = (size_t) IPC_GET_ARG2(data);
    1338         return 1;
     1484        return true;
    13391485}
    13401486
    13411487/** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework.
    13421488 *
    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  */
    1352 int async_share_in_finalize(ipc_callid_t callid, void *src, int flags)
     1489 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
     1490 * calls so that the user doesn't have to remember the meaning of each IPC
     1491 * argument.
     1492 *
     1493 * @param callid Hash of the IPC_M_DATA_READ call to answer.
     1494 * @param src    Source address space base.
     1495 * @param flags  Flags to be used for sharing. Bits can be only cleared.
     1496 *
     1497 * @return Zero on success or a value from @ref errno.h on failure.
     1498 *
     1499 */
     1500int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
    13531501{
    13541502        return ipc_share_in_finalize(callid, src, flags);
    13551503}
    13561504
    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  */
    1365 int async_share_out_start(int phoneid, void *src, int flags)
     1505/** Wrapper for IPC_M_SHARE_OUT calls using the async framework.
     1506 *
     1507 * @param phoneid Phone that will be used to contact the receiving side.
     1508 * @param src     Source address space area base address.
     1509 * @param flags   Flags to be used for sharing. Bits can be only cleared.
     1510 *
     1511 * @return Zero on success or a negative error code from errno.h.
     1512 *
     1513 */
     1514int async_share_out_start(int phoneid, void *src, unsigned int flags)
    13661515{
    13671516        return async_req_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
     
    13711520/** Wrapper for receiving the IPC_M_SHARE_OUT calls using the async framework.
    13721521 *
    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.
     1522 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT
     1523 * calls so that the user doesn't have to remember the meaning of each IPC
     1524 * argument.
    13751525 *
    13761526 * So far, this wrapper is to be used from within a connection fibril.
    13771527 *
    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  */
    1386 int async_share_out_receive(ipc_callid_t *callid, size_t *size, int *flags)
    1387 {
    1388         ipc_call_t data;
    1389        
     1528 * @param callid Storage for the hash of the IPC_M_SHARE_OUT call.
     1529 * @param size   Storage for the source address space area size.
     1530 * @param flags  Storage for the sharing flags.
     1531 *
     1532 * @return True on success, false on failure.
     1533 *
     1534 */
     1535bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags)
     1536{
    13901537        assert(callid);
    13911538        assert(size);
    13921539        assert(flags);
    1393 
     1540       
     1541        ipc_call_t data;
    13941542        *callid = async_get_call(&data);
     1543       
    13951544        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
    1396                 return 0;
     1545                return false;
     1546       
    13971547        *size = (size_t) IPC_GET_ARG2(data);
    1398         *flags = (int) IPC_GET_ARG3(data);
    1399         return 1;
     1548        *flags = (unsigned int) IPC_GET_ARG3(data);
     1549        return true;
    14001550}
    14011551
    14021552/** Wrapper for answering the IPC_M_SHARE_OUT calls using the async framework.
    14031553 *
    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.
     1554 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT
     1555 * calls so that the user doesn't have to remember the meaning of each IPC
     1556 * argument.
     1557 *
     1558 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
     1559 * @param dst    Destination address space area base address.
     1560 *
     1561 * @return Zero on success or a value from @ref errno.h on failure.
     1562 *
    14111563 */
    14121564int async_share_out_finalize(ipc_callid_t callid, void *dst)
     
    14151567}
    14161568
    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.
     1569/** Wrapper for IPC_M_DATA_READ calls using the async framework.
     1570 *
     1571 * @param phoneid Phone that will be used to contact the receiving side.
     1572 * @param dst     Address of the beginning of the destination buffer.
     1573 * @param size    Size of the destination buffer.
     1574 *
     1575 * @return Zero on success or a negative error code from errno.h.
     1576 *
    14251577 */
    14261578int async_data_read_start(int phoneid, void *dst, size_t size)
     
    14321584/** Wrapper for receiving the IPC_M_DATA_READ calls using the async framework.
    14331585 *
    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.
     1586 * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ
     1587 * calls so that the user doesn't have to remember the meaning of each IPC
     1588 * argument.
    14361589 *
    14371590 * So far, this wrapper is to be used from within a connection fibril.
    14381591 *
    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  */
    1446 int async_data_read_receive(ipc_callid_t *callid, size_t *size)
    1447 {
     1592 * @param callid Storage for the hash of the IPC_M_DATA_READ.
     1593 * @param size   Storage for the maximum size. Can be NULL.
     1594 *
     1595 * @return True on success, false on failure.
     1596 *
     1597 */
     1598bool async_data_read_receive(ipc_callid_t *callid, size_t *size)
     1599{
     1600        assert(callid);
     1601       
    14481602        ipc_call_t data;
    1449        
    1450         assert(callid);
    1451 
    14521603        *callid = async_get_call(&data);
     1604       
    14531605        if (IPC_GET_IMETHOD(data) != IPC_M_DATA_READ)
    1454                 return 0;
     1606                return false;
     1607       
    14551608        if (size)
    14561609                *size = (size_t) IPC_GET_ARG2(data);
    1457         return 1;
     1610       
     1611        return true;
    14581612}
    14591613
    14601614/** Wrapper for answering the IPC_M_DATA_READ calls using the async framework.
    14611615 *
    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.
     1616 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
     1617 * calls so that the user doesn't have to remember the meaning of each IPC
     1618 * argument.
     1619 *
     1620 * @param callid Hash of the IPC_M_DATA_READ call to answer.
     1621 * @param src    Source address for the IPC_M_DATA_READ call.
     1622 * @param size   Size for the IPC_M_DATA_READ call. Can be smaller than
     1623 *               the maximum size announced by the sender.
     1624 *
     1625 * @return Zero on success or a value from @ref errno.h on failure.
     1626 *
    14711627 */
    14721628int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
     
    14761632
    14771633/** Wrapper for forwarding any read request
    1478  *
    14791634 *
    14801635 */
     
    15091664}
    15101665
    1511 /** Wrapper for making IPC_M_DATA_WRITE calls using the async framework.
     1666/** Wrapper for IPC_M_DATA_WRITE calls using the async framework.
    15121667 *
    15131668 * @param phoneid Phone that will be used to contact the receiving side.
     
    15261681/** Wrapper for receiving the IPC_M_DATA_WRITE calls using the async framework.
    15271682 *
    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.
     1683 * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE
     1684 * calls so that the user doesn't have to remember the meaning of each IPC
     1685 * argument.
    15301686 *
    15311687 * So far, this wrapper is to be used from within a connection fibril.
    15321688 *
    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  */
    1541 int async_data_write_receive(ipc_callid_t *callid, size_t *size)
    1542 {
     1689 * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
     1690 * @param size   Storage for the suggested size. May be NULL.
     1691 *
     1692 * @return True on success, false on failure.
     1693 *
     1694 */
     1695bool async_data_write_receive(ipc_callid_t *callid, size_t *size)
     1696{
     1697        assert(callid);
     1698       
    15431699        ipc_call_t data;
    1544        
    1545         assert(callid);
    1546        
    15471700        *callid = async_get_call(&data);
     1701       
    15481702        if (IPC_GET_IMETHOD(data) != IPC_M_DATA_WRITE)
    1549                 return 0;
     1703                return false;
    15501704       
    15511705        if (size)
    15521706                *size = (size_t) IPC_GET_ARG2(data);
    15531707       
    1554         return 1;
     1708        return true;
    15551709}
    15561710
    15571711/** Wrapper for answering the IPC_M_DATA_WRITE calls using the async framework.
    15581712 *
    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.
     1713 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE
     1714 * calls so that the user doesn't have to remember the meaning of each IPC
     1715 * argument.
    15611716 *
    15621717 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
     
    16541809 *
    16551810 */
    1656 void async_data_write_void(const int retval)
     1811void async_data_write_void(sysarg_t retval)
    16571812{
    16581813        ipc_callid_t callid;
     
    16621817
    16631818/** Wrapper for forwarding any data that is about to be received
    1664  *
    16651819 *
    16661820 */
Note: See TracChangeset for help on using the changeset viewer.