multiple wait object support for win32 (kazu)

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2013 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
bellard 2006-06-25 17:18:27 +00:00
parent e15d737181
commit a18e524af0
3 changed files with 75 additions and 16 deletions

View File

@ -630,6 +630,7 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,
typedef struct TAPState { typedef struct TAPState {
VLANClientState *vc; VLANClientState *vc;
tap_win32_overlapped_t *handle; tap_win32_overlapped_t *handle;
HANDLE tap_event;
} TAPState; } TAPState;
static TAPState *tap_win32_state = NULL; static TAPState *tap_win32_state = NULL;
@ -656,6 +657,7 @@ void tap_win32_poll(void)
if (size > 0) { if (size > 0) {
qemu_send_packet(s->vc, buf, size); qemu_send_packet(s->vc, buf, size);
tap_win32_free_buffer(s->handle, buf); tap_win32_free_buffer(s->handle, buf);
SetEvent(s->tap_event);
} }
} }
@ -676,5 +678,11 @@ int tap_win32_init(VLANState *vlan, const char *ifname)
snprintf(s->vc->info_str, sizeof(s->vc->info_str), snprintf(s->vc->info_str, sizeof(s->vc->info_str),
"tap: ifname=%s", ifname); "tap: ifname=%s", ifname);
tap_win32_state = s; tap_win32_state = s;
s->tap_event = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!s->tap_event) {
fprintf(stderr, "tap-win32: Failed CreateEvent\n");
}
qemu_add_wait_object(s->tap_event, NULL, NULL);
return 0; return 0;
} }

72
vl.c
View File

@ -1014,7 +1014,7 @@ static void init_timers(void)
perror("failed CreateEvent"); perror("failed CreateEvent");
exit(1); exit(1);
} }
ResetEvent(host_alarm); qemu_add_wait_object(host_alarm, NULL, NULL);
} }
pit_min_timer_count = ((uint64_t)10000 * PIT_FREQ) / 1000000; pit_min_timer_count = ((uint64_t)10000 * PIT_FREQ) / 1000000;
#else #else
@ -3962,6 +3962,51 @@ void qemu_del_polling_cb(PollingFunc *func, void *opaque)
} }
} }
#ifdef _WIN32
/***********************************************************/
/* Wait objects support */
typedef struct WaitObjects {
int num;
HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1];
void *opaque[MAXIMUM_WAIT_OBJECTS + 1];
} WaitObjects;
static WaitObjects wait_objects = {0};
int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
{
WaitObjects *w = &wait_objects;
if (w->num >= MAXIMUM_WAIT_OBJECTS)
return -1;
w->events[w->num] = handle;
w->func[w->num] = func;
w->opaque[w->num] = opaque;
w->num++;
return 0;
}
void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
{
int i, found;
WaitObjects *w = &wait_objects;
found = 0;
for (i = 0; i < w->num; i++) {
if (w->events[i] == handle)
found = 1;
if (found) {
w->events[i] = w->events[i + 1];
w->func[i] = w->func[i + 1];
w->opaque[i] = w->opaque[i + 1];
}
}
if (found)
w->num--;
}
#endif
/***********************************************************/ /***********************************************************/
/* savevm/loadvm support */ /* savevm/loadvm support */
@ -4838,21 +4883,18 @@ void main_loop_wait(int timeout)
} }
#ifdef _WIN32 #ifdef _WIN32
if (ret == 0 && timeout > 0) { if (ret == 0 && timeout > 0) {
int err; int err;
HANDLE hEvents[1]; WaitObjects *w = &wait_objects;
hEvents[0] = host_alarm; ret = WaitForMultipleObjects(w->num, w->events, FALSE, timeout);
ret = WaitForMultipleObjects(1, hEvents, FALSE, timeout); if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) {
switch(ret) { if (w->func[ret - WAIT_OBJECT_0])
case WAIT_OBJECT_0 + 0: w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]);
break; } else if (ret == WAIT_TIMEOUT) {
case WAIT_TIMEOUT: } else {
break; err = GetLastError();
default: fprintf(stderr, "Wait error %d %d\n", ret, err);
err = GetLastError(); }
fprintf(stderr, "Wait error %d %d\n", ret, err);
break;
}
} }
#endif #endif
/* poll any events */ /* poll any events */

9
vl.h
View File

@ -47,6 +47,7 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h>
#define fsync _commit #define fsync _commit
#define lseek _lseeki64 #define lseek _lseeki64
#define ENOTSUP 4096 #define ENOTSUP 4096
@ -221,6 +222,14 @@ typedef int PollingFunc(void *opaque);
int qemu_add_polling_cb(PollingFunc *func, void *opaque); int qemu_add_polling_cb(PollingFunc *func, void *opaque);
void qemu_del_polling_cb(PollingFunc *func, void *opaque); void qemu_del_polling_cb(PollingFunc *func, void *opaque);
#ifdef _WIN32
/* Wait objects handling */
typedef void WaitObjectFunc(void *opaque);
int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
#endif
/* character device */ /* character device */
#define CHR_EVENT_BREAK 0 /* serial break char */ #define CHR_EVENT_BREAK 0 /* serial break char */