// File: /workspace/github_c_makefile_star2_O2/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 0x7d1a
movl %esi, %ebp
pushq $0x1
popq %rdi
pushq $0x48
popq %rsi
callq 0x32c0
movq %rax, %rbx
testq %rax, %rax
je 0x7d12
movl %ebp, %edi
callq 0x8328
movq %rax, (%rbx)
testq %rax, %rax
je 0x7d12
pushq $0x18
popq %rdi
callq 0x3450
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rax)
movups %xmm0, (%rax)
movq %rax, 0x30(%rbx)
movq %rbx, %rdi
addq $0x8, %rdi
xorl %esi, %esi
callq 0x3660
testl %eax, %eax
jne 0x7d12
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x3550
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x35b0
leaq 0x8(%rsp), %rdi
andq $0x0, (%rdi)
leaq 0x98(%rip), %rdx        # 0x7d9b
movq %r14, %rsi
movq %rbx, %rcx
callq 0x37a0
testl %eax, %eax
je 0x7d2a
movq %rbx, %rdi
callq 0x7e8a
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)
pushq $0x1
popq %rdi
pushq $0x10
popq %rsi
callq 0x32c0
testq %rax, %rax
je 0x7d12
movq %rax, %r14
callq 0x3720
movq %rax, %r15
movq %rax, (%r14)
movq %rbx, 0x8(%r14)
pushq $0x1
popq %rdi
pushq $0x38
popq %rsi
callq 0x32c0
movq %rax, (%rsp)
testq %rax, %rax
je 0x7d12
movq %r15, 0x28(%rax)
movq %rax, %rdi
xorl %esi, %esi
callq 0x3660
testl %eax, %eax
jne 0x7d12
movq 0x30(%rbx), %rdi
movq %rsp, %rsi
callq 0x8144
movq (%rbx), %rdi
leaq 0xcf(%rip), %rsi        # 0x7e60
movq %r14, %rdx
callq 0x8979
jmp 0x7d1c