void thread_pool_free(ThreadPool *pool)

{

    if (!pool) {

        return;

    }



    assert(QLIST_EMPTY(&pool->head));



    qemu_mutex_lock(&pool->lock);



    /* Stop new threads from spawning */

    qemu_bh_delete(pool->new_thread_bh);

    pool->cur_threads -= pool->new_threads;

    pool->new_threads = 0;



    /* Wait for worker threads to terminate */

    pool->stopping = true;

    while (pool->cur_threads > 0) {

        qemu_sem_post(&pool->sem);

        qemu_cond_wait(&pool->worker_stopped, &pool->lock);

    }



    qemu_mutex_unlock(&pool->lock);



    qemu_bh_delete(pool->completion_bh);

    qemu_sem_destroy(&pool->sem);

    qemu_cond_destroy(&pool->worker_stopped);

    qemu_mutex_destroy(&pool->lock);

    g_free(pool);

}

void thread_pool_free(ThreadPool *pool)

{

    if (!pool) {

        return;

    }



    assert(QLIST_EMPTY(&pool->head));



    qemu_mutex_lock(&pool->lock);



    

    qemu_bh_delete(pool->new_thread_bh);

    pool->cur_threads -= pool->new_threads;

    pool->new_threads = 0;



    

    pool->stopping = true;

    while (pool->cur_threads > 0) {

        qemu_sem_post(&pool->sem);

        qemu_cond_wait(&pool->worker_stopped, &pool->lock);

    }



    qemu_mutex_unlock(&pool->lock);



    qemu_bh_delete(pool->completion_bh);

    qemu_sem_destroy(&pool->sem);

    qemu_cond_destroy(&pool->worker_stopped);

    qemu_mutex_destroy(&pool->lock);

    g_free(pool);

}

void FUNC_0(ThreadPool *VAR_0)

{

    if (!VAR_0) {

        return;

    }



    assert(QLIST_EMPTY(&VAR_0->head));



    qemu_mutex_lock(&VAR_0->lock);



    

    qemu_bh_delete(VAR_0->new_thread_bh);

    VAR_0->cur_threads -= VAR_0->new_threads;

    VAR_0->new_threads = 0;



    

    VAR_0->stopping = true;

    while (VAR_0->cur_threads > 0) {

        qemu_sem_post(&VAR_0->sem);

        qemu_cond_wait(&VAR_0->worker_stopped, &VAR_0->lock);

    }



    qemu_mutex_unlock(&VAR_0->lock);



    qemu_bh_delete(VAR_0->completion_bh);

    qemu_sem_destroy(&VAR_0->sem);

    qemu_cond_destroy(&VAR_0->worker_stopped);

    qemu_mutex_destroy(&VAR_0->lock);

    g_free(VAR_0);

}

void FUNC_0(ThreadPool *VAR_0)
{ if (!VAR_0) { return; } assert(QLIST_EMPTY(&VAR_0->head)); qemu_mutex_lock(&VAR_0->lock); qemu_bh_delete(VAR_0->new_thread_bh); VAR_0->cur_threads -= VAR_0->new_threads; VAR_0->new_threads = 0; VAR_0->stopping = true; while (VAR_0->cur_threads > 0) { qemu_sem_post(&VAR_0->sem); qemu_cond_wait(&VAR_0->worker_stopped, &VAR_0->lock); } qemu_mutex_unlock(&VAR_0->lock); qemu_bh_delete(VAR_0->completion_bh); qemu_sem_destroy(&VAR_0->sem); qemu_cond_destroy(&VAR_0->worker_stopped); qemu_mutex_destroy(&VAR_0->lock); g_free(VAR_0); }