PERFORCE change 165479 for review
Sylvestre Gallon
syl at FreeBSD.org
Tue Jun 30 19:21:49 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=165479
Change 165479 by syl at syl_atuin on 2009/06/30 19:21:11
Replace libusb list by queue(3).
Affected files ...
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb.h#14 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#52 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.h#13 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#18 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_io.c#20 edit
Differences ...
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb.h#14 (text+ko) ====
@@ -26,14 +26,16 @@
#ifndef __LIBUSB_H__
#define __LIBUSB_H__
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/queue.h>
+
#include <stdint.h>
#include <time.h>
#include <string.h>
#include <pthread.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/endian.h>
#ifdef __cplusplus
extern "C" {
@@ -43,10 +45,6 @@
#endif
-struct list_head {
- struct list_head *prev, *next;
-};
-
/* libusb enums */
enum libusb_class_code {
@@ -182,6 +180,26 @@
LIBUSB_DEBUG_TRANSFER=2,
};
+/* internal structures */
+
+typedef struct libusb_pollfd {
+ int fd;
+ short events;
+} libusb_pollfd;
+
+struct usb_pollfd {
+ TAILQ_ENTRY(usb_pollfd) list;
+ struct libusb_pollfd pollfd;
+};
+
+struct usb_transfer {
+ TAILQ_ENTRY(usb_transfer) list;
+ int num_iso_packets;
+ struct timeval timeout;
+ int transferred;
+ uint8_t flags;
+};
+
/* libusb structures */
typedef void (*libusb_pollfd_added_cb) (int fd, short events, void *user_data);
@@ -193,16 +211,16 @@
int ctrl_pipe[2];
- struct list_head usb_devs;
+ TAILQ_HEAD(usb_devs_list, libusb_device) usb_devs;
pthread_mutex_t usb_devs_lock;
- struct list_head open_devs;
+ TAILQ_HEAD(open_devs_list, libusb_device_handle) open_devs;
pthread_mutex_t open_devs_lock;
- struct list_head flying_transfers;
+ TAILQ_HEAD(flying_transfers_list, usb_transfer) flying_transfers;
pthread_mutex_t flying_transfers_lock;
- struct list_head pollfds;
+ TAILQ_HEAD(pollfds_list, usb_pollfd) pollfds;
pthread_mutex_t pollfds_lock;
unsigned int pollfd_modify;
@@ -229,7 +247,7 @@
uint8_t device_address;
uint8_t num_configurations;
- struct list_head list;
+ TAILQ_ENTRY(libusb_device) list;
unsigned long session_data;
void *os_priv;
} libusb_device;
@@ -238,7 +256,7 @@
pthread_mutex_t lock;
unsigned long claimed_interfaces;
- struct list_head list;
+ TAILQ_ENTRY(libusb_device_handle) list;
struct libusb_device *dev;
void *os_priv;
} libusb_device_handle;
@@ -342,11 +360,6 @@
struct libusb_iso_packet_descriptor iso_packet_desc[0];
} libusb_transfer __aligned(sizeof(void *));
-typedef struct libusb_pollfd {
- int fd;
- short events;
-} libusb_pollfd;
-
/* Library initialisation */
void libusb_set_debug(libusb_context * ctx, int level);
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#52 (text+ko) ====
@@ -74,8 +74,8 @@
pthread_mutex_init(&ctx->usb_devs_lock, NULL);
pthread_mutex_init(&ctx->open_devs_lock, NULL);
- USB_LIST_INIT(&ctx->usb_devs);
- USB_LIST_INIT(&ctx->open_devs);
+ TAILQ_INIT(&ctx->usb_devs);
+ TAILQ_INIT(&ctx->open_devs);
pthread_mutex_init(&ctx->flying_transfers_lock, NULL);
pthread_mutex_init(&ctx->pollfds_lock, NULL);
@@ -84,8 +84,8 @@
pthread_mutex_init(&ctx->event_waiters_lock, NULL);
pthread_cond_init(&ctx->event_waiters_cond, NULL);
- USB_LIST_INIT(&ctx->flying_transfers);
- USB_LIST_INIT(&ctx->pollfds);
+ TAILQ_INIT(&ctx->flying_transfers);
+ TAILQ_INIT(&ctx->pollfds);
ret = pipe(ctx->ctrl_pipe);
if (ret < 0) {
@@ -197,7 +197,7 @@
dev->os_priv = pdev;
pthread_mutex_lock(&ctx->usb_devs_lock);
- LIST_ADD(&dev->list, &ctx->usb_devs);
+ TAILQ_INSERT_HEAD(&ctx->usb_devs, dev, list);
pthread_mutex_unlock(&ctx->usb_devs_lock);
(*list)[i] = libusb_ref_device(dev);
@@ -344,7 +344,7 @@
if (dev->refcnt == 0) {
pthread_mutex_lock(&dev->ctx->usb_devs_lock);
- LIST_DEL(&dev->list);
+ TAILQ_REMOVE(&ctx->usb_devs, dev, list);
pthread_mutex_unlock(&dev->ctx->usb_devs_lock);
libusb20_dev_free(dev->os_priv);
@@ -393,7 +393,7 @@
}
pthread_mutex_lock(&ctx->open_devs_lock);
- LIST_ADD(&hdl->list, &ctx->open_devs);
+ TAILQ_INSERT_HEAD(&ctx->open_devs, hdl, list);
pthread_mutex_unlock(&ctx->open_devs_lock);
*devh = hdl;
@@ -480,7 +480,7 @@
if (err <= 0) {
pthread_mutex_lock(&ctx->open_devs_lock);
- LIST_DEL(&devh->list);
+ TAILQ_REMOVE(&ctx->open_devs, devh, list);
pthread_mutex_unlock(&ctx->open_devs_lock);
usb_remove_pollfd(ctx, libusb20_dev_get_fd(pdev));
@@ -497,7 +497,7 @@
read(ctx->ctrl_pipe[0], &dummy, sizeof(dummy));
pthread_mutex_lock(&ctx->open_devs_lock);
- LIST_DEL(&devh->list);
+ TAILQ_REMOVE(&ctx->open_devs, devh, list);
pthread_mutex_unlock(&ctx->open_devs_lock);
usb_remove_pollfd(ctx, libusb20_dev_get_fd(pdev));
@@ -1046,25 +1046,27 @@
/*Add to flying list*/
pthread_mutex_lock(&ctx->flying_transfers_lock);
- if (USB_LIST_EMPTY(&ctx->flying_transfers)) {
- LIST_ADD(&usb_backend->list, &ctx->flying_transfers);
+ if (TAILQ_EMPTY(&ctx->flying_transfers)) {
+ TAILQ_INSERT_HEAD(&ctx->flying_transfers, usb_backend, list);
goto out;
}
if (timerisset(&usb_backend->timeout) == 0) {
- LIST_ADD_TAIL(&usb_backend->list, &ctx->flying_transfers);
+ TAILQ_INSERT_HEAD(&ctx->flying_transfers, usb_backend, list);
goto out;
}
- LIST_FOREACH_ENTRY(usb_node, &ctx->flying_transfers, list) {
+ TAILQ_FOREACH(usb_node, &ctx->flying_transfers, list) {
cur_tv = &usb_node->timeout;
if (timerisset(cur_tv) == 0 ||
(cur_tv->tv_sec > usb_backend->timeout.tv_sec) ||
(cur_tv->tv_sec == usb_backend->timeout.tv_sec &&
cur_tv->tv_usec > usb_backend->timeout.tv_usec)) {
- LIST_ADD_TAIL(&usb_backend->list, &usb_node->list);
+ /*XXX need to check with libusb-1*/
+ TAILQ_INSERT_TAIL(&ctx->flying_transfers, usb_node, list);
goto out;
}
}
- LIST_ADD_TAIL(&usb_backend->list, &ctx->flying_transfers);
+ /*XXX*/
+ TAILQ_INSERT_TAIL(&ctx->flying_transfers, usb_backend, list);
out:
pthread_mutex_unlock(&ctx->flying_transfers_lock);
@@ -1093,7 +1095,7 @@
if (ret != 0) {
pthread_mutex_unlock(&libusb20_lock);
pthread_mutex_lock(&ctx->flying_transfers_lock);
- LIST_DEL(&usb_backend->list);
+ TAILQ_REMOVE(&ctx->flying_transfers, usb_backend, list);
pthread_mutex_unlock(&ctx->flying_transfers_lock);
return (LIBUSB_ERROR_OTHER);
}
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.h#13 (text+ko) ====
@@ -30,37 +30,7 @@
* The two following macros were taken from the original LibUSB v1.0
* for sake of compatibility:
*/
-#define USB_LIST_INIT(entry) \
- (entry)->prev = (entry)->next = entry;
-#define USB_LIST_EMPTY(entry) \
- ((entry)->next = (entry))
-
-#define LIST_ADD(entry, head) \
- (entry)->next = (head)->next; \
- (entry)->prev = (head); \
- (head)->next->prev = (entry); \
- (head)->next = (entry);
-#define LIST_ADD_TAIL(entry, head) \
- (entry)->next = (head); \
- (entry)->prev = (head)->prev; \
- (head)->prev->next = (entry); \
- (head)->prev = (entry);
-#define LIST_DEL(entry) \
- (entry)->next->prev = (entry)->prev; \
- (entry)->prev->next = (entry)->next;
-#define LIST_ENT(ptr, type, member) \
- ((type *)((char *)(ptr) - (unsigned long) (&((type*)0L)->member)))
-#define LIST_FOREACH_ENTRY(pos, head, member) \
- for (pos = LIST_ENT((head)->next, typeof(*pos), member) ; \
- &pos->member != head ; \
- pos = LIST_ENT(pos->member.next, typeof(*pos), member))
-#define LIST_FOREACH_ENTRY_SAFE(pos, n, head, member) \
- for (pos = LIST_ENT((head)->next, typeof(*pos), member), \
- n = LIST_ENT(pos->member.next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = n, n = LIST_ENT(n->member.next, typeof(*n), member))
-
static int get_next_timeout(libusb_context *ctx, struct timeval *tv, struct timeval *out);
static int handle_timeouts(struct libusb_context *ctx);
static int handle_events(struct libusb_context *ctx, struct timeval *tv);
@@ -76,19 +46,6 @@
#define USB_TIMED_OUT (1<<0)
#define UNEXPORTED __attribute__((__visibility__("hidden")))
-struct usb_pollfd {
- struct libusb_pollfd pollfd;
- struct list_head list;
-};
-
-struct usb_transfer {
- int num_iso_packets;
- struct list_head list;
- struct timeval timeout;
- int transferred;
- uint8_t flags;
-};
-
#define DPRINTF(ctx, dbg, format, args...) \
if (ctx->debug == dbg) { \
printf("LIBUSB_%s : ", (ctx->debug == LIBUSB_DEBUG_FUNCTION) ? "FUNCTION" : "TRANSFER"); \
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#18 (text+ko) ====
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_io.c#20 (text+ko) ====
@@ -54,7 +54,7 @@
pollfd->pollfd.events = events;
pthread_mutex_lock(&ctx->pollfds_lock);
- LIST_ADD_TAIL(&pollfd->list, &ctx->pollfds);
+ TAILQ_INSERT_TAIL(&ctx->pollfds, pollfd, list);
pthread_mutex_unlock(&ctx->pollfds_lock);
if (ctx->fd_added_cb)
@@ -71,7 +71,7 @@
found = 0;
pthread_mutex_lock(&ctx->pollfds_lock);
- LIST_FOREACH_ENTRY(pollfd, &ctx->pollfds, list) {
+ TAILQ_FOREACH(pollfd, &ctx->pollfds, list) {
if (pollfd->pollfd.fd == fd) {
found = 1;
break ;
@@ -83,7 +83,7 @@
return ;
}
- LIST_DEL(&pollfd->list);
+ TAILQ_REMOVE(&ctx->pollfds, pollfd, list);
pthread_mutex_unlock(&ctx->pollfds_lock);
free(pollfd);
@@ -104,7 +104,7 @@
ctx = xfer->dev_handle->dev->ctx;
pthread_mutex_lock(&ctx->flying_transfers_lock);
- LIST_DEL(&uxfer->list);
+ TAILQ_REMOVE(&ctx->flying_transfers, uxfer, list);
pthread_mutex_unlock(&ctx->flying_transfers_lock);
if (status == LIBUSB_TRANSFER_COMPLETED && xfer->flags &
@@ -145,7 +145,7 @@
while (1) {
pthread_mutex_lock(&ctx->flying_transfers_lock);
to_cancel = NULL;
- LIST_FOREACH_ENTRY(cur, &ctx->flying_transfers, list) {
+ TAILQ_FOREACH(cur, &ctx->flying_transfers, list) {
xfer = (struct libusb_transfer *) ((uint8_t *)cur +
sizeof(struct usb_transfer));
if (xfer->dev_handle == devh) {
@@ -199,13 +199,13 @@
ret = 0;
pthread_mutex_lock(&ctx->flying_transfers_lock);
- if (USB_LIST_EMPTY(&ctx->flying_transfers))
+ if (TAILQ_EMPTY(&ctx->flying_transfers))
goto out;
ret = clock_gettime(CLOCK_MONOTONIC, &sys_ts);
TIMESPEC_TO_TIMEVAL(&sys_tv, &sys_ts);
- LIST_FOREACH_ENTRY(xfer, &ctx->flying_transfers, list) {
+ TAILQ_FOREACH(xfer, &ctx->flying_transfers, list) {
cur_tv = &xfer->timeout;
if (timerisset(cur_tv) == 0)
@@ -253,14 +253,14 @@
i = -1;
pthread_mutex_lock(&ctx->pollfds_lock);
- LIST_FOREACH_ENTRY(ipollfd, &ctx->pollfds, list)
+ TAILQ_FOREACH(ipollfd, &ctx->pollfds, list)
nfds++;
fds = malloc(sizeof(*fds) * nfds);
if (fds == NULL)
return (LIBUSB_ERROR_NO_MEM);
- LIST_FOREACH_ENTRY(ipollfd, &ctx->pollfds, list) {
+ TAILQ_FOREACH(ipollfd, &ctx->pollfds, list) {
tmppollfd = &ipollfd->pollfd;
tmpfd = tmppollfd->fd;
i++;
@@ -305,7 +305,7 @@
continue;
ret--;
- LIST_FOREACH_ENTRY(devh, &ctx->open_devs, list) {
+ TAILQ_FOREACH(devh, &ctx->open_devs, list) {
if (libusb20_dev_get_fd(devh->os_priv) == tfds->fd)
break ;
}
@@ -582,12 +582,12 @@
found = 0;
pthread_mutex_lock(&ctx->flying_transfers_lock);
- if (USB_LIST_EMPTY(&ctx->flying_transfers)) {
+ if (TAILQ_EMPTY(&ctx->flying_transfers)) {
pthread_mutex_unlock(&ctx->flying_transfers_lock);
return (0);
}
- LIST_FOREACH_ENTRY(xfer, &ctx->flying_transfers, list) {
+ TAILQ_FOREACH(xfer, &ctx->flying_transfers, list) {
if (!(xfer->flags & USB_TIMED_OUT)) {
found = 1;
break ;
@@ -644,7 +644,7 @@
i = 0;
pthread_mutex_lock(&ctx->pollfds_lock);
- LIST_FOREACH_ENTRY(pollfd, &ctx->pollfds, list)
+ TAILQ_FOREACH(pollfd, &ctx->pollfds, list)
i++;
ret = calloc(i + 1 , sizeof(struct libusb_pollfd *));
@@ -654,7 +654,7 @@
}
i = 0;
- LIST_FOREACH_ENTRY(pollfd, &ctx->pollfds, list)
+ TAILQ_FOREACH(pollfd, &ctx->pollfds, list)
ret[i++] = (struct libusb_pollfd *) pollfd;
ret[i] = NULL;
More information about the p4-projects
mailing list