Changeset 00aece0 in mainline for uspace/lib/c/generic/loc.c
- Timestamp:
- 2012-02-18T16:47:38Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4449c6c
- Parents:
- bd5f3b7 (diff), f943dd3 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/loc.c
rbd5f3b7 r00aece0 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); … … 256 249 return retval; 257 250 } 258 259 async_set_client_connection(conn);260 251 261 252 exch = loc_exchange_begin(LOC_PORT_SUPPLIER); … … 797 788 sysarg_t **data, size_t *count) 798 789 { 799 service_id_t *ids;800 size_t act_size;801 size_t alloc_size;802 int rc;803 804 790 *data = NULL; 805 act_size = 0; /* silence warning */ 806 807 rc = loc_category_get_ids_once(method, arg1, NULL, 0, 791 *count = 0; 792 793 size_t act_size = 0; 794 int rc = loc_category_get_ids_once(method, arg1, NULL, 0, 808 795 &act_size); 809 796 if (rc != EOK) 810 797 return rc; 811 812 alloc_size = act_size;813 ids = malloc(alloc_size);798 799 size_t alloc_size = act_size; 800 service_id_t *ids = malloc(alloc_size); 814 801 if (ids == NULL) 815 802 return ENOMEM; 816 803 817 804 while (true) { 818 805 rc = loc_category_get_ids_once(method, arg1, ids, alloc_size, … … 820 807 if (rc != EOK) 821 808 return rc; 822 809 823 810 if (act_size <= alloc_size) 824 811 break; 825 826 alloc_size *= 2; 827 free(ids); 828 829 ids = malloc(alloc_size); 812 813 alloc_size = act_size; 814 ids = realloc(ids, alloc_size); 830 815 if (ids == NULL) 831 816 return ENOMEM; 832 817 } 833 818 834 819 *count = act_size / sizeof(category_id_t); 835 820 *data = ids; … … 869 854 int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun) 870 855 { 871 if (loc_callback_create() != EOK) 856 fibril_mutex_lock(&loc_callback_mutex); 857 if (loc_callback_create() != EOK) { 858 fibril_mutex_unlock(&loc_callback_mutex); 872 859 return EIO; 873 860 } 861 874 862 cat_change_cb = cb_fun; 863 fibril_mutex_unlock(&loc_callback_mutex); 864 875 865 return EOK; 876 866 }
Note:
See TracChangeset
for help on using the changeset viewer.