// File: /workspace/github_c_makefile_star2_O0/sszllzss[P]webSocket_Libevent_ThreadPool/Threadpool.cpp
// Function: threadpool_create(int)
threadpool_t *threadpool_create(int min_thr_num)
{
    threadpool_t *pool=NULL;
    int i;
    do{
        /*  开辟threadpool结构内存空间   */
        if((pool = (threadpool_t *) malloc(sizeof(threadpool_t)))==NULL)
        {
            De_perror("malloci thrread fail");
            break;
        }
        /* 清空线程池结构体 */
        memset(pool, 0, sizeof(threadpool_t));

        pool->min_thr_num = min_thr_num;//线程最小值
        pool->shutdown = false;//不关闭线程
        /* 创建线程列表 */
        pool->threads = new pthread_list_t();
        if(pool->threads == NULL)
        {
            De_fprintf(stderr,"new pthread_list_t fail\r\n");
            break;
        }

        /* 创建任务队列 */
        pool->threadpool_task_queue = new thread_pool_task_queue_t();
        if(pool->threadpool_task_queue == NULL)
        {
            De_fprintf(stderr,"new threadpool_task_queue_t fail\r\n");
            break;
        }
        /* 初始化互斥琐、条件变量 */
        if (pthread_mutex_init(&(pool->lock), NULL) != 0
            || pthread_mutex_init(&(pool->thread_counter), NULL) != 0
            || pthread_cond_init(&(pool->queue_not_empty), NULL) != 0
            || pthread_cond_init(&(pool->queue_not_full), NULL) != 0)
        {
            De_fprintf(stderr,"init the lock or cond fail");
            break;
        }
        /* 启动 min_thr_num 个 work thread */
        pthread_attr_t attr;
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);//设置线程分离
        for (i = 0; i < min_thr_num; i++) {
            pthread_t pid=0;
            int ret = pthread_create(&pid, &attr, threadpool_thread, (void *)pool);/*pool指向当前线程池*/
            if(ret !=0)
            {
                De_fprintf(stderr, "creatd thread fail:%s\r\n", strerror(ret));
                break;
            }
            pool->threads->push_back(pid); 
            /* De_printf("start thread 0x%x...\n", (unsigned int)pid); */
        }
        pthread_attr_destroy(&attr);
        if(i!=min_thr_num)
            break;
        pthread_create(&(pool->adjust_tid), NULL, adjust_thread, (void *)pool);/* 启动管理者线程 */
        return pool;
    }while(0);
    threadpool_destroy(pool);

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movl %edi, -0xc(%rbp)
movq $0x0, -0x18(%rbp)
movl $0xd8, %edi
callq 0x46a0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0xf289
jmp 0xf24c
movq 0xdd85(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x4f3e(%rip), %rsi      # 0x1419b
leaq 0x6bcb(%rip), %rdx      # 0x15e2f
leaq 0x6bd6(%rip), %rcx      # 0x15e41
movl $0x55, %r8d
movb $0x0, %al
callq 0x46e0
leaq 0x6bd1(%rip), %rdi      # 0x15e50
callq 0x4410
jmp 0xf61b
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0xd8, %edx
callq 0x4290
movl -0xc(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc8(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0xd4(%rax)
movl $0x18, %edi
callq 0x44f0
movq %rax, %rdi
movq %rdi, -0x80(%rbp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x4290
movq -0x80(%rbp), %rdi
callq 0xff20
movq -0x80(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xb8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0xb8(%rax)
jne 0xf35a
jmp 0xf2f9
movq 0xdcd8(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x4e91(%rip), %rsi      # 0x1419b
leaq 0x6b1e(%rip), %rdx      # 0x15e2f
leaq 0x6b29(%rip), %rcx      # 0x15e41
movl $0x61, %r8d
movb $0x0, %al
callq 0x46e0
movq 0xdcac(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x6b2f(%rip), %rsi      # 0x15e65
movb $0x0, %al
callq 0x46e0
movq 0xdc94(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x699b(%rip), %rsi      # 0x15ce9
movb $0x0, %al
callq 0x46e0
jmp 0xf61b
movl $0x50, %edi
callq 0x44f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x88(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
callq 0xff40
jmp 0xf38e
movq -0x88(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xc0(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0xc0(%rax)
jne 0xf437
jmp 0xf3b4
movq 0xdc1d(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x4dd6(%rip), %rsi      # 0x1419b
leaq 0x6a63(%rip), %rdx      # 0x15e2f
leaq 0x6a6e(%rip), %rcx      # 0x15e41
movl $0x69, %r8d
movb $0x0, %al
callq 0x46e0
movq 0xdbf1(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x6a8e(%rip), %rsi      # 0x15e7f
movb $0x0, %al
callq 0x46e0
movq 0xdbd9(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x68e0(%rip), %rsi      # 0x15ce9
movb $0x0, %al
callq 0x46e0
jmp 0xf61b
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x50, %esi
callq 0x4510
jmp 0xf639
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4730
cmpl $0x0, %eax
jne 0xf48e
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4730
cmpl $0x0, %eax
jne 0xf48e
movq -0x18(%rbp), %rdi
addq $0x80, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4600
cmpl $0x0, %eax
jne 0xf48e
movq -0x18(%rbp), %rdi
addq $0x50, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4600
cmpl $0x0, %eax
je 0xf4f1
jmp 0xf490
movq 0xdb41(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x4cfa(%rip), %rsi      # 0x1419b
leaq 0x6987(%rip), %rdx      # 0x15e2f
leaq 0x6992(%rip), %rcx      # 0x15e41
movl $0x72, %r8d
movb $0x0, %al
callq 0x46e0
movq 0xdb15(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x69d5(%rip), %rsi      # 0x15ea2
movb $0x0, %al
callq 0x46e0
movq 0xdafd(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x6804(%rip), %rsi      # 0x15ce9
movb $0x0, %al
callq 0x46e0
jmp 0xf61b
leaq -0x68(%rbp), %rdi
callq 0x4620
leaq -0x68(%rbp), %rdi
movl $0x1, %esi
callq 0x4680
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xf5df
movq $0x0, -0x70(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x70(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq 0x11a(%rip), %rdx       # 0xf650
callq 0x4880
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
je 0xf5bd
jmp 0xf546
movq 0xda8b(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x4c44(%rip), %rsi      # 0x1419b
leaq 0x68d1(%rip), %rdx      # 0x15e2f
leaq 0x68dc(%rip), %rcx      # 0x15e41
movl $0x7e, %r8d
movb $0x0, %al
callq 0x46e0
movq 0xda5f(%rip), %rax      # 0x1cfd8
movq (%rax), %rax
movq %rax, -0x90(%rbp)
movl -0x74(%rbp), %edi
callq 0x4190
movq -0x90(%rbp), %rdi
movq %rax, %rdx
leaq 0x6678(%rip), %rsi      # 0x15c14
movb $0x0, %al
callq 0x46e0
movq 0xda2e(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
leaq 0x6735(%rip), %rsi      # 0x15ce9
movb $0x0, %al
callq 0x46e0
jmp 0xf5df
movq -0x18(%rbp), %rax
movq 0xb8(%rax), %rdi
leaq -0x70(%rbp), %rsi
callq 0xff60
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf50f
leaq -0x68(%rbp), %rdi
callq 0x47c0
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
je 0xf5f2
jmp 0xf61b
movq -0x18(%rbp), %rdi
addq $0xb0, %rdi
movq -0x18(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq 0x254(%rip), %rdx       # 0xf860
callq 0x4880
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xf62c
movq -0x18(%rbp), %rdi
callq 0xfb20
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x4830
nopw %cs:(%rax,%rax)