// File: /workspace/github_cpp_makefile_star2_O2/Barath-Kannan[P]SignalsAndSlots/test/SignalTest.cpp
// Function: SignalTest_MultiEmit_Test::TestBody()
TEST_F(SignalTest, MultiEmit){
    cout << "Instantiating signal object" << endl;

    Signal<int, int> testSignal;

    BasicTimer bt;
    BasicTimer bt2;
    cout << "Connecting signal" << endl;
    bt.start();
    int id = testSignal.connectSlot(ExecutorScheme::STRAND, staticSumFunction);
    bt.stop();
    cout << "Time to connect: " << bt.getElapsedMilliseconds() << "ms" << endl;

    cout << "Emitting signal" << endl;

    bt.start();
    list<thread> threads;
    const uint32_t nThreads = 64;
    std::atomic<uint32_t> threadsRemaining{nThreads};
    for (uint32_t i=0; i<nThreads; i++){
        threads.emplace_back([&, i](){
            for (uint32_t i=0; i<1000000; ++i){
                testSignal.emitSignal(1, 2);
            }
            uint32_t tr = threadsRemaining.fetch_sub(1);
            cout << "Threads remaining: " << tr-1 << endl;
            cout << "globalStaticInt: " << globalStaticIntX << endl;
        });
    }
    bt.stop();
    
    bt2.start();
    while (bt2.getElapsedSeconds() < 60.0) {
        if (globalStaticIntX == 1000000*3*nThreads) {
            bt2.stop();
            break;
        }
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }
    //ASSERT_LT(bt2.getElapsedSeconds(), 0.1);
    cout << "Time to emit: " << bt.getElapsedMilliseconds() << "ms" << endl;
    cout << "Time to emit and process: " << bt2.getElapsedMilliseconds() << "ms" << endl;
    cout << "Net time to process: " << bt2.getElapsedMilliseconds() - bt.getElapsedMilliseconds() << "ms" << endl;

    ASSERT_EQ(0, id);

    testSignal.disconnectAllSlots();
    for (auto &t : threads) t.join();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq 0x5058c(%rip), %rdi     # 0x5ffb0
leaq 0x2a75d(%rip), %rsi     # 0x3a188
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
leaq 0xa0(%rsp), %rdi
callq 0x10606
leaq 0x30(%rsp), %rdi
callq 0xcb2c
leaq 0x50(%rsp), %rdi
callq 0xcb2c
movq 0x50550(%rip), %rdi     # 0x5ffb0
leaq 0x2a769(%rip), %rsi     # 0x3a1d0
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
leaq 0x30(%rsp), %rdi
callq 0xcb9a
leaq 0x80(%rsp), %rdx
andq $0x0, 0x8(%rdx)
leaq -0x1c7d(%rip), %rax     # 0xde15
movq %rax, (%rdx)
leaq 0x56a8(%rip), %rax      # 0x15144
movq %rax, 0x18(%rdx)
leaq 0x56a7(%rip), %rax      # 0x1514e
movq %rax, 0x10(%rdx)
leaq 0xa0(%rsp), %rdi
pushq $0x3
popq %rsi
callq 0x10164
movl %eax, %ebx
leaq 0x80(%rsp), %rdi
callq 0xd31c
movl %ebx, 0x2c(%rsp)
leaq 0x30(%rsp), %rdi
callq 0xcbc2
movq 0x504d1(%rip), %rdi     # 0x5ffb0
leaq 0x2a6fc(%rip), %rsi     # 0x3a1e2
callq 0xb4f0
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xcb66
movq %rbx, %rdi
callq 0xb960
leaq 0x2c1fc(%rip), %rsi     # 0x3bd03
movq %rax, %rdi
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
movq 0x50492(%rip), %rdi     # 0x5ffb0
leaq 0x2a6cf(%rip), %rsi     # 0x3a1f4
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
leaq 0x30(%rsp), %rdi
callq 0xcb9a
leaq 0x68(%rsp), %rbp
movq %rbp, 0x8(%rbp)
movq %rbp, (%rbp)
andq $0x0, 0x10(%rbp)
leaq 0x28(%rsp), %rax
movl $0x40, (%rax)
xorl %ebx, %ebx
pushq $0x20
popq %r15
leaq 0x8(%rsp), %r12
leaq 0x10(%rsp), %r13
cmpl $0x40, %ebx
je 0xfc0a
movq %rbp, %rdi
callq 0x1a44c
movq %rbp, %rcx
movq %rax, %rbp
movq %rcx, %r14
movq %rcx, 0x10(%rsp)
movq %rax, 0x18(%rsp)
andq $0x0, 0x10(%rax)
movq %r15, %rdi
callq 0xb510
movq %rbp, %rdi
addq $0x10, %rdi
leaq 0x4e080(%rip), %rcx     # 0x5dc28
movq %rcx, (%rax)
movl %ebx, 0x8(%rax)
leaq 0xa0(%rsp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rax)
movq %rax, 0x8(%rsp)
movq %r12, %rsi
xorl %edx, %edx
callq 0xb4c0
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xfbe2
movq (%rdi), %rax
callq *0x8(%rax)
andq $0x0, 0x18(%rsp)
movq %r13, %rdi
callq 0x1a454
movq %rbp, %rdi
movq %r14, %rbp
movq %r14, %rsi
callq 0xb090
incq 0x78(%rsp)
incl %ebx
jmp 0xfb69
leaq 0x30(%rsp), %rdi
callq 0xcbc2
leaq 0x50(%rsp), %rdi
callq 0xcb9a
leaq 0x50(%rsp), %r14
leaq 0xa2ae2(%rip), %rbx     # 0xb270c
leaq 0x10(%rsp), %r15
movq %r14, %rdi
callq 0xcb38
movsd 0x2a451(%rip), %xmm1    # 0x3a090
ucomisd %xmm0, %xmm1
jbe 0xfc6b
movl (%rbx), %eax
cmpl $0xb71b000, %eax        # imm = 0xB71B000
je 0xfc61
movq $0x64, 0x10(%rsp)
movq %r15, %rdi
callq 0x10486
jmp 0xfc2f
leaq 0x50(%rsp), %rdi
callq 0xcbc2
movq 0x5033e(%rip), %rdi     # 0x5ffb0
leaq 0x2a58b(%rip), %rsi     # 0x3a204
callq 0xb4f0
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0xcb66
movq %r14, %rdi
callq 0xb960
leaq 0x2c069(%rip), %rsi     # 0x3bd03
movq %rax, %rdi
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
movq 0x502ff(%rip), %rdi     # 0x5ffb0
leaq 0x2a5b7(%rip), %rsi     # 0x3a26f
callq 0xb4f0
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0xcb66
movq %r14, %rdi
callq 0xb960
leaq 0x2c02a(%rip), %rsi     # 0x3bd03
movq %rax, %rdi
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
movq 0x502c0(%rip), %rdi     # 0x5ffb0
leaq 0x2a593(%rip), %rsi     # 0x3a28a
callq 0xb4f0
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0xcb66
movsd %xmm0, 0x48(%rsp)
leaq 0x30(%rsp), %rdi
callq 0xcb66
movsd 0x48(%rsp), %xmm1
subsd %xmm0, %xmm1
movq %r14, %rdi
movapd %xmm1, %xmm0
callq 0xb960
leaq 0x2bfcd(%rip), %rsi     # 0x3bd03
movq %rax, %rdi
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
leaq 0x8(%rsp), %rcx
andl $0x0, (%rcx)
leaq 0x302ed(%rip), %rsi     # 0x40042
leaq 0x2f61f(%rip), %rdx     # 0x3f37b
leaq 0x10(%rsp), %rdi
leaq 0x2c(%rsp), %r8
callq 0x1558a
cmpb $0x0, 0x10(%rsp)
je 0xfd9f
leaq 0x18(%rsp), %rdi
callq 0x10766
leaq 0xa0(%rsp), %rdi
callq 0x1356c
movq %rbp, %rbx
movq (%rbx), %rbx
cmpq %rbp, %rbx
je 0xfe08
leaq 0x10(%rbx), %rdi
callq 0xb9e0
jmp 0xfd8c
leaq 0x8(%rsp), %rdi
callq 0x23d1e
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0xfdb8
movq (%rax), %r8
jmp 0xfdbf
leaq 0x2ec85(%rip), %r8      # 0x3ea44
leaq 0x2a3ae(%rip), %rdx     # 0x3a174
leaq 0x20(%rsp), %rdi
pushq $0x2
popq %rsi
movl $0x15e, %ecx            # imm = 0x15E
callq 0x22794
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x22812
leaq 0x18(%rsp), %rbx
leaq 0x20(%rsp), %rdi
callq 0x227f4
leaq 0x8(%rsp), %rdi
callq 0x10720
movq %rbx, %rdi
callq 0x10766
leaq 0x68(%rsp), %rdi
callq 0x13052
leaq 0xa0(%rsp), %rdi
callq 0x1352c
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x227f4
jmp 0xfe43
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x10720
jmp 0xfe52
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x10766
jmp 0xfeaa
jmp 0xfe83
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xd31c
jmp 0xfeb4
jmp 0xfe76
jmp 0xfe76
movq %rax, %rbx
jmp 0xfeb4
jmp 0xfe83
jmp 0xfe83
jmp 0xfe83
jmp 0xfe83
movq %rax, %rbx
jmp 0xfeaa
movq %rax, %rbx
jmp 0xfea0
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xfea0
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x10(%rsp), %rdi
callq 0x1a454
leaq 0x68(%rsp), %rdi
callq 0x13052
leaq 0xa0(%rsp), %rdi
callq 0x1352c
movq %rbx, %rdi
callq 0xba30
nop