Revision 31d4ee6c
b/vl.c | ||
---|---|---|
1557 | 1557 |
void *opaque; |
1558 | 1558 |
/* temporary data */ |
1559 | 1559 |
struct pollfd *ufd; |
1560 |
struct IOHandlerRecord *next;
|
|
1560 |
QLIST_ENTRY(IOHandlerRecord) next;
|
|
1561 | 1561 |
} IOHandlerRecord; |
1562 | 1562 |
|
1563 |
static IOHandlerRecord *first_io_handler; |
|
1563 |
static QLIST_HEAD(, IOHandlerRecord) io_handlers = |
|
1564 |
QLIST_HEAD_INITIALIZER(io_handlers); |
|
1565 |
|
|
1564 | 1566 |
|
1565 | 1567 |
/* XXX: fd_read_poll should be suppressed, but an API change is |
1566 | 1568 |
necessary in the character devices to suppress fd_can_read(). */ |
... | ... | |
1570 | 1572 |
IOHandler *fd_write, |
1571 | 1573 |
void *opaque) |
1572 | 1574 |
{ |
1573 |
IOHandlerRecord **pioh, *ioh;
|
|
1575 |
IOHandlerRecord *ioh; |
|
1574 | 1576 |
|
1575 | 1577 |
if (!fd_read && !fd_write) { |
1576 |
pioh = &first_io_handler; |
|
1577 |
for(;;) { |
|
1578 |
ioh = *pioh; |
|
1579 |
if (ioh == NULL) |
|
1580 |
break; |
|
1578 |
QLIST_FOREACH(ioh, &io_handlers, next) { |
|
1581 | 1579 |
if (ioh->fd == fd) { |
1582 | 1580 |
ioh->deleted = 1; |
1583 | 1581 |
break; |
1584 | 1582 |
} |
1585 |
pioh = &ioh->next; |
|
1586 | 1583 |
} |
1587 | 1584 |
} else { |
1588 |
for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
|
|
1585 |
QLIST_FOREACH(ioh, &io_handlers, next) {
|
|
1589 | 1586 |
if (ioh->fd == fd) |
1590 | 1587 |
goto found; |
1591 | 1588 |
} |
1592 | 1589 |
ioh = qemu_mallocz(sizeof(IOHandlerRecord)); |
1593 |
ioh->next = first_io_handler; |
|
1594 |
first_io_handler = ioh; |
|
1590 |
QLIST_INSERT_HEAD(&io_handlers, ioh, next); |
|
1595 | 1591 |
found: |
1596 | 1592 |
ioh->fd = fd; |
1597 | 1593 |
ioh->fd_read_poll = fd_read_poll; |
... | ... | |
2812 | 2808 |
FD_ZERO(&rfds); |
2813 | 2809 |
FD_ZERO(&wfds); |
2814 | 2810 |
FD_ZERO(&xfds); |
2815 |
for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
|
|
2811 |
QLIST_FOREACH(ioh, &io_handlers, next) {
|
|
2816 | 2812 |
if (ioh->deleted) |
2817 | 2813 |
continue; |
2818 | 2814 |
if (ioh->fd_read && |
... | ... | |
2838 | 2834 |
ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv); |
2839 | 2835 |
qemu_mutex_lock_iothread(); |
2840 | 2836 |
if (ret > 0) { |
2841 |
IOHandlerRecord **pioh;
|
|
2837 |
IOHandlerRecord *pioh; |
|
2842 | 2838 |
|
2843 |
for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
|
|
2839 |
QLIST_FOREACH(ioh, &io_handlers, next) {
|
|
2844 | 2840 |
if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) { |
2845 | 2841 |
ioh->fd_read(ioh->opaque); |
2846 | 2842 |
} |
... | ... | |
2850 | 2846 |
} |
2851 | 2847 |
|
2852 | 2848 |
/* remove deleted IO handlers */ |
2853 |
pioh = &first_io_handler; |
|
2854 |
while (*pioh) { |
|
2855 |
ioh = *pioh; |
|
2849 |
QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) { |
|
2856 | 2850 |
if (ioh->deleted) { |
2857 |
*pioh = ioh->next;
|
|
2851 |
QLIST_REMOVE(ioh, next);
|
|
2858 | 2852 |
qemu_free(ioh); |
2859 |
} else |
|
2860 |
pioh = &ioh->next; |
|
2853 |
} |
|
2861 | 2854 |
} |
2862 | 2855 |
} |
2863 | 2856 |
|
Also available in: Unified diff