// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
leaq 0x50(%rsp), %rdi
callq 0x4260
leaq 0x60(%rsp), %rdi
testq %r15, %r15
je 0xe5f4
movq %r15, %rsi
callq 0x4230
jmp 0xe605
leaq 0x1eb7(%rip), %rsi      # 0x104b2
movl $0x24, %edx
callq 0x43a0
movq 0x99ac(%rip), %r14      # 0x17fb8
leaq 0x2fe0(%rip), %rsi      # 0x115f3
movl $0x1f, %edx
movq %r14, %rdi
callq 0x43a0
testq %r15, %r15
je 0xe639
movq 0x998c(%rip), %rdi      # 0x17fb8
movq %r15, %rsi
callq 0x4230
movq %rax, %r12
jmp 0xe654
movq 0x9978(%rip), %r12      # 0x17fb8
leaq 0x1e6b(%rip), %rsi      # 0x104b2
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 %r15, 0x48(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
cmpb $0x1, (%rbx)
jne 0xe842
leaq 0x70(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x98(%rbx), %r12
leaq 0x20(%rbx), %rax
movq %rax, 0x38(%rsp)
movq %rsp, %rbp
leaq 0x10(%rsp), %r13
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0xe6da
movq %r13, %rdi
movq %r13, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movups %xmm0, (%rax)
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
movb $0x0, 0x8(%rsp)
movq %rbp, %rdi
callq 0xf088
movb $0x1, 0x8(%rsp)
movq 0x50(%rbx), %rax
cmpq 0x30(%rbx), %rax
jne 0xe711
cmpb $0x1, (%rbx)
jne 0xe711
movq %r12, %rdi
movq %rbp, %rsi
callq 0x40d0
jmp 0xe6f5
cmpb $0x1, (%rbx)
jne 0xe83a
movl $0x15, %edx
movq %r14, %rdi
leaq 0x2eea(%rip), %rsi      # 0x11613
callq 0x43a0
movq 0x48(%rsp), %rsi
testq %rsi, %rsi
je 0xe745
movq %r14, %rdi
callq 0x4230
movq %rax, %r15
jmp 0xe75c
movl $0x24, %edx
movq %r14, %rdi
leaq 0x1d5e(%rip), %rsi      # 0x104b2
callq 0x43a0
movq %r14, %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 %r14, %rdi
leaq 0x2e97(%rip), %rsi      # 0x11629
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 %r14, %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 %r13, %rdi
callq 0x4d8c
movq 0x38(%rsp), %rdi
callq 0xf0ec
movq %rbp, %rdi
callq 0xea2e
cmpq $0x0, 0x20(%rsp)
je 0xe82f
movq %r13, %rdi
callq *0x28(%rsp)
cmpb $0x0, (%rbx)
jne 0xe6b8
jmp 0xe842
movq %rsp, %rdi
callq 0xea2e
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0xe85b
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x9736(%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 0xe93f
movq %rax, %rbx
cmpl $0x2, %edx
jne 0xe900
movq %rbx, %rdi
callq 0x4150
movq %rax, %rbx
movq 0x973e(%rip), %rdi      # 0x17fe8
leaq 0x2d89(%rip), %rsi      # 0x1163a
movl $0x31, %edx
callq 0x43a0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x971d(%rip), %rdi      # 0x17fe8
movq %rax, %rsi
callq 0x4330
movq %rax, %rdi
callq 0x41a0
jmp 0xe8db
movq %rax, %rbx
callq 0x4530
jmp 0xe900
jmp 0xe93f
jmp 0xe93f
movq %rax, %rbx
jmp 0xe919
movq %rax, %rbx
jmp 0xe900
movq %rax, %rbx
movq %rsp, %rdi
callq 0xea2e
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0xe919
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x9678(%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