Changeset f527f58 in mainline for uspace/lib/usbhost/src/endpoint.c


Ignore:
Timestamp:
2016-08-03T11:12:24Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
96ef672
Parents:
e657635
Message:

Reference-count endpoint_t structures

Track explicit references to USB endpoints. Call endpoint_destroy()
only after the last reference is destroyed. This prevents the scenario
in which removal was attempted on an endpoint while there was a transfer
in progress.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/endpoint.c

    re657635 rf527f58  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/** @addtogroup libusbhost
    2930 * @{
     
    3738#include <assert.h>
    3839#include <stdlib.h>
     40#include <atomic.h>
    3941
    4042/** Allocate ad initialize endpoint_t structure.
     
    5557        endpoint_t *instance = malloc(sizeof(endpoint_t));
    5658        if (instance) {
     59                atomic_set(&instance->refcnt, 0);
    5760                instance->address = address;
    5861                instance->endpoint = endpoint;
     
    8386{
    8487        assert(instance);
    85         //TODO: Do something about waiting fibrils.
    8688        assert(!instance->active);
    8789        assert(instance->hc_data.data == NULL);
    8890        free(instance);
     91}
     92
     93void endpoint_add_ref(endpoint_t *instance)
     94{
     95        atomic_inc(&instance->refcnt);
     96}
     97
     98void endpoint_del_ref(endpoint_t *instance)
     99{
     100        if (atomic_predec(&instance->refcnt) == 0)
     101                endpoint_destroy(instance);
    89102}
    90103
     
    122135{
    123136        assert(instance);
     137        /* Add reference for active endpoint. */
     138        endpoint_add_ref(instance);
    124139        fibril_mutex_lock(&instance->guard);
    125140        while (instance->active)
     
    139154        fibril_mutex_unlock(&instance->guard);
    140155        fibril_condvar_signal(&instance->avail);
     156        /* Drop reference for active endpoint. */
     157        endpoint_del_ref(instance);
    141158}
    142159
     
    171188        fibril_mutex_unlock(&instance->guard);
    172189}
     190
    173191/**
    174192 * @}
Note: See TracChangeset for help on using the changeset viewer.