Revision 06ac7d49 main-loop.c

b/main-loop.c
220 220

  
221 221
static fd_set rfds, wfds, xfds;
222 222
static int nfds;
223
static GPollFD poll_fds[1024 * 2]; /* this is probably overkill */
223 224

  
224 225
#ifndef _WIN32
225
static GPollFD poll_fds[1024 * 2]; /* this is probably overkill */
226 226
static int n_poll_fds;
227 227
static int max_priority;
228 228

  
......
351 351
/* Wait objects support */
352 352
typedef struct WaitObjects {
353 353
    int num;
354
    int revents[MAXIMUM_WAIT_OBJECTS + 1];
354 355
    HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
355 356
    WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1];
356 357
    void *opaque[MAXIMUM_WAIT_OBJECTS + 1];
......
367 368
    w->events[w->num] = handle;
368 369
    w->func[w->num] = func;
369 370
    w->opaque[w->num] = opaque;
371
    w->revents[w->num] = 0;
370 372
    w->num++;
371 373
    return 0;
372 374
}
......
385 387
            w->events[i] = w->events[i + 1];
386 388
            w->func[i] = w->func[i + 1];
387 389
            w->opaque[i] = w->opaque[i + 1];
390
            w->revents[i] = w->revents[i + 1];
388 391
        }
389 392
    }
390 393
    if (found) {
......
400 403

  
401 404
static int os_host_main_loop_wait(int timeout)
402 405
{
403
    int ret, ret2, i;
406
    int ret, i;
404 407
    PollingEntry *pe;
405
    int err;
406 408
    WaitObjects *w = &wait_objects;
407 409
    static struct timeval tv0;
408 410

  
......
422 424
        }
423 425
    }
424 426

  
427
    for (i = 0; i < w->num; i++) {
428
        poll_fds[i].fd = (DWORD) w->events[i];
429
        poll_fds[i].events = G_IO_IN;
430
    }
431

  
425 432
    qemu_mutex_unlock_iothread();
426
    ret = WaitForMultipleObjects(w->num, w->events, FALSE, timeout);
433
    ret = g_poll(poll_fds, w->num, timeout);
427 434
    qemu_mutex_lock_iothread();
428
    if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) {
429
        if (w->func[ret - WAIT_OBJECT_0]) {
430
            w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]);
435
    if (ret > 0) {
436
        for (i = 0; i < w->num; i++) {
437
            w->revents[i] = poll_fds[i].revents;
431 438
        }
432

  
433
        /* Check for additional signaled events */
434
        for (i = (ret - WAIT_OBJECT_0 + 1); i < w->num; i++) {
435
            /* Check if event is signaled */
436
            ret2 = WaitForSingleObject(w->events[i], 0);
437
            if (ret2 == WAIT_OBJECT_0) {
438
                if (w->func[i]) {
439
                    w->func[i](w->opaque[i]);
440
                }
441
            } else if (ret2 != WAIT_TIMEOUT) {
442
                err = GetLastError();
443
                fprintf(stderr, "WaitForSingleObject error %d %d\n", i, err);
439
        for (i = 0; i < w->num; i++) {
440
            if (w->revents[i] && w->func[i]) {
441
                w->func[i](w->opaque[i]);
444 442
            }
445 443
        }
446
    } else if (ret != WAIT_TIMEOUT) {
447
        err = GetLastError();
448
        fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err);
449 444
    }
450 445

  
451

  
452 446
    /* If an edge-triggered socket event occurred, select will return a
453 447
     * positive result on the next iteration.  We do not need to do anything
454 448
     * here.

Also available in: Unified diff