static void *aio_thread(void *unused)

{

    sigset_t set;



    /* block all signals */

    sigfillset(&set);

    sigprocmask(SIG_BLOCK, &set, NULL);



    while (1) {

        struct qemu_paiocb *aiocb;

        size_t offset;

        int ret = 0;



        pthread_mutex_lock(&lock);



        while (TAILQ_EMPTY(&request_list) &&

               !(ret == ETIMEDOUT)) {

            struct timespec ts = { 0 };

            qemu_timeval tv;



            qemu_gettimeofday(&tv);

            ts.tv_sec = tv.tv_sec + 10;

            ret = pthread_cond_timedwait(&cond, &lock, &ts);

        }



        if (ret == ETIMEDOUT)

            break;



        aiocb = TAILQ_FIRST(&request_list);

        TAILQ_REMOVE(&request_list, aiocb, node);



        offset = 0;

        aiocb->active = 1;



        idle_threads--;

        pthread_mutex_unlock(&lock);



        while (offset < aiocb->aio_nbytes) {

            ssize_t len;



            if (aiocb->is_write)

                len = pwrite(aiocb->aio_fildes,

                             (const char *)aiocb->aio_buf + offset,

                             aiocb->aio_nbytes - offset,

                             aiocb->aio_offset + offset);

            else

                len = pread(aiocb->aio_fildes,

                            (char *)aiocb->aio_buf + offset,

                            aiocb->aio_nbytes - offset,

                            aiocb->aio_offset + offset);



            if (len == -1 && errno == EINTR)

                continue;

            else if (len == -1) {

                pthread_mutex_lock(&lock);

                aiocb->ret = -errno;

                pthread_mutex_unlock(&lock);

                break;

            } else if (len == 0)

                break;



            offset += len;



            pthread_mutex_lock(&lock);

            aiocb->ret = offset;

            pthread_mutex_unlock(&lock);

        }



        pthread_mutex_lock(&lock);

        idle_threads++;

        pthread_mutex_unlock(&lock);



        sigqueue(getpid(),

                 aiocb->aio_sigevent.sigev_signo,

                 aiocb->aio_sigevent.sigev_value);

    }



    idle_threads--;

    cur_threads--;

    pthread_mutex_unlock(&lock);



    return NULL;

}

static void *aio_thread(void *unused)

{

    sigset_t set;



    

    sigfillset(&set);

    sigprocmask(SIG_BLOCK, &set, NULL);



    while (1) {

        struct qemu_paiocb *aiocb;

        size_t offset;

        int ret = 0;



        pthread_mutex_lock(&lock);



        while (TAILQ_EMPTY(&request_list) &&

               !(ret == ETIMEDOUT)) {

            struct timespec ts = { 0 };

            qemu_timeval tv;



            qemu_gettimeofday(&tv);

            ts.tv_sec = tv.tv_sec + 10;

            ret = pthread_cond_timedwait(&cond, &lock, &ts);

        }



        if (ret == ETIMEDOUT)

            break;



        aiocb = TAILQ_FIRST(&request_list);

        TAILQ_REMOVE(&request_list, aiocb, node);



        offset = 0;

        aiocb->active = 1;



        idle_threads--;

        pthread_mutex_unlock(&lock);



        while (offset < aiocb->aio_nbytes) {

            ssize_t len;



            if (aiocb->is_write)

                len = pwrite(aiocb->aio_fildes,

                             (const char *)aiocb->aio_buf + offset,

                             aiocb->aio_nbytes - offset,

                             aiocb->aio_offset + offset);

            else

                len = pread(aiocb->aio_fildes,

                            (char *)aiocb->aio_buf + offset,

                            aiocb->aio_nbytes - offset,

                            aiocb->aio_offset + offset);



            if (len == -1 && errno == EINTR)

                continue;

            else if (len == -1) {

                pthread_mutex_lock(&lock);

                aiocb->ret = -errno;

                pthread_mutex_unlock(&lock);

                break;

            } else if (len == 0)

                break;



            offset += len;



            pthread_mutex_lock(&lock);

            aiocb->ret = offset;

            pthread_mutex_unlock(&lock);

        }



        pthread_mutex_lock(&lock);

        idle_threads++;

        pthread_mutex_unlock(&lock);



        sigqueue(getpid(),

                 aiocb->aio_sigevent.sigev_signo,

                 aiocb->aio_sigevent.sigev_value);

    }



    idle_threads--;

    cur_threads--;

    pthread_mutex_unlock(&lock);



    return NULL;

}

                pthread_mutex_lock(&lock);                 aiocb->ret = -errno;                 pthread_mutex_unlock(&lock);             pthread_mutex_lock(&lock);             aiocb->ret = offset;             pthread_mutex_unlock(&lock);
static void *FUNC_0(void *VAR_0)

{

    sigset_t set;



    

    sigfillset(&set);

    sigprocmask(SIG_BLOCK, &set, NULL);



    while (1) {

        struct qemu_paiocb *VAR_1;

        size_t offset;

        int VAR_2 = 0;



        pthread_mutex_lock(&lock);



        while (TAILQ_EMPTY(&request_list) &&

               !(VAR_2 == ETIMEDOUT)) {

            struct timespec VAR_3 = { 0 };

            qemu_timeval tv;



            qemu_gettimeofday(&tv);

            VAR_3.tv_sec = tv.tv_sec + 10;

            VAR_2 = pthread_cond_timedwait(&cond, &lock, &VAR_3);

        }



        if (VAR_2 == ETIMEDOUT)

            break;



        VAR_1 = TAILQ_FIRST(&request_list);

        TAILQ_REMOVE(&request_list, VAR_1, node);



        offset = 0;

        VAR_1->active = 1;



        idle_threads--;

        pthread_mutex_unlock(&lock);



        while (offset < VAR_1->aio_nbytes) {

            ssize_t len;



            if (VAR_1->is_write)

                len = pwrite(VAR_1->aio_fildes,

                             (const char *)VAR_1->aio_buf + offset,

                             VAR_1->aio_nbytes - offset,

                             VAR_1->aio_offset + offset);

            else

                len = pread(VAR_1->aio_fildes,

                            (char *)VAR_1->aio_buf + offset,

                            VAR_1->aio_nbytes - offset,

                            VAR_1->aio_offset + offset);



            if (len == -1 && errno == EINTR)

                continue;

            else if (len == -1) {

                pthread_mutex_lock(&lock);

                VAR_1->VAR_2 = -errno;

                pthread_mutex_unlock(&lock);

                break;

            } else if (len == 0)

                break;



            offset += len;



            pthread_mutex_lock(&lock);

            VAR_1->VAR_2 = offset;

            pthread_mutex_unlock(&lock);

        }



        pthread_mutex_lock(&lock);

        idle_threads++;

        pthread_mutex_unlock(&lock);



        sigqueue(getpid(),

                 VAR_1->aio_sigevent.sigev_signo,

                 VAR_1->aio_sigevent.sigev_value);

    }



    idle_threads--;

    cur_threads--;

    pthread_mutex_unlock(&lock);



    return NULL;

}

static void *FUNC_0(void *VAR_0)
{ sigset_t set; sigfillset(&set); sigprocmask(SIG_BLOCK, &set, NULL); while (1) { struct qemu_paiocb *VAR_1; size_t offset; int VAR_2 = 0; pthread_mutex_lock(&lock); while (TAILQ_EMPTY(&request_list) &&
!(VAR_2 == ETIMEDOUT)) { struct timespec VAR_3 = { 0 }; qemu_timeval tv; qemu_gettimeofday(&tv); VAR_3.tv_sec = tv.tv_sec + 10; VAR_2 = pthread_cond_timedwait(&cond, &lock, &VAR_3); } if (VAR_2 == ETIMEDOUT)
break; VAR_1 = TAILQ_FIRST(&request_list); TAILQ_REMOVE(&request_list, VAR_1, node); offset = 0; VAR_1->active = 1; idle_threads--; pthread_mutex_unlock(&lock); while (offset < VAR_1->aio_nbytes) { ssize_t len; if (VAR_1->is_write)
len = pwrite(VAR_1->aio_fildes,
(const char *)VAR_1->aio_buf + offset,
VAR_1->aio_nbytes - offset,
VAR_1->aio_offset + offset); else
len = pread(VAR_1->aio_fildes,
(char *)VAR_1->aio_buf + offset,
VAR_1->aio_nbytes - offset,
VAR_1->aio_offset + offset); if (len == -1 && errno == EINTR)
continue; else if (len == -1) { pthread_mutex_lock(&lock); VAR_1->VAR_2 = -errno; pthread_mutex_unlock(&lock); break; } else if (len == 0) break; offset += len; pthread_mutex_lock(&lock); VAR_1->VAR_2 = offset; pthread_mutex_unlock(&lock); } pthread_mutex_lock(&lock); idle_threads++; pthread_mutex_unlock(&lock); sigqueue(getpid(),
VAR_1->aio_sigevent.sigev_signo,
VAR_1->aio_sigevent.sigev_value); } idle_threads--; cur_threads--; pthread_mutex_unlock(&lock); return NULL; }