Changeset f527f58 in mainline
- Timestamp:
- 2016-08-03T11:12:24Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 96ef672
- Parents:
- e657635
- Location:
- uspace/lib/usbhost
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/endpoint.h
re657635 rf527f58 40 40 #include <fibril_synch.h> 41 41 #include <usb/usb.h> 42 #include <atomic.h> 42 43 43 44 /** Host controller side endpoint structure. */ 44 45 typedef struct endpoint { 46 /** Reference count. */ 47 atomic_t refcnt; 45 48 /** Part of linked list. */ 46 49 link_t link; … … 91 94 void endpoint_destroy(endpoint_t *instance); 92 95 96 void endpoint_add_ref(endpoint_t *instance); 97 void endpoint_del_ref(endpoint_t *instance); 98 93 99 void endpoint_set_hc_data(endpoint_t *instance, 94 100 void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int)); -
uspace/lib/usbhost/src/endpoint.c
re657635 rf527f58 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 /** @addtogroup libusbhost 29 30 * @{ … … 37 38 #include <assert.h> 38 39 #include <stdlib.h> 40 #include <atomic.h> 39 41 40 42 /** Allocate ad initialize endpoint_t structure. … … 55 57 endpoint_t *instance = malloc(sizeof(endpoint_t)); 56 58 if (instance) { 59 atomic_set(&instance->refcnt, 0); 57 60 instance->address = address; 58 61 instance->endpoint = endpoint; … … 83 86 { 84 87 assert(instance); 85 //TODO: Do something about waiting fibrils.86 88 assert(!instance->active); 87 89 assert(instance->hc_data.data == NULL); 88 90 free(instance); 91 } 92 93 void endpoint_add_ref(endpoint_t *instance) 94 { 95 atomic_inc(&instance->refcnt); 96 } 97 98 void endpoint_del_ref(endpoint_t *instance) 99 { 100 if (atomic_predec(&instance->refcnt) == 0) 101 endpoint_destroy(instance); 89 102 } 90 103 … … 122 135 { 123 136 assert(instance); 137 /* Add reference for active endpoint. */ 138 endpoint_add_ref(instance); 124 139 fibril_mutex_lock(&instance->guard); 125 140 while (instance->active) … … 139 154 fibril_mutex_unlock(&instance->guard); 140 155 fibril_condvar_signal(&instance->avail); 156 /* Drop reference for active endpoint. */ 157 endpoint_del_ref(instance); 141 158 } 142 159 … … 171 188 fibril_mutex_unlock(&instance->guard); 172 189 } 190 173 191 /** 174 192 * @} -
uspace/lib/usbhost/src/hcd.c
re657635 rf527f58 241 241 usb_transfer_batch_destroy(batch); 242 242 243 /* Drop our own reference to ep. */ 244 endpoint_del_ref(ep); 245 243 246 return ret; 244 247 } -
uspace/lib/usbhost/src/usb_bus.c
re657635 rf527f58 242 242 return EEXIST; 243 243 } 244 /* Add endpoint list's reference to ep. */ 245 endpoint_add_ref(ep); 244 246 list_append(&ep->link, get_list(instance, ep->address)); 245 247 … … 274 276 ep->endpoint, usb_str_transfer_type_short(ep->transfer_type), 275 277 usb_str_direction(ep->direction)); 278 /* Drop endpoint list's reference to ep. */ 279 endpoint_del_ref(ep); 276 280 fibril_mutex_unlock(&instance->guard); 277 281 return EOK; … … 289 293 fibril_mutex_lock(&instance->guard); 290 294 endpoint_t *ep = find_locked(instance, address, endpoint, direction); 295 if (ep) { 296 /* We are exporting ep to the outside world, add reference. */ 297 endpoint_add_ref(ep); 298 } 291 299 fibril_mutex_unlock(&instance->guard); 292 300 return ep; … … 350 358 } 351 359 360 /* Add our reference to ep. */ 361 endpoint_add_ref(ep); 362 352 363 if (callback) { 353 364 const int ret = callback(ep, arg); 354 365 if (ret != EOK) { 355 366 fibril_mutex_unlock(&instance->guard); 356 endpoint_de stroy(ep);367 endpoint_del_ref(ep); 357 368 return ret; 358 369 } 359 370 } 371 372 /* Add endpoint list's reference to ep. */ 373 endpoint_add_ref(ep); 360 374 list_append(&ep->link, get_list(instance, ep->address)); 361 375 362 376 instance->free_bw -= ep->bandwidth; 363 377 fibril_mutex_unlock(&instance->guard); 378 379 /* Drop our reference to ep. */ 380 endpoint_del_ref(ep); 381 364 382 return EOK; 365 383 } … … 392 410 callback(ep, arg); 393 411 } 394 endpoint_destroy(ep); 412 /* Drop endpoint list's reference to ep. */ 413 endpoint_del_ref(ep); 395 414 return EOK; 396 415 } … … 445 464 if (callback) 446 465 callback(ep, arg); 447 endpoint_destroy(ep); 466 /* Drop endpoint list's reference to ep. */ 467 endpoint_del_ref(ep); 448 468 } 449 469 }
Note:
See TracChangeset
for help on using the changeset viewer.