// File: /workspace/github_c_makefile_star2_O0/sszllzss[P]webSocket_Libevent_ThreadPool/evbase_threadpool.cpp
// Function: evbase_threadpool_add_event(evbase_threadpool_t*)
event_base * evbase_threadpool_add_event(evbase_threadpool_t * evb_thpool)
{
    event_base *base = NULL;
    evbase_thread_vector::iterator i;
    pthread_mutex_lock(&evb_thpool->evbase_thread_list.lock);
    for(i = evb_thpool->evbase_thread_list.list->begin();
        i != evb_thpool->evbase_thread_list.list->end(); i++)
    {
        pthread_mutex_lock(&(*i)->monitor_num_locl);
        if((*i)->monitor_num < BASE_MAX_MONITOR_NUM)
        {
            base = (*i)->base;
            (*i)->monitor_num++;
            pthread_mutex_unlock(&(*i)->monitor_num_locl);
            break;
        }
        pthread_mutex_unlock(&(*i)->monitor_num_locl);
    }
    
    if(i == evb_thpool->evbase_thread_list.list->end())
    {
        pthread_mutex_unlock(&evb_thpool->evbase_thread_list.lock);
        do{
            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->base == NULL)
            {
                free(evb_th_arg);
                break;

            }
            evb_th_arg->evb_thpool = evb_thpool;

            evbase_thread_t *evb_th = (evbase_thread_t *)malloc(sizeof(evbase_thread_t));
            if(evb_th == NULL)
            {
                event_base_free(evb_th_arg->base);
                free(evb_th_arg);
                break;
            }
            memset(evb_th, 0, sizeof(evbase_thread_t));
            evb_th->base = base;
            evb_th->monitor_num++;
            if(pthread_mutex_init(&evb_th->monitor_num_locl, NULL) != 0)
            {
                free(evb_th);
                event_base_free(evb_th_arg->base);
                free(evb_th_arg);
                break;
            }
            pthread_mutex_lock(&evb_thpool->evbase_thread_list.lock);
            evb_thpool->evbase_thread_list.list->push_back(evb_th);
            pthread_mutex_unlock(&evb_thpool->evbase_thread_list.lock);

            //创建一个base监听
            threadpool_add(evb_thpool->pool, evbase_thread, evb_th_arg);
            base = evb_th_arg->base;
        }while(0);   
    }else
        pthread_mutex_unlock(&evb_thpool->evbase_thread_list.lock);


    return base;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
leaq -0x18(%rbp), %rdi
callq 0xe360
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x4720
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0xe200
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0xe270
movq %rax, -0x28(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xe230
testb $0x1, %al
jne 0xde4a
jmp 0xded6
leaq -0x18(%rbp), %rdi
callq 0xe2a0
movq (%rax), %rdi
callq 0x4720
leaq -0x18(%rbp), %rdi
callq 0xe2a0
movq (%rax), %rax
movl 0x30(%rax), %eax
leaq 0xf647(%rip), %rcx      # 0x1d4b8
cmpl (%rcx), %eax
jae 0xdeb1
leaq -0x18(%rbp), %rdi
callq 0xe2a0
movq (%rax), %rax
movq 0x28(%rax), %rax
movq %rax, -0x10(%rbp)
leaq -0x18(%rbp), %rdi
callq 0xe2a0
movq (%rax), %rax
movl 0x30(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x30(%rax)
leaq -0x18(%rbp), %rdi
callq 0xe2a0
movq (%rax), %rdi
callq 0x4390
jmp 0xded6
leaq -0x18(%rbp), %rdi
callq 0xe2a0
movq (%rax), %rdi
callq 0x4390
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0xe2c0
movq %rax, -0x30(%rbp)
jmp 0xde23
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0xe270
movq %rax, -0x38(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xe380
testb $0x1, %al
jne 0xdefd
jmp 0xe040
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x4390
movl $0x10, %edi
callq 0x46a0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0xdf24
jmp 0xe03e
movq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x4290
callq 0x47e0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xdf5b
movq -0x40(%rbp), %rdi
callq 0x45f0
jmp 0xe03e
movq -0x8(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x38, %edi
callq 0x46a0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xdf96
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0x46b0
movq -0x40(%rbp), %rdi
callq 0x45f0
jmp 0xe03e
movq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x4290
movq -0x10(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x48(%rbp), %rax
movl 0x30(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x30(%rax)
movq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4730
cmpl $0x0, %eax
je 0xdff1
movq -0x48(%rbp), %rdi
callq 0x45f0
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0x46b0
movq -0x40(%rbp), %rdi
callq 0x45f0
jmp 0xe03e
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x4720
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0xe190
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x4390
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
leaq -0x43e(%rip), %rsi      # 0xdbf0
callq 0xfc20
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0xe04d
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x4390
movq -0x10(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)