Changes in uspace/lib/c/generic/loc.c [c1f27f1d:0fe52ef] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/loc.c
rc1f27f1d r0fe52ef 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;50 49 51 50 static async_sess_t *loc_supp_block_sess = NULL; … … 55 54 static async_sess_t *loc_consumer_sess = NULL; 56 55 56 static loc_cat_change_cb_t cat_change_cb = NULL; 57 57 58 static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 58 59 { 60 loc_cat_change_cb_t cb_fun; 61 59 62 while (true) { 60 63 ipc_call_t call; … … 66 69 } 67 70 71 int retval; 72 68 73 switch (IPC_GET_IMETHOD(call)) { 69 74 case LOC_EVENT_CAT_CHANGE: 70 75 fibril_mutex_lock(&loc_callback_mutex); 71 loc_cat_change_cb_t cb_fun = cat_change_cb; 76 cb_fun = cat_change_cb; 77 if (cb_fun != NULL) { 78 (*cb_fun)(); 79 } 72 80 fibril_mutex_unlock(&loc_callback_mutex); 73 74 async_answer_0(callid, EOK); 75 76 if (cb_fun != NULL) 77 (*cb_fun)(); 78 81 retval = 0; 79 82 break; 80 83 default: 81 async_answer_0(callid, ENOTSUP);84 retval = ENOTSUP; 82 85 } 86 87 async_answer_0(callid, retval); 83 88 } 84 89 } … … 96 101 } 97 102 98 /** Create callback99 *100 * Must be called with loc_callback_mutex locked.101 *102 * @return EOK on success.103 *104 */105 103 static int loc_callback_create(void) 106 104 { 105 async_exch_t *exch; 106 sysarg_t retval; 107 int rc = EOK; 108 109 fibril_mutex_lock(&loc_callback_mutex); 110 107 111 if (!loc_callback_created) { 108 async_exch_t *exch = 109 loc_exchange_begin_blocking(LOC_PORT_CONSUMER); 112 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); 110 113 111 114 ipc_call_t answer; 112 115 aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer); 113 int rc =async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);116 async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL); 114 117 loc_exchange_end(exch); 115 118 119 async_wait_for(req, &retval); 116 120 if (rc != EOK) 117 return rc;118 119 sysarg_t retval;120 async_wait_for(req, &retval);121 if (retval != EOK)122 return retval;121 goto done; 122 123 if (retval != EOK) { 124 rc = retval; 125 goto done; 126 } 123 127 124 128 loc_callback_created = true; 125 129 } 126 130 127 return EOK; 131 rc = EOK; 132 done: 133 fibril_mutex_unlock(&loc_callback_mutex); 134 return rc; 128 135 } 129 136 … … 235 242 236 243 /** Register new driver with loc. */ 237 int loc_server_register(const char *name )244 int loc_server_register(const char *name, async_client_conn_t conn) 238 245 { 239 246 async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER); … … 249 256 return retval; 250 257 } 258 259 async_set_client_connection(conn); 251 260 252 261 exch = loc_exchange_begin(LOC_PORT_SUPPLIER); … … 788 797 sysarg_t **data, size_t *count) 789 798 { 799 service_id_t *ids; 800 size_t act_size; 801 size_t alloc_size; 802 int rc; 803 790 804 *data = NULL; 791 *count = 0; 792 793 size_t act_size = 0; 794 int rc = loc_category_get_ids_once(method, arg1, NULL, 0, 805 act_size = 0; /* silence warning */ 806 807 rc = loc_category_get_ids_once(method, arg1, NULL, 0, 795 808 &act_size); 796 809 if (rc != EOK) 797 810 return rc; 798 799 size_talloc_size = act_size;800 service_id_t *ids = malloc(alloc_size);811 812 alloc_size = act_size; 813 ids = malloc(alloc_size); 801 814 if (ids == NULL) 802 815 return ENOMEM; 803 816 804 817 while (true) { 805 818 rc = loc_category_get_ids_once(method, arg1, ids, alloc_size, … … 807 820 if (rc != EOK) 808 821 return rc; 809 822 810 823 if (act_size <= alloc_size) 811 824 break; 812 813 alloc_size = act_size; 814 ids = realloc(ids, alloc_size); 825 826 alloc_size *= 2; 827 free(ids); 828 829 ids = malloc(alloc_size); 815 830 if (ids == NULL) 816 831 return ENOMEM; 817 832 } 818 833 819 834 *count = act_size / sizeof(category_id_t); 820 835 *data = ids; … … 854 869 int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun) 855 870 { 856 fibril_mutex_lock(&loc_callback_mutex); 857 if (loc_callback_create() != EOK) { 858 fibril_mutex_unlock(&loc_callback_mutex); 871 if (loc_callback_create() != EOK) 859 872 return EIO; 860 } 861 873 862 874 cat_change_cb = cb_fun; 863 fibril_mutex_unlock(&loc_callback_mutex);864 865 875 return EOK; 866 876 }
Note:
See TracChangeset
for help on using the changeset viewer.