Changes in uspace/lib/c/generic/loc.c [0fe52ef:a3fcfba] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/loc.c
r0fe52ef ra3fcfba 47 47 static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex); 48 48 static bool loc_callback_created = false; 49 static loc_cat_change_cb_t cat_change_cb = NULL; 49 50 50 51 static async_sess_t *loc_supp_block_sess = NULL; … … 54 55 static async_sess_t *loc_consumer_sess = NULL; 55 56 56 static loc_cat_change_cb_t cat_change_cb = NULL;57 58 57 static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 59 58 { 60 loc_cat_change_cb_t cb_fun;61 62 59 while (true) { 63 60 ipc_call_t call; … … 69 66 } 70 67 71 int retval;72 73 68 switch (IPC_GET_IMETHOD(call)) { 74 69 case LOC_EVENT_CAT_CHANGE: 75 70 fibril_mutex_lock(&loc_callback_mutex); 76 cb_fun = cat_change_cb; 77 if (cb_fun != NULL) { 71 loc_cat_change_cb_t cb_fun = cat_change_cb; 72 fibril_mutex_unlock(&loc_callback_mutex); 73 74 async_answer_0(callid, EOK); 75 76 if (cb_fun != NULL) 78 77 (*cb_fun)(); 79 } 80 fibril_mutex_unlock(&loc_callback_mutex); 81 retval = 0; 78 82 79 break; 83 80 default: 84 retval = ENOTSUP;81 async_answer_0(callid, ENOTSUP); 85 82 } 86 87 async_answer_0(callid, retval);88 83 } 89 84 } … … 101 96 } 102 97 98 /** Create callback 99 * 100 * Must be called with loc_callback_mutex locked. 101 * 102 * @return EOK on success. 103 * 104 */ 103 105 static int loc_callback_create(void) 104 106 { 105 async_exch_t *exch;106 sysarg_t retval;107 int rc = EOK;108 109 fibril_mutex_lock(&loc_callback_mutex);110 111 107 if (!loc_callback_created) { 112 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); 108 async_exch_t *exch = 109 loc_exchange_begin_blocking(LOC_PORT_CONSUMER); 113 110 114 111 ipc_call_t answer; 115 112 aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer); 116 async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);113 int rc = async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL); 117 114 loc_exchange_end(exch); 118 115 116 if (rc != EOK) 117 return rc; 118 119 sysarg_t retval; 119 120 async_wait_for(req, &retval); 120 if (rc != EOK) 121 goto done; 122 123 if (retval != EOK) { 124 rc = retval; 125 goto done; 126 } 121 if (retval != EOK) 122 return retval; 127 123 128 124 loc_callback_created = true; 129 125 } 130 126 131 rc = EOK; 132 done: 133 fibril_mutex_unlock(&loc_callback_mutex); 134 return rc; 127 return EOK; 135 128 } 136 129 … … 242 235 243 236 /** Register new driver with loc. */ 244 int loc_server_register(const char *name , async_client_conn_t conn)237 int loc_server_register(const char *name) 245 238 { 246 239 async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER); … … 253 246 254 247 if (retval != EOK) { 255 async_wait_for(req, NULL); 256 return retval; 257 } 258 259 async_set_client_connection(conn); 248 async_forget(req); 249 return retval; 250 } 260 251 261 252 exch = loc_exchange_begin(LOC_PORT_SUPPLIER); … … 294 285 295 286 if (retval != EOK) { 296 async_ wait_for(req, NULL);287 async_forget(req); 297 288 return retval; 298 289 } … … 361 352 362 353 if (retval != EOK) { 363 async_ wait_for(req, NULL);354 async_forget(req); 364 355 return retval; 365 356 } … … 410 401 411 402 if (dretval != EOK) { 412 async_ wait_for(req, NULL);403 async_forget(req); 413 404 return dretval; 414 405 } … … 457 448 { 458 449 return loc_get_name_internal(LOC_SERVICE_GET_NAME, svc_id, name); 450 } 451 452 /** Get service server name. 453 * 454 * Provided ID of a service, return the name of its server. 455 * 456 * @param svc_id Service ID 457 * @param name Place to store pointer to new string. Caller should 458 * free it using free(). 459 * @return EOK on success or negative error code 460 */ 461 int loc_service_get_server_name(service_id_t svc_id, char **name) 462 { 463 return loc_get_name_internal(LOC_SERVICE_GET_SERVER_NAME, svc_id, name); 459 464 } 460 465 … … 480 485 481 486 if (retval != EOK) { 482 async_ wait_for(req, NULL);487 async_forget(req); 483 488 return retval; 484 489 } … … 529 534 530 535 if (retval != EOK) { 531 async_ wait_for(req, NULL);536 async_forget(req); 532 537 return retval; 533 538 } … … 692 697 693 698 if (rc != EOK) { 694 async_ wait_for(req, NULL);699 async_forget(req); 695 700 free(devs); 696 701 return 0; … … 741 746 742 747 if (rc != EOK) { 743 async_ wait_for(req, NULL);748 async_forget(req); 744 749 free(devs); 745 750 return 0; … … 769 774 770 775 if (rc != EOK) { 771 async_ wait_for(req, NULL);776 async_forget(req); 772 777 return rc; 773 778 } … … 797 802 sysarg_t **data, size_t *count) 798 803 { 799 service_id_t *ids;800 size_t act_size;801 size_t alloc_size;802 int rc;803 804 804 *data = NULL; 805 act_size = 0; /* silence warning */ 806 807 rc = loc_category_get_ids_once(method, arg1, NULL, 0, 805 *count = 0; 806 807 size_t act_size = 0; 808 int rc = loc_category_get_ids_once(method, arg1, NULL, 0, 808 809 &act_size); 809 810 if (rc != EOK) 810 811 return rc; 811 812 alloc_size = act_size;813 ids = malloc(alloc_size);812 813 size_t alloc_size = act_size; 814 service_id_t *ids = malloc(alloc_size); 814 815 if (ids == NULL) 815 816 return ENOMEM; 816 817 817 818 while (true) { 818 819 rc = loc_category_get_ids_once(method, arg1, ids, alloc_size, … … 820 821 if (rc != EOK) 821 822 return rc; 822 823 823 824 if (act_size <= alloc_size) 824 825 break; 825 826 alloc_size *= 2; 827 free(ids); 828 829 ids = malloc(alloc_size); 826 827 alloc_size = act_size; 828 ids = realloc(ids, alloc_size); 830 829 if (ids == NULL) 831 830 return ENOMEM; 832 831 } 833 832 834 833 *count = act_size / sizeof(category_id_t); 835 834 *data = ids; … … 869 868 int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun) 870 869 { 871 if (loc_callback_create() != EOK) 870 fibril_mutex_lock(&loc_callback_mutex); 871 if (loc_callback_create() != EOK) { 872 fibril_mutex_unlock(&loc_callback_mutex); 872 873 return EIO; 873 874 } 875 874 876 cat_change_cb = cb_fun; 877 fibril_mutex_unlock(&loc_callback_mutex); 878 875 879 return EOK; 876 880 }
Note:
See TracChangeset
for help on using the changeset viewer.