// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
cmpl $0x0, -0xc(%rbp)
ja 0xd843
leaq 0xfc7a(%rip), %rax      # 0x1d4b8
movl (%rax), %eax
movl %eax, -0xc(%rbp)
cmpl $0x1, -0x10(%rbp)
jae 0xd856
movq $0x0, -0x8(%rbp)
jmp 0xda40
movq $0x0, -0x18(%rbp)
movl $0x48, %edi
callq 0x46a0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xd878
jmp 0xda2f
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0x4290
movq -0x18(%rbp), %rax
movl $0x0, 0x40(%rax)
movl -0x10(%rbp), %edi
callq 0xf220
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xd8b4
jmp 0xda2f
movl $0x18, %edi
callq 0x44f0
movq %rax, %rdi
movq %rdi, -0x78(%rbp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x4290
movq -0x78(%rbp), %rdi
callq 0xe170
movq -0x78(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0xd8f6
jmp 0xda2f
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4730
cmpl $0x0, %eax
je 0xd911
jmp 0xda2f
leaq -0x50(%rbp), %rdi
callq 0x4620
leaq -0x50(%rbp), %rdi
movl $0x1, %esi
callq 0x4680
movq $0x0, -0x58(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x58(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq 0x10d(%rip), %rdx       # 0xda50
callq 0x4880
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0xd956
jmp 0xda2f
movq -0x58(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movl $0x10, %edi
callq 0x46a0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0xd97c
jmp 0xda2f
movq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x4290
callq 0x47e0
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x68(%rbp)
jne 0xd9a7
jmp 0xda2f
movq -0x18(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x38, %edi
callq 0x46a0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0xd9ca
jmp 0xda2f
movq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x4290
movq -0x68(%rbp), %rax
movq (%rax), %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x70(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4730
cmpl $0x0, %eax
je 0xd9fd
jmp 0xda2f
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
leaq -0x70(%rbp), %rsi
callq 0xe190
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x68(%rbp), %rdx
leaq 0x1d0(%rip), %rsi       # 0xdbf0
callq 0xfc20
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xda40
movq -0x18(%rbp), %rdi
callq 0xdc50
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)