// File: /workspace/github_cpp_makefile_star2_O2/Barath-Kannan[P]SignalsAndSlots/src/details/WheeledThreadPool.cpp
// Function: BSignals::details::WheeledThreadPool::queueListener(unsigned int)
void WheeledThreadPool::queueListener(uint32_t index) {
    auto &spoke = threadPooledFunctions.getSpoke(index);
    std::function<void()> func;
    std::chrono::duration<double> waitTime = std::chrono::nanoseconds(1);
    const uint32_t wrap = threadPooledFunctions.size();
    auto wrapIncrementer = [wrap](uint32_t i){return (i+1 == wrap ? 0 : i+1);};
    
    while (isStarted){
        if (spoke.dequeue(func)){
            spoke.transferMaxToCache();
            if (func) func();
            waitTime = std::chrono::nanoseconds(1);
        }
        else{
            bool found = false;
            for (uint32_t i=wrapIncrementer(index); i != index; i=wrapIncrementer(i)){
                if (threadPooledFunctions.getSpoke(i).fastDequeue(func)){
                    found = true;
                    break;
                }
            }
            if (found){
                if (func) func();
                waitTime = std::chrono::nanoseconds(1);
            }
            else{
                std::this_thread::sleep_for(waitTime);
                waitTime*=2;
            }
        }
        if (waitTime > maxWait){
            spoke.blockingDequeue(func);
            if (func) func();
            waitTime = std::chrono::nanoseconds(1);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edi, %ebx
movabsq $0x3e112e0be826d695, %rcx # imm = 0x3E112E0BE826D695
movl %edi, %eax
imulq $0x2900, %rax, %rax     # imm = 0x2900
movq 0x441e(%rip), %rbp      # 0x8fd8
leaq (%rax,%rbp), %r14
addq $0x88, %r14
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movapd %xmm0, 0x10(%r15)
movapd %xmm0, (%r15)
movq %rsp, %rax
leal 0x1(%rbx), %edx
xorl %r13d, %r13d
cmpl $0x20, %edx
cmovel %r13d, %edx
movl %edx, 0xc(%rsp)
movq %rcx, (%rax)
movq 0x43d9(%rip), %rax      # 0x8fd0
cmpb $0x1, (%rax)
jne 0x4cde
movq %r14, %rdi
movq %r15, %rsi
callq 0x41a0
movl 0xc(%rsp), %r12d
testb %al, %al
je 0x4c2e
movq %r14, %rdi
callq 0x4060
cmpq $0x0, 0x20(%rsp)
je 0x4c89
movq %r15, %rdi
callq 0x4280
jmp 0x4c89
cmpl %ebx, %r12d
je 0x4c61
movl %r12d, %eax
imulq $0x2900, %rax, %rax     # imm = 0x2900
leaq (%rax,%rbp), %rdi
addq $0x88, %rdi
movq %r15, %rsi
callq 0x4320
testb %al, %al
jne 0x4c79
incl %r12d
cmpl $0x20, %r12d
cmovel %r13d, %r12d
jmp 0x4c2e
movq %rsp, %rdi
callq 0x41b0
movsd (%rsp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, (%rsp)
jmp 0x4c9f
cmpq $0x0, 0x20(%rsp)
je 0x4c89
movq %r15, %rdi
callq 0x4280
movabsq $0x3e112e0be826d695, %rax # imm = 0x3E112E0BE826D695
movq %rax, (%rsp)
movsd 0x1379(%rip), %xmm0     # 0x6018
movq 0x433a(%rip), %rax      # 0x8fe0
ucomisd (%rax), %xmm0
jbe 0x4bf0
movq %r14, %rdi
movq %r15, %rsi
callq 0x4540
cmpq $0x0, 0x20(%rsp)
je 0x4ccb
movq %r15, %rdi
callq 0x4280
movabsq $0x3e112e0be826d695, %rax # imm = 0x3E112E0BE826D695
movq %rax, (%rsp)
jmp 0x4bf0
leaq 0x10(%rsp), %rdi
callq 0x41e0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4cfb
jmp 0x4cfb
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x41e0
movq %rbx, %rdi
callq 0x44b0