// File: /workspace/github_cpp_makefile_star2_O1/guoxuanhan[P]NetServer/threadpool.cpp
// Function: ThreadPool::ThreadFunc()
void ThreadPool::ThreadFunc()
{
    std::thread::id tid = std::this_thread::get_id();
    std::stringstream sin;
    sin << tid;
    std::cout<< "Worker thread is running! tid: " << tid << std::endl;
    Task task;
    while(started_)
    {
        task = NULL;
        {
            std::unique_lock<std::mutex> lock(mutex_);//unique_lock支持解锁又上锁的情况
            while(taskqueue_.empty() && started_)
            {
                condition_.wait(lock);
            }
            if(!started_)
            {
                break;
            }
            std::cout<< "Thread wake up! tid: " << tid << std::endl;
            std::cout<< "Taskqueue size: " << taskqueue_.size() << std::endl;
            task = taskqueue_.front();
            taskqueue_.pop();
        }
        if(task)
        {
            try
            {
                task();//task()中IO过程可以使用协程优化，让出CPU资源
            } catch(std::bad_alloc& bad)
            {
                std::cerr << "Bad_alloc caught in ThreadPool::ThreadFunc task: " << bad.what() << std::endl;
                while(true);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, %rbx
callq 0x42f0
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x4260
leaq 0x60(%rsp), %rdi
testq %r14, %r14
je 0xe66c
movq %r14, %rsi
callq 0x4230
jmp 0xe67d
leaq 0x1e23(%rip), %rsi      # 0x10496
movl $0x24, %edx
callq 0x43a0
movq 0x9934(%rip), %r13      # 0x17fb8
leaq 0x2f78(%rip), %rsi      # 0x11603
movl $0x1f, %edx
movq %r13, %rdi
callq 0x43a0
testq %r14, %r14
je 0xe6b1
movq 0x9914(%rip), %rdi      # 0x17fb8
movq %r14, %rsi
callq 0x4230
movq %rax, %r12
jmp 0xe6cc
movq 0x9900(%rip), %r12      # 0x17fb8
leaq 0x1dd7(%rip), %rsi      # 0x10496
movl $0x24, %edx
movq %r12, %rdi
callq 0x43a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4320
movsbl %al, %esi
movq %r12, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4240
movq %r14, 0x48(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
cmpb $0x1, (%rbx)
jne 0xe8c2
leaq 0x70(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x98(%rbx), %r12
leaq 0x20(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0x28(%rsp), %rbp
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0xe74e
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movups %xmm0, (%rax)
movq 0x40(%rsp), %rax
movq %rax, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
movq %rbp, %rdi
callq 0xf10c
movb $0x1, 0x30(%rsp)
movq 0x50(%rbx), %rax
cmpq 0x30(%rbx), %rax
jne 0xe786
cmpb $0x1, (%rbx)
jne 0xe786
movq %r12, %rdi
movq %rbp, %rsi
callq 0x40d0
jmp 0xe76a
movb (%rbx), %r14b
cmpb $0x1, %r14b
jne 0xe8b8
movl $0x15, %edx
movq %r13, %rdi
leaq 0x2e81(%rip), %rsi      # 0x11623
callq 0x43a0
movq 0x48(%rsp), %rsi
testq %rsi, %rsi
je 0xe7be
movq %r13, %rdi
callq 0x4230
movq %rax, %r15
jmp 0xe7d5
movl $0x24, %edx
movq %r13, %rdi
leaq 0x1cc9(%rip), %rsi      # 0x10496
callq 0x43a0
movq %r13, %r15
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4320
movsbl %al, %esi
movq %r15, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4240
movl $0x10, %edx
movq %r13, %rdi
leaq 0x2e2e(%rip), %rsi      # 0x11639
callq 0x43a0
movq 0x68(%rbx), %rax
movq %rax, %rcx
subq 0x48(%rbx), %rcx
shrq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
shlq $0x4, %rcx
movq 0x40(%rbx), %rsi
movq 0x50(%rbx), %rax
subq 0x58(%rbx), %rax
subq 0x30(%rbx), %rsi
sarq $0x5, %rax
sarq $0x5, %rsi
addq %rax, %rsi
addq %rcx, %rsi
movq %r13, %rdi
callq 0x4230
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4320
movsbl %al, %esi
movq %r15, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4240
movq 0x30(%rbx), %rsi
movq %rsp, %rdi
callq 0x4d8c
movq 0x38(%rsp), %rdi
callq 0xf170
movq %rbp, %rdi
callq 0xeabe
testb %r14b, %r14b
je 0xe8c2
cmpq $0x0, 0x10(%rsp)
je 0xe8ad
movq %rsp, %rdi
callq *0x18(%rsp)
cmpb $0x0, (%rbx)
jne 0xe72c
jmp 0xe8c2
leaq 0x28(%rsp), %rdi
callq 0xeabe
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0xe8d9
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x96b8(%rip), %rsi      # 0x17f98
leaq 0x50(%rsp), %rdi
callq 0x4290
leaq 0xd0(%rsp), %rdi
callq 0x4110
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe9bd
movq %rax, %rbx
cmpl $0x2, %edx
jne 0xe980
movq %rbx, %rdi
callq 0x4150
movq %rax, %rbx
movq 0x96c0(%rip), %rdi      # 0x17fe8
leaq 0x2d1b(%rip), %rsi      # 0x1164a
movl $0x31, %edx
callq 0x43a0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x969f(%rip), %rdi      # 0x17fe8
movq %rax, %rsi
callq 0x4330
movq %rax, %rdi
callq 0x41a0
jmp 0xe959
movq %rax, %rbx
callq 0x4530
jmp 0xe980
jmp 0xe9bd
jmp 0xe9bd
movq %rax, %rbx
jmp 0xe980
movq %rax, %rbx
jmp 0xe997
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xeabe
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0xe997
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x95fa(%rip), %rsi      # 0x17f98
leaq 0x50(%rsp), %rdi
callq 0x4290
leaq 0xd0(%rsp), %rdi
callq 0x4110
movq %rbx, %rdi
callq 0x45a0
movq %rax, %rdi
callq 0x4df2
nop