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


Ignore:
Timestamp:
2011-03-30T13:10:24Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4ae90f9
Parents:
6e50466 (diff), d6b81941 (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 mainline changes

File:
1 edited

Legend:

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

    r6e50466 rad7a6c9  
    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 {
     
    134132
    135133typedef struct {
     134        sysarg_t in_task_hash;
     135        link_t link;
     136        int refcnt;
     137        void *data;
     138} client_t;
     139
     140typedef struct {
    136141        awaiter_t wdata;
    137142       
     
    139144        link_t link;
    140145       
     146        /** Incoming client task hash. */
     147        sysarg_t in_task_hash;
    141148        /** Incoming phone hash. */
    142149        sysarg_t in_phone_hash;
     150       
     151        /** Link to the client tracking structure. */
     152        client_t *client;
    143153       
    144154        /** Messages that should be delivered to this fibril. */
     
    158168
    159169/** Identifier of the incoming connection handled by the current fibril. */
    160 fibril_local connection_t *FIBRIL_connection;
    161 
    162 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call);
    163 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call);
     170static fibril_local connection_t *FIBRIL_connection;
     171
     172static void *default_client_data_constructor(void)
     173{
     174        return NULL;
     175}
     176
     177static void default_client_data_destructor(void *data)
     178{
     179}
     180
     181static async_client_data_ctor_t async_client_data_create =
     182    default_client_data_constructor;
     183static async_client_data_dtor_t async_client_data_destroy =
     184    default_client_data_destructor;
     185
     186void async_set_client_data_constructor(async_client_data_ctor_t ctor)
     187{
     188        async_client_data_create = ctor;
     189}
     190
     191void async_set_client_data_destructor(async_client_data_dtor_t dtor)
     192{
     193        async_client_data_destroy = dtor;
     194}
     195
     196void *async_client_data_get(void)
     197{
     198        assert(FIBRIL_connection);
     199        return FIBRIL_connection->client->data;
     200}
     201
     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}
    164214
    165215/**
     
    167217 */
    168218static 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}
    169231
    170232/**
     
    174236static async_client_conn_t interrupt_received = default_interrupt_received;
    175237
     238static hash_table_t client_hash_table;
    176239static hash_table_t conn_hash_table;
    177240static LIST_INITIALIZE(timeout_list);
    178241
    179 #define CONN_HASH_TABLE_CHAINS  32
     242#define CLIENT_HASH_TABLE_BUCKETS  32
     243#define CONN_HASH_TABLE_BUCKETS    32
     244
     245static hash_index_t client_hash(unsigned long key[])
     246{
     247        assert(key);
     248        return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
     249}
     250
     251static int client_compare(unsigned long key[], hash_count_t keys, link_t *item)
     252{
     253        client_t *client = hash_table_get_instance(item, client_t, link);
     254        return (key[0] == client->in_task_hash);
     255}
     256
     257static void client_remove(link_t *item)
     258{
     259}
     260
     261/** Operations for the client hash table. */
     262static hash_table_operations_t client_hash_table_ops = {
     263        .hash = client_hash,
     264        .compare = client_compare,
     265        .remove_callback = client_remove
     266};
    180267
    181268/** Compute hash into the connection hash table based on the source phone hash.
     
    186273 *
    187274 */
    188 static hash_index_t conn_hash(unsigned long *key)
     275static hash_index_t conn_hash(unsigned long key[])
    189276{
    190277        assert(key);
    191         return (((*key) >> 4) % CONN_HASH_TABLE_CHAINS);
     278        return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS);
    192279}
    193280
     
    203290static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item)
    204291{
    205         connection_t *hs = hash_table_get_instance(item, connection_t, link);
    206         return (key[0] == hs->in_phone_hash);
    207 }
    208 
    209 /** Connection hash table removal callback function.
    210  *
    211  * This function is called whenever a connection is removed from the connection
    212  * hash table.
    213  *
    214  * @param item Connection hash table item being removed.
    215  *
    216  */
     292        connection_t *conn = hash_table_get_instance(item, connection_t, link);
     293        return (key[0] == conn->in_phone_hash);
     294}
     295
    217296static void conn_remove(link_t *item)
    218297{
    219         free(hash_table_get_instance(item, connection_t, link));
    220 }
    221 
     298}
    222299
    223300/** Operations for the connection hash table. */
     
    240317        link_t *tmp = timeout_list.next;
    241318        while (tmp != &timeout_list) {
    242                 awaiter_t *cur;
    243                
    244                 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               
    245322                if (tv_gteq(&cur->to_event.expires, &wd->to_event.expires))
    246323                        break;
     324               
    247325                tmp = tmp->next;
    248326        }
     
    261339 *
    262340 * @return False if the call doesn't match any connection.
    263  *         True if the call was passed to the respective connection fibril.
     341 * @return True if the call was passed to the respective connection fibril.
    264342 *
    265343 */
     
    352430       
    353431        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       
    354438        fibril_add_ready(fid);
    355439       
     
    398482                         * the first IPC_M_PHONE_HUNGUP call and continues to
    399483                         * call async_get_call_timeout(). Repeat
    400                          * IPC_M_PHONE_HUNGUP until the caller notices. 
     484                         * IPC_M_PHONE_HUNGUP until the caller notices.
    401485                         */
    402486                        memset(call, 0, sizeof(ipc_call_t));
     
    405489                        return conn->close_callid;
    406490                }
    407 
     491               
    408492                if (usecs)
    409493                        async_insert_timeout(&conn->wdata);
     
    443527}
    444528
    445 /** Default fibril function that gets called to handle new connection.
    446  *
    447  * This function is defined as a weak symbol - to be redefined in user code.
    448  *
    449  * @param callid Hash of the incoming call.
    450  * @param call   Data of the incoming call.
    451  *
    452  */
    453 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)
    454 {
    455         ipc_answer_0(callid, ENOENT);
    456 }
    457 
    458 /** Default fibril function that gets called to handle interrupt notifications.
    459  *
    460  * This function is defined as a weak symbol - to be redefined in user code.
    461  *
    462  * @param callid Hash of the incoming call.
    463  * @param call   Data of the incoming call.
    464  *
    465  */
    466 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
    467 {
    468 }
    469 
    470529/** Wrapper for client connection fibril.
    471530 *
     
    481540{
    482541        /*
    483          * Setup fibril-local connection pointer and call client_connection().
    484          *
     542         * Setup fibril-local connection pointer.
    485543         */
    486544        FIBRIL_connection = (connection_t *) arg;
     545       
     546        futex_down(&async_futex);
     547       
     548        /*
     549         * Add our reference for the current connection in the client task
     550         * tracking structure. If this is the first reference, create and
     551         * hash in a new tracking structure.
     552         */
     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       
     559        if (lnk) {
     560                client = hash_table_get_instance(lnk, client_t, link);
     561                client->refcnt++;
     562        } else {
     563                client = malloc(sizeof(client_t));
     564                if (!client) {
     565                        ipc_answer_0(FIBRIL_connection->callid, ENOMEM);
     566                        futex_up(&async_futex);
     567                        return 0;
     568                }
     569               
     570                client->in_task_hash = FIBRIL_connection->in_task_hash;
     571               
     572                async_serialize_start();
     573                client->data = async_client_data_create();
     574                async_serialize_end();
     575               
     576                client->refcnt = 1;
     577                hash_table_insert(&client_hash_table, &key, &client->link);
     578        }
     579       
     580        futex_up(&async_futex);
     581       
     582        FIBRIL_connection->client = client;
     583       
     584        /*
     585         * Call the connection handler function.
     586         */
    487587        FIBRIL_connection->cfibril(FIBRIL_connection->callid,
    488588            &FIBRIL_connection->call);
    489589       
    490         /* Remove myself from the connection hash table */
     590        /*
     591         * Remove the reference for this client task connection.
     592         */
     593        bool destroy;
     594       
    491595        futex_down(&async_futex);
    492         unsigned long key = FIBRIL_connection->in_phone_hash;
     596       
     597        if (--client->refcnt == 0) {
     598                hash_table_remove(&client_hash_table, &key, 1);
     599                destroy = true;
     600        } else
     601                destroy = false;
     602       
     603        futex_up(&async_futex);
     604       
     605        if (destroy) {
     606                if (client->data)
     607                        async_client_data_destroy(client->data);
     608               
     609                free(client);
     610        }
     611       
     612        /*
     613         * Remove myself from the connection hash table.
     614         */
     615        futex_down(&async_futex);
     616        key = FIBRIL_connection->in_phone_hash;
    493617        hash_table_remove(&conn_hash_table, &key, 1);
    494618        futex_up(&async_futex);
    495619       
    496         /* Answer all remaining messages with EHANGUP */
     620        /*
     621         * Answer all remaining messages with EHANGUP.
     622         */
    497623        while (!list_empty(&FIBRIL_connection->msg_queue)) {
    498                 msg_t *msg;
    499                
    500                 msg = list_get_instance(FIBRIL_connection->msg_queue.next,
    501                     msg_t, link);
     624                msg_t *msg =
     625                    list_get_instance(FIBRIL_connection->msg_queue.next, msg_t,
     626                    link);
     627               
    502628                list_remove(&msg->link);
    503629                ipc_answer_0(msg->callid, EHANGUP);
     
    505631        }
    506632       
     633        /*
     634         * If the connection was hung-up, answer the last call,
     635         * i.e. IPC_M_PHONE_HUNGUP.
     636         */
    507637        if (FIBRIL_connection->close_callid)
    508638                ipc_answer_0(FIBRIL_connection->close_callid, EOK);
    509639       
     640        free(FIBRIL_connection);
    510641        return 0;
    511642}
     
    517648 * particular fibrils.
    518649 *
     650 * @param in_task_hash  Identification of the incoming connection.
    519651 * @param in_phone_hash Identification of the incoming connection.
    520652 * @param callid        Hash of the opening IPC_M_CONNECT_ME_TO call.
     
    529661 *
    530662 */
    531 fid_t async_new_connection(sysarg_t in_phone_hash, ipc_callid_t callid,
    532     ipc_call_t *call, void (*cfibril)(ipc_callid_t, ipc_call_t *))
     663fid_t async_new_connection(sysarg_t in_task_hash, sysarg_t in_phone_hash,
     664    ipc_callid_t callid, ipc_call_t *call,
     665    void (*cfibril)(ipc_callid_t, ipc_call_t *))
    533666{
    534667        connection_t *conn = malloc(sizeof(*conn));
     
    536669                if (callid)
    537670                        ipc_answer_0(callid, ENOMEM);
     671               
    538672                return (uintptr_t) NULL;
    539673        }
    540674       
     675        conn->in_task_hash = in_task_hash;
    541676        conn->in_phone_hash = in_phone_hash;
    542677        list_initialize(&conn->msg_queue);
     
    552687        conn->wdata.fid = fibril_create(connection_fibril, conn);
    553688       
    554         if (!conn->wdata.fid) {
     689        if (conn->wdata.fid == 0) {
    555690                free(conn);
     691               
    556692                if (callid)
    557693                        ipc_answer_0(callid, ENOMEM);
     694               
    558695                return (uintptr_t) NULL;
    559696        }
     
    582719static void handle_call(ipc_callid_t callid, ipc_call_t *call)
    583720{
    584         /* Unrouted call - do some default behaviour */
     721        /* Unrouted call - take some default action */
    585722        if ((callid & IPC_CALLID_NOTIFICATION)) {
    586723                process_notification(callid, call);
    587                 goto out;
     724                return;
    588725        }
    589726       
     
    591728        case IPC_M_CONNECT_ME:
    592729        case IPC_M_CONNECT_ME_TO:
    593                 /* Open new connection with fibril etc. */
    594                 async_new_connection(IPC_GET_ARG5(*call), callid, call,
    595                     client_connection);
    596                 goto out;
     730                /* Open new connection with fibril, etc. */
     731                async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call),
     732                    callid, call, client_connection);
     733                return;
    597734        }
    598735       
    599736        /* Try to route the call through the connection hash table */
    600737        if (route_call(callid, call))
    601                 goto out;
     738                return;
    602739       
    603740        /* Unknown call from unknown phone - hang it up */
    604741        ipc_answer_0(callid, EHANGUP);
    605         return;
    606        
    607 out:
    608         ;
    609742}
    610743
     
    619752        link_t *cur = timeout_list.next;
    620753        while (cur != &timeout_list) {
    621                 awaiter_t *waiter;
    622                
    623                 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               
    624757                if (tv_gt(&waiter->to_event.expires, &tv))
    625758                        break;
    626 
     759               
    627760                cur = cur->next;
    628 
     761               
    629762                list_remove(&waiter->to_event.link);
    630763                waiter->to_event.inlist = false;
     
    653786        while (true) {
    654787                if (fibril_switch(FIBRIL_FROM_MANAGER)) {
    655                         futex_up(&async_futex); 
     788                        futex_up(&async_futex);
    656789                        /*
    657790                         * async_futex is always held when entering a manager
     
    676809                                continue;
    677810                        } else
    678                                 timeout = tv_sub(&waiter->to_event.expires,
    679                                     &tv);
     811                                timeout = tv_sub(&waiter->to_event.expires, &tv);
    680812                } else
    681813                        timeout = SYNCH_NO_TIMEOUT;
    682814               
    683815                futex_up(&async_futex);
    684 
     816               
    685817                atomic_inc(&threads_in_ipc_wait);
    686818               
     
    690822               
    691823                atomic_dec(&threads_in_ipc_wait);
    692 
     824               
    693825                if (!callid) {
    694826                        handle_expired_timeouts();
     
    729861{
    730862        fid_t fid = fibril_create(async_manager_fibril, NULL);
    731         fibril_add_manager(fid);
     863        if (fid != 0)
     864                fibril_add_manager(fid);
    732865}
    733866
     
    740873/** Initialize the async framework.
    741874 *
    742  * @return Zero on success or an error code.
    743  */
    744 int __async_init(void)
    745 {
    746         if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_CHAINS, 1,
    747             &conn_hash_table_ops)) {
    748                 printf("%s: Cannot create async hash table\n", "libc");
    749                 return ENOMEM;
    750         }
    751        
    752         return 0;
     875 */
     876void __async_init(void)
     877{
     878        if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1,
     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();
    753885}
    754886
     
    763895 * @param retval Value returned in the answer.
    764896 * @param data   Call data of the answer.
     897 *
    765898 */
    766899static void reply_received(void *arg, int retval, ipc_call_t *data)
     
    810943    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
    811944{
    812         amsg_t *msg = malloc(sizeof(*msg));
     945        amsg_t *msg = malloc(sizeof(amsg_t));
    813946       
    814947        if (!msg)
     
    819952       
    820953        msg->wdata.to_event.inlist = false;
    821         /* 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         */
    822959        msg->wdata.active = true;
    823960       
     
    850987    ipc_call_t *dataptr)
    851988{
    852         amsg_t *msg = malloc(sizeof(*msg));
     989        amsg_t *msg = malloc(sizeof(amsg_t));
    853990       
    854991        if (!msg)
     
    859996       
    860997        msg->wdata.to_event.inlist = false;
    861         /* 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         */
    8621003        msg->wdata.active = true;
    8631004       
     
    9581099void async_usleep(suseconds_t timeout)
    9591100{
    960         amsg_t *msg = malloc(sizeof(*msg));
     1101        amsg_t *msg = malloc(sizeof(amsg_t));
    9611102       
    9621103        if (!msg)
     
    11011242}
    11021243
     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
    11031357/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
    1104  * 
     1358 *
    11051359 * Ask through phone for a new connection to some service.
    11061360 *
    1107  * @param phoneid       Phone handle used for contacting the other side.
    1108  * @param arg1          User defined argument.
    1109  * @param arg2          User defined argument.
    1110  * @param arg3          User defined argument.
    1111  *
    1112  * @return              New phone handle on success or a negative error code.
    1113  */
    1114 int
    1115 async_connect_me_to(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3)
    1116 {
    1117         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{
    11181372        sysarg_t newphid;
    1119 
    1120         rc = async_req_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, NULL,
    1121             NULL, NULL, NULL, &newphid);
    1122        
    1123         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)
    11241377                return rc;
    1125 
     1378       
    11261379        return newphid;
    11271380}
    11281381
    11291382/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
    1130  * 
     1383 *
    11311384 * Ask through phone for a new connection to some service and block until
    11321385 * success.
    11331386 *
    1134  * @param phoneid       Phone handle used for contacting the other side.
    1135  * @param arg1          User defined argument.
    1136  * @param arg2          User defined argument.
    1137  * @param arg3          User defined argument.
    1138  *
    1139  * @return              New phone handle on success or a negative error code.
    1140  */
    1141 int
    1142 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,
    11431396    sysarg_t arg3)
    11441397{
    1145         int rc;
    11461398        sysarg_t newphid;
    1147 
    1148         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,
    11491400            IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
    11501401       
    1151         if (rc != EOK) 
     1402        if (rc != EOK)
    11521403                return rc;
    1153 
     1404       
    11541405        return newphid;
    11551406}
    11561407
    1157 /** Wrapper for making IPC_M_SHARE_IN calls using the async framework.
    1158  *
    1159  * @param phoneid       Phone that will be used to contact the receiving side.
    1160  * @param dst           Destination address space area base.
    1161  * @param size          Size of the destination address space area.
    1162  * @param arg           User defined argument.
    1163  * @param flags         Storage where the received flags will be stored. Can be
    1164  *                      NULL.
    1165  *
    1166  * @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 *
    11671444 */
    11681445int async_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
    1169     int *flags)
    1170 {
    1171         int res;
     1446    unsigned int *flags)
     1447{
    11721448        sysarg_t tmp_flags;
    1173         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,
    11741450            (sysarg_t) size, arg, NULL, &tmp_flags);
     1451       
    11751452        if (flags)
    1176                 *flags = tmp_flags;
     1453                *flags = (unsigned int) tmp_flags;
     1454       
    11771455        return res;
    11781456}
     
    11801458/** Wrapper for receiving the IPC_M_SHARE_IN calls using the async framework.
    11811459 *
    1182  * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN calls
    1183  * 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.
    11841463 *
    11851464 * So far, this wrapper is to be used from within a connection fibril.
    11861465 *
    1187  * @param callid        Storage where the hash of the IPC_M_SHARE_IN call will
    1188  *                      be stored.
    1189  * @param size          Destination address space area size.   
    1190  *
    1191  * @return              Non-zero on success, zero on failure.
    1192  */
    1193 int async_share_in_receive(ipc_callid_t *callid, size_t *size)
    1194 {
    1195         ipc_call_t data;
    1196        
     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{
    11971474        assert(callid);
    11981475        assert(size);
    1199 
     1476       
     1477        ipc_call_t data;
    12001478        *callid = async_get_call(&data);
     1479       
    12011480        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
    1202                 return 0;
     1481                return false;
     1482       
    12031483        *size = (size_t) IPC_GET_ARG2(data);
    1204         return 1;
     1484        return true;
    12051485}
    12061486
    12071487/** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework.
    12081488 *
    1209  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
    1210  * so that the user doesn't have to remember the meaning of each IPC argument.
    1211  *
    1212  * @param callid        Hash of the IPC_M_DATA_READ call to answer.
    1213  * @param src           Source address space base.
    1214  * @param flags         Flags to be used for sharing. Bits can be only cleared.
    1215  *
    1216  * @return              Zero on success or a value from @ref errno.h on failure.
    1217  */
    1218 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)
    12191501{
    12201502        return ipc_share_in_finalize(callid, src, flags);
    12211503}
    12221504
    1223 /** Wrapper for making IPC_M_SHARE_OUT calls using the async framework.
    1224  *
    1225  * @param phoneid       Phone that will be used to contact the receiving side.
    1226  * @param src           Source address space area base address.
    1227  * @param flags         Flags to be used for sharing. Bits can be only cleared.
    1228  *
    1229  * @return              Zero on success or a negative error code from errno.h.
    1230  */
    1231 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)
    12321515{
    12331516        return async_req_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
     
    12371520/** Wrapper for receiving the IPC_M_SHARE_OUT calls using the async framework.
    12381521 *
    1239  * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT calls
    1240  * 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.
    12411525 *
    12421526 * So far, this wrapper is to be used from within a connection fibril.
    12431527 *
    1244  * @param callid        Storage where the hash of the IPC_M_SHARE_OUT call will
    1245  *                      be stored.
    1246  * @param size          Storage where the source address space area size will be
    1247  *                      stored.
    1248  * @param flags         Storage where the sharing flags will be stored.
    1249  *
    1250  * @return              Non-zero on success, zero on failure.
    1251  */
    1252 int async_share_out_receive(ipc_callid_t *callid, size_t *size, int *flags)
    1253 {
    1254         ipc_call_t data;
    1255        
     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{
    12561537        assert(callid);
    12571538        assert(size);
    12581539        assert(flags);
    1259 
     1540       
     1541        ipc_call_t data;
    12601542        *callid = async_get_call(&data);
     1543       
    12611544        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
    1262                 return 0;
     1545                return false;
     1546       
    12631547        *size = (size_t) IPC_GET_ARG2(data);
    1264         *flags = (int) IPC_GET_ARG3(data);
    1265         return 1;
     1548        *flags = (unsigned int) IPC_GET_ARG3(data);
     1549        return true;
    12661550}
    12671551
    12681552/** Wrapper for answering the IPC_M_SHARE_OUT calls using the async framework.
    12691553 *
    1270  * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT calls
    1271  * so that the user doesn't have to remember the meaning of each IPC argument.
    1272  *
    1273  * @param callid        Hash of the IPC_M_DATA_WRITE call to answer.
    1274  * @param dst           Destination address space area base address.   
    1275  *
    1276  * @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 *
    12771563 */
    12781564int async_share_out_finalize(ipc_callid_t callid, void *dst)
     
    12811567}
    12821568
    1283 
    1284 /** Wrapper for making IPC_M_DATA_READ calls using the async framework.
    1285  *
    1286  * @param phoneid       Phone that will be used to contact the receiving side.
    1287  * @param dst           Address of the beginning of the destination buffer.
    1288  * @param size          Size of the destination buffer.
    1289  *
    1290  * @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 *
    12911577 */
    12921578int async_data_read_start(int phoneid, void *dst, size_t size)
     
    12981584/** Wrapper for receiving the IPC_M_DATA_READ calls using the async framework.
    12991585 *
    1300  * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ calls
    1301  * 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.
    13021589 *
    13031590 * So far, this wrapper is to be used from within a connection fibril.
    13041591 *
    1305  * @param callid        Storage where the hash of the IPC_M_DATA_READ call will
    1306  *                      be stored.
    1307  * @param size          Storage where the maximum size will be stored. Can be
    1308  *                      NULL.
    1309  *
    1310  * @return              Non-zero on success, zero on failure.
    1311  */
    1312 int async_data_read_receive(ipc_callid_t *callid, size_t *size)
    1313 {
     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       
    13141602        ipc_call_t data;
    1315        
    1316         assert(callid);
    1317 
    13181603        *callid = async_get_call(&data);
     1604       
    13191605        if (IPC_GET_IMETHOD(data) != IPC_M_DATA_READ)
    1320                 return 0;
     1606                return false;
     1607       
    13211608        if (size)
    13221609                *size = (size_t) IPC_GET_ARG2(data);
    1323         return 1;
     1610       
     1611        return true;
    13241612}
    13251613
    13261614/** Wrapper for answering the IPC_M_DATA_READ calls using the async framework.
    13271615 *
    1328  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
    1329  * so that the user doesn't have to remember the meaning of each IPC argument.
    1330  *
    1331  * @param callid        Hash of the IPC_M_DATA_READ call to answer.
    1332  * @param src           Source address for the IPC_M_DATA_READ call.
    1333  * @param size          Size for the IPC_M_DATA_READ call. Can be smaller than
    1334  *                      the maximum size announced by the sender.
    1335  *
    1336  * @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 *
    13371627 */
    13381628int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
     
    13421632
    13431633/** Wrapper for forwarding any read request
    1344  *
    13451634 *
    13461635 */
     
    13751664}
    13761665
    1377 /** Wrapper for making IPC_M_DATA_WRITE calls using the async framework.
     1666/** Wrapper for IPC_M_DATA_WRITE calls using the async framework.
    13781667 *
    13791668 * @param phoneid Phone that will be used to contact the receiving side.
     
    13921681/** Wrapper for receiving the IPC_M_DATA_WRITE calls using the async framework.
    13931682 *
    1394  * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE calls
    1395  * 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.
    13961686 *
    13971687 * So far, this wrapper is to be used from within a connection fibril.
    13981688 *
    1399  * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will
    1400  *               be stored.
    1401  * @param size   Storage where the suggested size will be stored. May be
    1402  *               NULL
    1403  *
    1404  * @return Non-zero on success, zero on failure.
    1405  *
    1406  */
    1407 int async_data_write_receive(ipc_callid_t *callid, size_t *size)
    1408 {
     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       
    14091699        ipc_call_t data;
    1410        
    1411         assert(callid);
    1412        
    14131700        *callid = async_get_call(&data);
     1701       
    14141702        if (IPC_GET_IMETHOD(data) != IPC_M_DATA_WRITE)
    1415                 return 0;
     1703                return false;
    14161704       
    14171705        if (size)
    14181706                *size = (size_t) IPC_GET_ARG2(data);
    14191707       
    1420         return 1;
     1708        return true;
    14211709}
    14221710
    14231711/** Wrapper for answering the IPC_M_DATA_WRITE calls using the async framework.
    14241712 *
    1425  * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE calls
    1426  * 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.
    14271716 *
    14281717 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
     
    15201809 *
    15211810 */
    1522 void async_data_write_void(const int retval)
     1811void async_data_write_void(sysarg_t retval)
    15231812{
    15241813        ipc_callid_t callid;
     
    15281817
    15291818/** Wrapper for forwarding any data that is about to be received
    1530  *
    15311819 *
    15321820 */
Note: See TracChangeset for help on using the changeset viewer.