Changeset 8dc762e0 in mainline for uspace/lib/usb/src/host/usb_endpoint_manager.c
- Timestamp:
- 2011-04-06T21:12:41Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade
- Children:
- f567bcf
- Parents:
- 1e70157
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/host/usb_endpoint_manager.c
r1e70157 r8dc762e0 48 48 link_t link; 49 49 size_t bw; 50 void *data; 51 void (*data_remove_callback)(void* data); 52 } ep_t; 53 /*----------------------------------------------------------------------------*/ 54 static hash_index_t ep_hash(unsigned long key[]) 50 endpoint_t *ep; 51 } node_t; 52 /*----------------------------------------------------------------------------*/ 53 static hash_index_t node_hash(unsigned long key[]) 55 54 { 56 55 hash_index_t hash = 0; … … 63 62 } 64 63 /*----------------------------------------------------------------------------*/ 65 static int ep_compare(unsigned long key[], hash_count_t keys, link_t *item)64 static int node_compare(unsigned long key[], hash_count_t keys, link_t *item) 66 65 { 67 66 assert(item); 68 ep_t *ep = hash_table_get_instance(item, ep_t, link);67 node_t *node = hash_table_get_instance(item, node_t, link); 69 68 hash_count_t i = 0; 70 69 for (; i < keys; ++i) { 71 if (key[i] != ep->key[i])70 if (key[i] != node->key[i]) 72 71 return false; 73 72 } … … 75 74 } 76 75 /*----------------------------------------------------------------------------*/ 77 static void ep_remove(link_t *item)76 static void node_remove(link_t *item) 78 77 { 79 78 assert(item); 80 ep_t *ep = 81 hash_table_get_instance(item, ep_t, link); 82 ep->data_remove_callback(ep->data); 83 free(ep); 79 node_t *node = hash_table_get_instance(item, node_t, link); 80 endpoint_destroy(node->ep); 81 free(node); 84 82 } 85 83 /*----------------------------------------------------------------------------*/ 86 84 static hash_table_operations_t op = { 87 .hash = ep_hash,88 .compare = ep_compare,89 .remove_callback = ep_remove,85 .hash = node_hash, 86 .compare = node_compare, 87 .remove_callback = node_remove, 90 88 }; 91 89 /*----------------------------------------------------------------------------*/ … … 145 143 int usb_endpoint_manager_register_ep(usb_endpoint_manager_t *instance, 146 144 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 147 void *data, void (*data_remove_callback)(void* data), size_t bw) 148 { 145 endpoint_t *ep, size_t data_size) 146 { 147 assert(ep); 148 size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type, 149 data_size, ep->max_packet_size); 149 150 assert(instance); 150 151 … … 168 169 } 169 170 170 ep_t *ep = malloc(sizeof(ep_t));171 if ( ep== NULL) {171 node_t *node = malloc(sizeof(node_t)); 172 if (node == NULL) { 172 173 fibril_mutex_unlock(&instance->guard); 173 174 return ENOMEM; 174 175 } 175 176 176 ep->id = id; 177 ep->bw = bw; 178 ep->data = data; 179 link_initialize(&ep->link); 180 181 hash_table_insert(&instance->ep_table, (unsigned long*)&id, &ep->link); 177 node->id = id; 178 node->bw = bw; 179 node->ep = ep; 180 link_initialize(&node->link); 181 182 hash_table_insert(&instance->ep_table, 183 (unsigned long*)&id, &node->link); 182 184 instance->free_bw -= bw; 183 185 fibril_mutex_unlock(&instance->guard); … … 203 205 } 204 206 205 ep_t *ep = hash_table_get_instance(item, ep_t, link);206 instance->free_bw += ep->bw;207 node_t *node = hash_table_get_instance(item, node_t, link); 208 instance->free_bw += node->bw; 207 209 hash_table_remove(&instance->ep_table, (unsigned long*)&id, MAX_KEYS); 208 210 … … 212 214 } 213 215 /*----------------------------------------------------------------------------*/ 214 void * usb_endpoint_manager_get_ep_data(usb_endpoint_manager_t *instance,216 endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance, 215 217 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 216 218 size_t *bw) … … 229 231 return NULL; 230 232 } 231 ep_t *ep = hash_table_get_instance(item, ep_t, link);233 node_t *node = hash_table_get_instance(item, node_t, link); 232 234 if (bw) 233 *bw = ep->bw;235 *bw = node->bw; 234 236 235 237 fibril_mutex_unlock(&instance->guard); 236 return ep->data;237 } 238 return node->ep; 239 }
Note:
See TracChangeset
for help on using the changeset viewer.