Changes in uspace/lib/c/generic/async.c [8bf1eeb:c1c0184] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
r8bf1eeb rc1c0184 43 43 * framework will automatically take care of most synchronization problems. 44 44 * 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 * 45 50 * Example of use (pseudo C): 46 51 * … … 53 58 * int fibril1(void *arg) 54 59 * { 55 * conn = async_connect_me_to();60 * conn = ipc_connect_me_to(); 56 61 * c1 = async_send(conn); 57 62 * c2 = async_send(conn); … … 72 77 * { 73 78 * if (want_refuse) { 74 * async_answer_0(icallid, ELIMIT);79 * ipc_answer_0(icallid, ELIMIT); 75 80 * return; 76 81 * } 77 * async_answer_0(icallid, EOK);82 * ipc_answer_0(icallid, EOK); 78 83 * 79 84 * callid = async_get_call(&call); 80 85 * somehow_handle_the_call(callid, call); 81 * async_answer_2(callid, 1, 2, 3);86 * ipc_answer_2(callid, 1, 2, 3); 82 87 * 83 88 * callid = async_get_call(&call); … … 87 92 */ 88 93 89 #define LIBC_ASYNC_C_ 90 #include <ipc/ipc.h> 94 #include <futex.h> 91 95 #include <async.h> 92 #undef LIBC_ASYNC_C_ 93 94 #include <futex.h> 96 #include <async_priv.h> 95 97 #include <fibril.h> 96 98 #include <stdio.h> 97 99 #include <adt/hash_table.h> 98 100 #include <adt/list.h> 101 #include <ipc/ipc.h> 99 102 #include <assert.h> 100 103 #include <errno.h> … … 102 105 #include <arch/barrier.h> 103 106 #include <bool.h> 104 #include "private/async.h"105 107 106 108 atomic_t async_futex = FUTEX_INITIALIZER; … … 122 124 123 125 /** 124 * Structures of this type are used to group information about 125 * a call and about amessage queue link.126 * Structures of this type are used to group information about a call and a 127 * message queue link. 126 128 */ 127 129 typedef struct { … … 132 134 133 135 typedef struct { 134 sysarg_t in_task_hash;135 link_t link;136 int refcnt;137 void *data;138 } client_t;139 140 typedef struct {141 136 awaiter_t wdata; 142 137 … … 144 139 link_t link; 145 140 146 /** Incoming client task hash. */147 sysarg_t in_task_hash;148 141 /** Incoming phone hash. */ 149 142 sysarg_t in_phone_hash; 150 151 /** Link to the client tracking structure. */152 client_t *client;153 143 154 144 /** Messages that should be delivered to this fibril. */ … … 168 158 169 159 /** Identifier of the incoming connection handled by the current fibril. */ 170 static fibril_local connection_t *FIBRIL_connection; 171 172 static void *default_client_data_constructor(void) 173 { 174 return NULL; 175 } 176 177 static void default_client_data_destructor(void *data) 178 { 179 } 180 181 static async_client_data_ctor_t async_client_data_create = 182 default_client_data_constructor; 183 static async_client_data_dtor_t async_client_data_destroy = 184 default_client_data_destructor; 185 186 void async_set_client_data_constructor(async_client_data_ctor_t ctor) 187 { 188 async_client_data_create = ctor; 189 } 190 191 void async_set_client_data_destructor(async_client_data_dtor_t dtor) 192 { 193 async_client_data_destroy = dtor; 194 } 195 196 void *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 */ 210 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call) 211 { 212 ipc_answer_0(callid, ENOENT); 213 } 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); 214 164 215 165 /** … … 217 167 */ 218 168 static async_client_conn_t client_connection = default_client_connection; 219 220 /** Default fibril function that gets called to handle interrupt notifications.221 *222 * This function is defined as a weak symbol - to be redefined in user code.223 *224 * @param callid Hash of the incoming call.225 * @param call Data of the incoming call.226 *227 */228 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)229 {230 }231 169 232 170 /** … … 236 174 static async_client_conn_t interrupt_received = default_interrupt_received; 237 175 238 static hash_table_t client_hash_table;239 176 static hash_table_t conn_hash_table; 240 177 static LIST_INITIALIZE(timeout_list); 241 178 242 #define CLIENT_HASH_TABLE_BUCKETS 32 243 #define CONN_HASH_TABLE_BUCKETS 32 244 245 static hash_index_t client_hash(unsigned long key[]) 179 #define CONN_HASH_TABLE_CHAINS 32 180 181 /** Compute hash into the connection hash table based on the source phone hash. 182 * 183 * @param key Pointer to source phone hash. 184 * 185 * @return Index into the connection hash table. 186 * 187 */ 188 static hash_index_t conn_hash(unsigned long *key) 246 189 { 247 190 assert(key); 248 return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS); 249 } 250 251 static 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 257 static void client_remove(link_t *item) 258 { 259 } 260 261 /** Operations for the client hash table. */ 262 static hash_table_operations_t client_hash_table_ops = { 263 .hash = client_hash, 264 .compare = client_compare, 265 .remove_callback = client_remove 266 }; 267 268 /** Compute hash into the connection hash table based on the source phone hash. 269 * 270 * @param key Pointer to source phone hash. 271 * 272 * @return Index into the connection hash table. 273 * 274 */ 275 static hash_index_t conn_hash(unsigned long key[]) 276 { 277 assert(key); 278 return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS); 191 return (((*key) >> 4) % CONN_HASH_TABLE_CHAINS); 279 192 } 280 193 … … 290 203 static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item) 291 204 { 292 connection_t *conn = hash_table_get_instance(item, connection_t, link); 293 return (key[0] == conn->in_phone_hash); 294 } 295 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 */ 296 217 static void conn_remove(link_t *item) 297 218 { 298 } 219 free(hash_table_get_instance(item, connection_t, link)); 220 } 221 299 222 300 223 /** Operations for the connection hash table. */ … … 317 240 link_t *tmp = timeout_list.next; 318 241 while (tmp != &timeout_list) { 319 awaiter_t *cur 320 = list_get_instance(tmp, awaiter_t, to_event.link); 242 awaiter_t *cur; 321 243 244 cur = list_get_instance(tmp, awaiter_t, to_event.link); 322 245 if (tv_gteq(&cur->to_event.expires, &wd->to_event.expires)) 323 246 break; 324 325 247 tmp = tmp->next; 326 248 } … … 339 261 * 340 262 * @return False if the call doesn't match any connection. 341 * @returnTrue if the call was passed to the respective connection fibril.263 * True if the call was passed to the respective connection fibril. 342 264 * 343 265 */ … … 430 352 431 353 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 438 354 fibril_add_ready(fid); 439 355 … … 482 398 * the first IPC_M_PHONE_HUNGUP call and continues to 483 399 * call async_get_call_timeout(). Repeat 484 * IPC_M_PHONE_HUNGUP until the caller notices. 400 * IPC_M_PHONE_HUNGUP until the caller notices. 485 401 */ 486 402 memset(call, 0, sizeof(ipc_call_t)); … … 489 405 return conn->close_callid; 490 406 } 491 407 492 408 if (usecs) 493 409 async_insert_timeout(&conn->wdata); … … 527 443 } 528 444 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 529 470 /** Wrapper for client connection fibril. 530 471 * … … 540 481 { 541 482 /* 542 * Setup fibril-local connection pointer. 483 * Setup fibril-local connection pointer and call client_connection(). 484 * 543 485 */ 544 486 FIBRIL_connection = (connection_t *) arg; 545 546 futex_down(&async_futex);547 548 /*549 * Add our reference for the current connection in the client task550 * tracking structure. If this is the first reference, create and551 * 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 */587 487 FIBRIL_connection->cfibril(FIBRIL_connection->callid, 588 488 &FIBRIL_connection->call); 589 489 590 /* 591 * Remove the reference for this client task connection. 592 */ 593 bool destroy; 594 490 /* Remove myself from the connection hash table */ 595 491 futex_down(&async_futex); 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; 492 unsigned long key = FIBRIL_connection->in_phone_hash; 617 493 hash_table_remove(&conn_hash_table, &key, 1); 618 494 futex_up(&async_futex); 619 495 620 /* 621 * Answer all remaining messages with EHANGUP. 622 */ 496 /* Answer all remaining messages with EHANGUP */ 623 497 while (!list_empty(&FIBRIL_connection->msg_queue)) { 624 msg_t *msg = 625 list_get_instance(FIBRIL_connection->msg_queue.next, msg_t, 626 link); 498 msg_t *msg; 627 499 500 msg = list_get_instance(FIBRIL_connection->msg_queue.next, 501 msg_t, link); 628 502 list_remove(&msg->link); 629 503 ipc_answer_0(msg->callid, EHANGUP); … … 631 505 } 632 506 633 /*634 * If the connection was hung-up, answer the last call,635 * i.e. IPC_M_PHONE_HUNGUP.636 */637 507 if (FIBRIL_connection->close_callid) 638 508 ipc_answer_0(FIBRIL_connection->close_callid, EOK); 639 509 640 free(FIBRIL_connection);641 510 return 0; 642 511 } … … 648 517 * particular fibrils. 649 518 * 650 * @param in_task_hash Identification of the incoming connection.651 519 * @param in_phone_hash Identification of the incoming connection. 652 520 * @param callid Hash of the opening IPC_M_CONNECT_ME_TO call. … … 661 529 * 662 530 */ 663 fid_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 *)) 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 *)) 666 533 { 667 534 connection_t *conn = malloc(sizeof(*conn)); … … 669 536 if (callid) 670 537 ipc_answer_0(callid, ENOMEM); 671 672 538 return (uintptr_t) NULL; 673 539 } 674 540 675 conn->in_task_hash = in_task_hash;676 541 conn->in_phone_hash = in_phone_hash; 677 542 list_initialize(&conn->msg_queue); … … 687 552 conn->wdata.fid = fibril_create(connection_fibril, conn); 688 553 689 if ( conn->wdata.fid == 0) {554 if (!conn->wdata.fid) { 690 555 free(conn); 691 692 556 if (callid) 693 557 ipc_answer_0(callid, ENOMEM); 694 695 558 return (uintptr_t) NULL; 696 559 } … … 719 582 static void handle_call(ipc_callid_t callid, ipc_call_t *call) 720 583 { 721 /* Unrouted call - take some default action*/584 /* Unrouted call - do some default behaviour */ 722 585 if ((callid & IPC_CALLID_NOTIFICATION)) { 723 586 process_notification(callid, call); 724 return;587 goto out; 725 588 } 726 589 … … 728 591 case IPC_M_CONNECT_ME: 729 592 case IPC_M_CONNECT_ME_TO: 730 /* Open new connection with fibril ,etc. */731 async_new_connection( call->in_task_hash, IPC_GET_ARG5(*call),732 c allid, call, client_connection);733 return;593 /* Open new connection with fibril etc. */ 594 async_new_connection(IPC_GET_ARG5(*call), callid, call, 595 client_connection); 596 goto out; 734 597 } 735 598 736 599 /* Try to route the call through the connection hash table */ 737 600 if (route_call(callid, call)) 738 return;601 goto out; 739 602 740 603 /* Unknown call from unknown phone - hang it up */ 741 604 ipc_answer_0(callid, EHANGUP); 605 return; 606 607 out: 608 ; 742 609 } 743 610 … … 752 619 link_t *cur = timeout_list.next; 753 620 while (cur != &timeout_list) { 754 awaiter_t *waiter = 755 list_get_instance(cur, awaiter_t, to_event.link); 621 awaiter_t *waiter; 756 622 623 waiter = list_get_instance(cur, awaiter_t, to_event.link); 757 624 if (tv_gt(&waiter->to_event.expires, &tv)) 758 625 break; 759 626 760 627 cur = cur->next; 761 628 762 629 list_remove(&waiter->to_event.link); 763 630 waiter->to_event.inlist = false; … … 786 653 while (true) { 787 654 if (fibril_switch(FIBRIL_FROM_MANAGER)) { 788 futex_up(&async_futex); 655 futex_up(&async_futex); 789 656 /* 790 657 * async_futex is always held when entering a manager … … 809 676 continue; 810 677 } else 811 timeout = tv_sub(&waiter->to_event.expires, &tv); 678 timeout = tv_sub(&waiter->to_event.expires, 679 &tv); 812 680 } else 813 681 timeout = SYNCH_NO_TIMEOUT; 814 682 815 683 futex_up(&async_futex); 816 684 817 685 atomic_inc(&threads_in_ipc_wait); 818 686 … … 822 690 823 691 atomic_dec(&threads_in_ipc_wait); 824 692 825 693 if (!callid) { 826 694 handle_expired_timeouts(); … … 861 729 { 862 730 fid_t fid = fibril_create(async_manager_fibril, NULL); 863 if (fid != 0) 864 fibril_add_manager(fid); 731 fibril_add_manager(fid); 865 732 } 866 733 … … 873 740 /** Initialize the async framework. 874 741 * 875 */ 876 void __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(); 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 _async_sess_init(); 753 754 return 0; 885 755 } 886 756 … … 895 765 * @param retval Value returned in the answer. 896 766 * @param data Call data of the answer. 897 *898 767 */ 899 768 static void reply_received(void *arg, int retval, ipc_call_t *data) … … 943 812 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr) 944 813 { 945 amsg_t *msg = malloc(sizeof( amsg_t));814 amsg_t *msg = malloc(sizeof(*msg)); 946 815 947 816 if (!msg) … … 952 821 953 822 msg->wdata.to_event.inlist = false; 954 955 /* 956 * We may sleep in the next method, 957 * but it will use its own means 958 */ 823 /* We may sleep in the next method, but it will use its own mechanism */ 959 824 msg->wdata.active = true; 960 825 … … 987 852 ipc_call_t *dataptr) 988 853 { 989 amsg_t *msg = malloc(sizeof( amsg_t));854 amsg_t *msg = malloc(sizeof(*msg)); 990 855 991 856 if (!msg) … … 996 861 997 862 msg->wdata.to_event.inlist = false; 998 999 /* 1000 * We may sleep in the next method, 1001 * but it will use its own means 1002 */ 863 /* We may sleep in next method, but it will use its own mechanism */ 1003 864 msg->wdata.active = true; 1004 865 … … 1099 960 void async_usleep(suseconds_t timeout) 1100 961 { 1101 amsg_t *msg = malloc(sizeof( amsg_t));962 amsg_t *msg = malloc(sizeof(*msg)); 1102 963 1103 964 if (!msg) … … 1242 1103 } 1243 1104 1244 void async_msg_0(int phone, sysarg_t imethod) 1245 { 1246 ipc_call_async_0(phone, imethod, NULL, NULL, true); 1247 } 1248 1249 void 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 1254 void 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 1259 void 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 1265 void 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 1272 void 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 1279 sysarg_t async_answer_0(ipc_callid_t callid, sysarg_t retval) 1280 { 1281 return ipc_answer_0(callid, retval); 1282 } 1283 1284 sysarg_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 1289 sysarg_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 1295 sysarg_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 1301 sysarg_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 1307 sysarg_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 1313 int 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 1319 int 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 * 1105 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework. 1106 * 1329 1107 * Ask through phone for a new connection to some service. 1330 1108 * 1331 * @param phone 1332 * @param arg1 1333 * @param arg2 1334 * @param arg3 1335 * @param client_receiver Connection handing routine.1336 * 1337 * @return New phone handle on success or a negative error code.1338 * 1339 */ 1340 int 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) 1109 * @param phoneid Phone handle used for contacting the other side. 1110 * @param arg1 User defined argument. 1111 * @param arg2 User defined argument. 1112 * @param arg3 User defined argument. 1113 * 1114 * @return New phone handle on success or a negative error code. 1115 */ 1116 int 1117 async_connect_me_to(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3) 1118 { 1119 int rc; 1120 sysarg_t newphid; 1121 1122 rc = async_req_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, NULL, 1123 NULL, NULL, NULL, &newphid); 1124 1125 if (rc != EOK) 1348 1126 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; 1127 1128 return newphid; 1355 1129 } 1356 1130 1357 1131 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework. 1358 * 1359 * Ask through phone for a new connection to some service. 1360 * 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 */ 1369 int async_connect_me_to(int phone, sysarg_t arg1, sysarg_t arg2, 1370 sysarg_t arg3) 1371 { 1372 sysarg_t newphid; 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) 1377 return rc; 1378 1379 return newphid; 1380 } 1381 1382 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework. 1383 * 1132 * 1384 1133 * Ask through phone for a new connection to some service and block until 1385 1134 * success. 1386 1135 * 1387 * @param phoneid 1388 * @param arg1 1389 * @param arg2 1390 * @param arg3 1391 * 1392 * @return 1393 * 1394 */ 1395 intasync_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,1136 * @param phoneid Phone handle used for contacting the other side. 1137 * @param arg1 User defined argument. 1138 * @param arg2 User defined argument. 1139 * @param arg3 User defined argument. 1140 * 1141 * @return New phone handle on success or a negative error code. 1142 */ 1143 int 1144 async_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2, 1396 1145 sysarg_t arg3) 1397 1146 { 1147 int rc; 1398 1148 sysarg_t newphid; 1399 int rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 1149 1150 rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 1400 1151 IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid); 1401 1152 1402 if (rc != EOK) 1153 if (rc != EOK) 1403 1154 return rc; 1404 1155 1405 1156 return newphid; 1406 1157 } 1407 1158 1408 /** Connect to a task specified by id. 1409 * 1410 */ 1411 int 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 */ 1423 int async_hangup(int phone) 1424 { 1425 return ipc_hangup(phone); 1426 } 1427 1428 /** Interrupt one thread of this task from waiting for IPC. */ 1429 void 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 * 1159 /** Wrapper for making IPC_M_SHARE_IN calls using the async framework. 1160 * 1161 * @param phoneid Phone that will be used to contact the receiving side. 1162 * @param dst Destination address space area base. 1163 * @param size Size of the destination address space area. 1164 * @param arg User defined argument. 1165 * @param flags Storage where the received flags will be stored. Can be 1166 * NULL. 1167 * 1168 * @return Zero on success or a negative error code from errno.h. 1444 1169 */ 1445 1170 int async_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg, 1446 unsigned int *flags) 1447 { 1171 int *flags) 1172 { 1173 int res; 1448 1174 sysarg_t tmp_flags; 1449 intres = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,1175 res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst, 1450 1176 (sysarg_t) size, arg, NULL, &tmp_flags); 1451 1452 1177 if (flags) 1453 *flags = (unsigned int) tmp_flags; 1454 1178 *flags = tmp_flags; 1455 1179 return res; 1456 1180 } … … 1458 1182 /** Wrapper for receiving the IPC_M_SHARE_IN calls using the async framework. 1459 1183 * 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. 1184 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN calls 1185 * so that the user doesn't have to remember the meaning of each IPC argument. 1463 1186 * 1464 1187 * So far, this wrapper is to be used from within a connection fibril. 1465 1188 * 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 */ 1472 bool async_share_in_receive(ipc_callid_t *callid, size_t *size) 1473 { 1189 * @param callid Storage where the hash of the IPC_M_SHARE_IN call will 1190 * be stored. 1191 * @param size Destination address space area size. 1192 * 1193 * @return Non-zero on success, zero on failure. 1194 */ 1195 int async_share_in_receive(ipc_callid_t *callid, size_t *size) 1196 { 1197 ipc_call_t data; 1198 1474 1199 assert(callid); 1475 1200 assert(size); 1476 1477 ipc_call_t data; 1201 1478 1202 *callid = async_get_call(&data); 1479 1480 1203 if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN) 1481 return false; 1482 1204 return 0; 1483 1205 *size = (size_t) IPC_GET_ARG2(data); 1484 return true;1206 return 1; 1485 1207 } 1486 1208 1487 1209 /** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework. 1488 1210 * 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 */ 1500 int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags) 1211 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls 1212 * so that the user doesn't have to remember the meaning of each IPC argument. 1213 * 1214 * @param callid Hash of the IPC_M_DATA_READ call to answer. 1215 * @param src Source address space base. 1216 * @param flags Flags to be used for sharing. Bits can be only cleared. 1217 * 1218 * @return Zero on success or a value from @ref errno.h on failure. 1219 */ 1220 int async_share_in_finalize(ipc_callid_t callid, void *src, int flags) 1501 1221 { 1502 1222 return ipc_share_in_finalize(callid, src, flags); 1503 1223 } 1504 1224 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 */ 1514 int async_share_out_start(int phoneid, void *src, unsigned int flags) 1225 /** Wrapper for making IPC_M_SHARE_OUT calls using the async framework. 1226 * 1227 * @param phoneid Phone that will be used to contact the receiving side. 1228 * @param src Source address space area base address. 1229 * @param flags Flags to be used for sharing. Bits can be only cleared. 1230 * 1231 * @return Zero on success or a negative error code from errno.h. 1232 */ 1233 int async_share_out_start(int phoneid, void *src, int flags) 1515 1234 { 1516 1235 return async_req_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0, … … 1520 1239 /** Wrapper for receiving the IPC_M_SHARE_OUT calls using the async framework. 1521 1240 * 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. 1241 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT calls 1242 * so that the user doesn't have to remember the meaning of each IPC argument. 1525 1243 * 1526 1244 * So far, this wrapper is to be used from within a connection fibril. 1527 1245 * 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 */ 1535 bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags) 1536 { 1246 * @param callid Storage where the hash of the IPC_M_SHARE_OUT call will 1247 * be stored. 1248 * @param size Storage where the source address space area size will be 1249 * stored. 1250 * @param flags Storage where the sharing flags will be stored. 1251 * 1252 * @return Non-zero on success, zero on failure. 1253 */ 1254 int async_share_out_receive(ipc_callid_t *callid, size_t *size, int *flags) 1255 { 1256 ipc_call_t data; 1257 1537 1258 assert(callid); 1538 1259 assert(size); 1539 1260 assert(flags); 1540 1541 ipc_call_t data; 1261 1542 1262 *callid = async_get_call(&data); 1543 1544 1263 if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT) 1545 return false; 1546 1264 return 0; 1547 1265 *size = (size_t) IPC_GET_ARG2(data); 1548 *flags = ( unsignedint) IPC_GET_ARG3(data);1549 return true;1266 *flags = (int) IPC_GET_ARG3(data); 1267 return 1; 1550 1268 } 1551 1269 1552 1270 /** Wrapper for answering the IPC_M_SHARE_OUT calls using the async framework. 1553 1271 * 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 * 1272 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT calls 1273 * so that the user doesn't have to remember the meaning of each IPC argument. 1274 * 1275 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. 1276 * @param dst Destination address space area base address. 1277 * 1278 * @return Zero on success or a value from @ref errno.h on failure. 1563 1279 */ 1564 1280 int async_share_out_finalize(ipc_callid_t callid, void *dst) … … 1567 1283 } 1568 1284 1569 /** Start IPC_M_DATA_READ 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 (in bytes). 1574 * @param dataptr Storage of call data (arg 2 holds actual data size). 1575 * @return Hash of the sent message or 0 on error. 1576 */ 1577 aid_t async_data_read(int phoneid, void *dst, size_t size, ipc_call_t *dataptr) 1578 { 1579 return async_send_2(phoneid, IPC_M_DATA_READ, (sysarg_t) dst, 1580 (sysarg_t) size, dataptr); 1581 } 1582 1583 /** Wrapper for IPC_M_DATA_READ calls using the async framework. 1584 * 1585 * @param phoneid Phone that will be used to contact the receiving side. 1586 * @param dst Address of the beginning of the destination buffer. 1587 * @param size Size of the destination buffer. 1588 * 1589 * @return Zero on success or a negative error code from errno.h. 1590 * 1285 1286 /** Wrapper for making IPC_M_DATA_READ calls using the async framework. 1287 * 1288 * @param phoneid Phone that will be used to contact the receiving side. 1289 * @param dst Address of the beginning of the destination buffer. 1290 * @param size Size of the destination buffer. 1291 * 1292 * @return Zero on success or a negative error code from errno.h. 1591 1293 */ 1592 1294 int async_data_read_start(int phoneid, void *dst, size_t size) … … 1598 1300 /** Wrapper for receiving the IPC_M_DATA_READ calls using the async framework. 1599 1301 * 1600 * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ 1601 * calls so that the user doesn't have to remember the meaning of each IPC 1602 * argument. 1302 * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ calls 1303 * so that the user doesn't have to remember the meaning of each IPC argument. 1603 1304 * 1604 1305 * So far, this wrapper is to be used from within a connection fibril. 1605 1306 * 1606 * @param callid Storage for the hash of the IPC_M_DATA_READ. 1607 * @param size Storage for the maximum size. Can be NULL. 1608 * 1609 * @return True on success, false on failure. 1610 * 1611 */ 1612 bool async_data_read_receive(ipc_callid_t *callid, size_t *size) 1613 { 1307 * @param callid Storage where the hash of the IPC_M_DATA_READ call will 1308 * be stored. 1309 * @param size Storage where the maximum size will be stored. Can be 1310 * NULL. 1311 * 1312 * @return Non-zero on success, zero on failure. 1313 */ 1314 int async_data_read_receive(ipc_callid_t *callid, size_t *size) 1315 { 1316 ipc_call_t data; 1317 1614 1318 assert(callid); 1615 1616 ipc_call_t data; 1319 1617 1320 *callid = async_get_call(&data); 1618 1619 1321 if (IPC_GET_IMETHOD(data) != IPC_M_DATA_READ) 1620 return false; 1621 1322 return 0; 1622 1323 if (size) 1623 1324 *size = (size_t) IPC_GET_ARG2(data); 1624 1625 return true; 1325 return 1; 1626 1326 } 1627 1327 1628 1328 /** Wrapper for answering the IPC_M_DATA_READ calls using the async framework. 1629 1329 * 1630 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ 1631 * calls so that the user doesn't have to remember the meaning of each IPC 1632 * argument. 1633 * 1634 * @param callid Hash of the IPC_M_DATA_READ call to answer. 1635 * @param src Source address for the IPC_M_DATA_READ call. 1636 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than 1637 * the maximum size announced by the sender. 1638 * 1639 * @return Zero on success or a value from @ref errno.h on failure. 1640 * 1330 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls 1331 * so that the user doesn't have to remember the meaning of each IPC argument. 1332 * 1333 * @param callid Hash of the IPC_M_DATA_READ call to answer. 1334 * @param src Source address for the IPC_M_DATA_READ call. 1335 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than 1336 * the maximum size announced by the sender. 1337 * 1338 * @return Zero on success or a value from @ref errno.h on failure. 1641 1339 */ 1642 1340 int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size) … … 1646 1344 1647 1345 /** Wrapper for forwarding any read request 1346 * 1648 1347 * 1649 1348 */ … … 1678 1377 } 1679 1378 1680 /** Wrapper for IPC_M_DATA_WRITE calls using the async framework.1379 /** Wrapper for making IPC_M_DATA_WRITE calls using the async framework. 1681 1380 * 1682 1381 * @param phoneid Phone that will be used to contact the receiving side. … … 1695 1394 /** Wrapper for receiving the IPC_M_DATA_WRITE calls using the async framework. 1696 1395 * 1697 * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE 1698 * calls so that the user doesn't have to remember the meaning of each IPC 1699 * argument. 1396 * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE calls 1397 * so that the user doesn't have to remember the meaning of each IPC argument. 1700 1398 * 1701 1399 * So far, this wrapper is to be used from within a connection fibril. 1702 1400 * 1703 * @param callid Storage for the hash of the IPC_M_DATA_WRITE. 1704 * @param size Storage for the suggested size. May be NULL. 1705 * 1706 * @return True on success, false on failure. 1707 * 1708 */ 1709 bool async_data_write_receive(ipc_callid_t *callid, size_t *size) 1710 { 1401 * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will 1402 * be stored. 1403 * @param size Storage where the suggested size will be stored. May be 1404 * NULL 1405 * 1406 * @return Non-zero on success, zero on failure. 1407 * 1408 */ 1409 int async_data_write_receive(ipc_callid_t *callid, size_t *size) 1410 { 1411 ipc_call_t data; 1412 1711 1413 assert(callid); 1712 1414 1713 ipc_call_t data;1714 1415 *callid = async_get_call(&data); 1715 1716 1416 if (IPC_GET_IMETHOD(data) != IPC_M_DATA_WRITE) 1717 return false;1417 return 0; 1718 1418 1719 1419 if (size) 1720 1420 *size = (size_t) IPC_GET_ARG2(data); 1721 1421 1722 return true;1422 return 1; 1723 1423 } 1724 1424 1725 1425 /** Wrapper for answering the IPC_M_DATA_WRITE calls using the async framework. 1726 1426 * 1727 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE 1728 * calls so that the user doesn't have to remember the meaning of each IPC 1729 * argument. 1427 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE calls 1428 * so that the user doesn't have to remember the meaning of each IPC argument. 1730 1429 * 1731 1430 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. … … 1823 1522 * 1824 1523 */ 1825 void async_data_write_void( sysarg_t retval)1524 void async_data_write_void(const int retval) 1826 1525 { 1827 1526 ipc_callid_t callid; … … 1831 1530 1832 1531 /** Wrapper for forwarding any data that is about to be received 1532 * 1833 1533 * 1834 1534 */
Note:
See TracChangeset
for help on using the changeset viewer.