void os_host_main_loop_wait(int *timeout)

{

    int ret, ret2, i;

    PollingEntry *pe;



    /* XXX: need to suppress polling by better using win32 events */

    ret = 0;

    for(pe = first_polling_entry; pe != NULL; pe = pe->next) {

        ret |= pe->func(pe->opaque);

    }

    if (ret == 0) {

        int err;

        WaitObjects *w = &wait_objects;



        qemu_mutex_unlock_iothread();

        ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout);

        qemu_mutex_lock_iothread();

        if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) {

            if (w->func[ret - WAIT_OBJECT_0])

                w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]);



            /* Check for additional signaled events */

            for(i = (ret - WAIT_OBJECT_0 + 1); i < w->num; i++) {



                /* Check if event is signaled */

                ret2 = WaitForSingleObject(w->events[i], 0);

                if(ret2 == WAIT_OBJECT_0) {

                    if (w->func[i])

                        w->func[i](w->opaque[i]);

                } else if (ret2 == WAIT_TIMEOUT) {

                } else {

                    err = GetLastError();

                    fprintf(stderr, "WaitForSingleObject error %d %d\n", i, err);

                }

            }

        } else if (ret == WAIT_TIMEOUT) {

        } else {

            err = GetLastError();

            fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err);

        }

    }



    *timeout = 0;

}

void os_host_main_loop_wait(int *timeout)

{

    int ret, ret2, i;

    PollingEntry *pe;



    

    ret = 0;

    for(pe = first_polling_entry; pe != NULL; pe = pe->next) {

        ret |= pe->func(pe->opaque);

    }

    if (ret == 0) {

        int err;

        WaitObjects *w = &wait_objects;



        qemu_mutex_unlock_iothread();

        ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout);

        qemu_mutex_lock_iothread();

        if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) {

            if (w->func[ret - WAIT_OBJECT_0])

                w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]);



            

            for(i = (ret - WAIT_OBJECT_0 + 1); i < w->num; i++) {



                

                ret2 = WaitForSingleObject(w->events[i], 0);

                if(ret2 == WAIT_OBJECT_0) {

                    if (w->func[i])

                        w->func[i](w->opaque[i]);

                } else if (ret2 == WAIT_TIMEOUT) {

                } else {

                    err = GetLastError();

                    fprintf(stderr, "WaitForSingleObject error %d %d\n", i, err);

                }

            }

        } else if (ret == WAIT_TIMEOUT) {

        } else {

            err = GetLastError();

            fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err);

        }

    }



    *timeout = 0;

}

void FUNC_0(int *VAR_0)

{

    int VAR_1, VAR_2, VAR_3;

    PollingEntry *pe;



    

    VAR_1 = 0;

    for(pe = first_polling_entry; pe != NULL; pe = pe->next) {

        VAR_1 |= pe->func(pe->opaque);

    }

    if (VAR_1 == 0) {

        int VAR_4;

        WaitObjects *w = &wait_objects;



        qemu_mutex_unlock_iothread();

        VAR_1 = WaitForMultipleObjects(w->num, w->events, FALSE, *VAR_0);

        qemu_mutex_lock_iothread();

        if (WAIT_OBJECT_0 + 0 <= VAR_1 && VAR_1 <= WAIT_OBJECT_0 + w->num - 1) {

            if (w->func[VAR_1 - WAIT_OBJECT_0])

                w->func[VAR_1 - WAIT_OBJECT_0](w->opaque[VAR_1 - WAIT_OBJECT_0]);



            

            for(VAR_3 = (VAR_1 - WAIT_OBJECT_0 + 1); VAR_3 < w->num; VAR_3++) {



                

                VAR_2 = WaitForSingleObject(w->events[VAR_3], 0);

                if(VAR_2 == WAIT_OBJECT_0) {

                    if (w->func[VAR_3])

                        w->func[VAR_3](w->opaque[VAR_3]);

                } else if (VAR_2 == WAIT_TIMEOUT) {

                } else {

                    VAR_4 = GetLastError();

                    fprintf(stderr, "WaitForSingleObject error %d %d\n", VAR_3, VAR_4);

                }

            }

        } else if (VAR_1 == WAIT_TIMEOUT) {

        } else {

            VAR_4 = GetLastError();

            fprintf(stderr, "WaitForMultipleObjects error %d %d\n", VAR_1, VAR_4);

        }

    }



    *VAR_0 = 0;

}

void FUNC_0(int *VAR_0)
{ int VAR_1, VAR_2, VAR_3; PollingEntry *pe; VAR_1 = 0; for(pe = first_polling_entry; pe != NULL; pe = pe->next) { VAR_1 |= pe->func(pe->opaque); } if (VAR_1 == 0) { int VAR_4; WaitObjects *w = &wait_objects; qemu_mutex_unlock_iothread(); VAR_1 = WaitForMultipleObjects(w->num, w->events, FALSE, *VAR_0); qemu_mutex_lock_iothread(); if (WAIT_OBJECT_0 + 0 <= VAR_1 && VAR_1 <= WAIT_OBJECT_0 + w->num - 1) { if (w->func[VAR_1 - WAIT_OBJECT_0])
w->func[VAR_1 - WAIT_OBJECT_0](w->opaque[VAR_1 - WAIT_OBJECT_0]); for(VAR_3 = (VAR_1 - WAIT_OBJECT_0 + 1); VAR_3 < w->num; VAR_3++) { VAR_2 = WaitForSingleObject(w->events[VAR_3], 0); if(VAR_2 == WAIT_OBJECT_0) { if (w->func[VAR_3])
w->func[VAR_3](w->opaque[VAR_3]); } else if (VAR_2 == WAIT_TIMEOUT) { } else { VAR_4 = GetLastError(); fprintf(stderr, "WaitForSingleObject error %d %d\n", VAR_3, VAR_4); } } } else if (VAR_1 == WAIT_TIMEOUT) { } else { VAR_4 = GetLastError(); fprintf(stderr, "WaitForMultipleObjects error %d %d\n", VAR_1, VAR_4); } } *VAR_0 = 0; }