// File: /workspace/github_c_makefile_star2_O1/sszllzss[P]webSocket_Libevent_ThreadPool/evbase_threadpool.cpp
// Function: evbase_threadpool_new(unsigned int, unsigned int)
evbase_threadpool_t *evbase_threadpool_new(unsigned base_max_monitor_num,unsigned min_thread_num)
{
    if(base_max_monitor_num <= 0)
        base_max_monitor_num = BASE_MAX_MONITOR_NUM;
    if(min_thread_num<1)
        return NULL;
    evbase_threadpool_t *evbase_threadpool=NULL;
    do{
        evbase_threadpool = (evbase_threadpool_t *)malloc(sizeof(evbase_threadpool_t));
        if(evbase_threadpool == NULL)
            break;
        memset(evbase_threadpool,0, sizeof(evbase_threadpool_t));

        evbase_threadpool->shutdown = false;

        evbase_threadpool->pool = threadpool_create(min_thread_num);
        if(evbase_threadpool->pool == NULL)
            break;
        evbase_threadpool->evbase_thread_list.list = new evbase_thread_vector();
        if(evbase_threadpool->evbase_thread_list.list == NULL)
            break;
        if(pthread_mutex_init(&evbase_threadpool->evbase_thread_list.lock, NULL) != 0)
        {
            break;
        }

        pthread_attr_t attr;
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);//设置线程分离
        pthread_t pid=0;
        int ret = pthread_create(&pid, &attr, manager_thread, evbase_threadpool);
        if(ret!=0)
            break;
        evbase_threadpool->manager = pid;
        struct evbase_thread_arg *evb_th_arg = (struct evbase_thread_arg *)malloc(sizeof(struct evbase_thread_arg));
        if(evb_th_arg == NULL)
            break;
        memset(evb_th_arg, 0, sizeof(struct evbase_thread_arg));
        evb_th_arg->base = event_base_new();
        if(evb_th_arg == NULL)
            break;
        evb_th_arg->evb_thpool = evbase_threadpool;
        evbase_thread_t *evb_th = (evbase_thread_t *)malloc(sizeof(evbase_thread_t));
        if(evb_th == NULL)
            break;
        memset(evb_th, 0, sizeof(evbase_thread_t));
        evb_th->base = evb_th_arg->base;
        if(pthread_mutex_init(&evb_th->monitor_num_locl, NULL) != 0)
            break;

        evbase_threadpool->evbase_thread_list.list->push_back(evb_th);
        //创建一个base监听
        threadpool_add(evbase_threadpool->pool, evbase_thread, evb_th_arg);
        return evbase_threadpool; 
    }while(0);
    evbase_threadpool_destroy(evbase_threadpool);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
testl %esi, %esi
je 0x8685
movl %esi, %ebp
movl $0x48, %edi
callq 0x35a0
movq %rax, %rbx
testq %rax, %rax
je 0x867d
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movq $0x0, 0x40(%rbx)
movl %ebp, %edi
callq 0x8c44
movq %rax, (%rbx)
testq %rax, %rax
je 0x867d
movl $0x18, %edi
callq 0x3440
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, 0x30(%rbx)
movq %rbx, %rdi
addq $0x8, %rdi
xorl %esi, %esi
callq 0x3630
testl %eax, %eax
jne 0x867d
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x3530
movq %r14, %rdi
movl $0x1, %esi
callq 0x3580
leaq 0x8(%rsp), %rdi
movq $0x0, (%rdi)
leaq 0xb9(%rip), %rdx        # 0x8727
movq %r14, %rsi
movq %rbx, %rcx
callq 0x3770
testl %eax, %eax
je 0x8695
movq %rbx, %rdi
callq 0x882f
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq %rax, 0x38(%rbx)
movl $0x10, %edi
callq 0x35a0
testq %rax, %rax
je 0x867d
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
callq 0x36f0
movq %rax, %r15
movq %rax, (%r14)
movq %rbx, 0x8(%r14)
movl $0x38, %edi
callq 0x35a0
movq %rax, (%rsp)
testq %rax, %rax
je 0x867d
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x30(%rax)
movq %r15, 0x28(%rax)
movq %rax, %rdi
xorl %esi, %esi
callq 0x3630
testl %eax, %eax
jne 0x867d
movq 0x30(%rbx), %rdi
movq %rsp, %rsi
callq 0x8ad4
movq (%rbx), %rdi
leaq 0xeb(%rip), %rsi        # 0x8805
movq %r14, %rdx
callq 0x920d
jmp 0x8687