Changes in uspace/lib/c/generic/loc.c [c1f27f1d:f302586] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/loc.c
rc1f27f1d rf302586 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 … … 788 795 sysarg_t **data, size_t *count) 789 796 { 797 service_id_t *ids; 798 size_t act_size; 799 size_t alloc_size; 800 int rc; 801 790 802 *data = NULL; 791 *count = 0; 792 793 size_t act_size = 0; 794 int rc = loc_category_get_ids_once(method, arg1, NULL, 0, 803 act_size = 0; /* silence warning */ 804 805 rc = loc_category_get_ids_once(method, arg1, NULL, 0, 795 806 &act_size); 796 807 if (rc != EOK) 797 808 return rc; 798 799 size_talloc_size = act_size;800 service_id_t *ids = malloc(alloc_size);809 810 alloc_size = act_size; 811 ids = malloc(alloc_size); 801 812 if (ids == NULL) 802 813 return ENOMEM; 803 814 804 815 while (true) { 805 816 rc = loc_category_get_ids_once(method, arg1, ids, alloc_size, … … 807 818 if (rc != EOK) 808 819 return rc; 809 820 810 821 if (act_size <= alloc_size) 811 822 break; 812 813 alloc_size = act_size; 814 ids = realloc(ids, alloc_size); 823 824 alloc_size *= 2; 825 free(ids); 826 827 ids = malloc(alloc_size); 815 828 if (ids == NULL) 816 829 return ENOMEM; 817 830 } 818 831 819 832 *count = act_size / sizeof(category_id_t); 820 833 *data = ids; … … 854 867 int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun) 855 868 { 856 fibril_mutex_lock(&loc_callback_mutex); 857 if (loc_callback_create() != EOK) { 858 fibril_mutex_unlock(&loc_callback_mutex); 869 if (loc_callback_create() != EOK) 859 870 return EIO; 860 } 861 871 862 872 cat_change_cb = cb_fun; 863 fibril_mutex_unlock(&loc_callback_mutex);864 865 873 return EOK; 866 874 }
Note:
See TracChangeset
for help on using the changeset viewer.