// File: /workspace/github_cpp_makefile_star2_O2/Barath-Kannan[P]SignalsAndSlots/test/SignalTest_Parametrized.cpp
// Function: SignalTestParametrized_IntenseUsage_Test::TestBody()
TEST_P(SignalTestParametrized, IntenseUsage) {
    auto func = ([this](sigType x) {
        volatile sigType v = x;
        for (uint32_t i = 0; i < params.nOperations; i++) {
            v+=x;
        }
        completedFunctions++;
    });

    Signal<sigType> signal(params.threadSafe);
    cout << "Connecting " << params.nConnections << " functions" << endl;
    for (uint32_t i = 0; i < params.nConnections; i++) {
        signal.connectSlot(params.scheme, func);
    }

    FunctionTimeRegular<> printer([this]() {
        cout << "Total elements emitted: " << counter << " / " << params.nEmissions << fixed << endl;
        cout << "Emission rate: " << (double) counter / bt.getElapsedMilliseconds() << fixed << "m/ms" << endl;
        cout << "Total elements processed: " << completedFunctions << " / " << params.nEmissions * params.nConnections << fixed << endl;
        cout << "Operation rate: " << (double) completedFunctions * params.nOperations / bt2.getElapsedNanoseconds() << "m/ns" << endl;
        return (bt2.getElapsedSeconds() < 6000);
    }, std::chrono::milliseconds(500));

    FunctionTimeRegular<> checkFinished([this]() {
        return (completedFunctions != params.nEmissions * params.nConnections);
    }, std::chrono::milliseconds(1));

    cout << "Starting emission thread: " << endl;
    
    std::list<thread> emitters;
    for (uint32_t i=0; i<params.nEmitters; ++i){
        emitters.emplace_back([this, &signal, i]() {
            if (i==0){
                bt2.start();
                bt.start();
            }
            uint32_t current;
            while ((current = counter.fetch_add(1000)) < params.nEmissions-1000){
                for (uint32_t j=0; j<1000; ++j) signal.emitSignal(1);
            }
            if (current == params.nEmissions-1000){
                for (uint32_t j=0; j<1000; ++j) signal.emitSignal(1);
                bt.stop();
            }
        });
    }
    cout << "Emission thread spawned" << endl;
    cout.precision(std::numeric_limits<double>::max_digits10);
    for (auto &t : emitters){
        t.join();
    }
    cout << "Emission completed" << endl;
    checkFinished.join();
    bt2.stop();
    printer.stopAndJoin();
    cout << "Processing completed" << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
movq %rdi, %rbx
movzbl 0x28(%rdi), %esi
leaq 0x180(%rsp), %rdi
callq 0x1e15a
movq 0x45798(%rip), %rdi     # 0x5ffb0
leaq 0x21594(%rip), %rsi     # 0x3bdb3
callq 0xb4f0
movl 0x18(%rbx), %esi
movq %rax, %rdi
callq 0xb390
leaq 0x21589(%rip), %rsi     # 0x3bdbf
movq %rax, %rdi
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
xorl %ebp, %ebp
leaq 0xd27(%rip), %r15       # 0x1b576
leaq 0xd40(%rip), %r12       # 0x1b596
leaq 0x180(%rsp), %r13
leaq 0x40(%rsp), %r14
cmpl 0x18(%rbx), %ebp
jae 0x1a897
movl 0x2c(%rbx), %esi
andq $0x0, 0x48(%rsp)
movq %rbx, 0x40(%rsp)
movq %r15, 0x58(%rsp)
movq %r12, 0x50(%rsp)
movq %r13, %rdi
movq %r14, %rdx
callq 0x1bfb4
movq %r14, %rdi
callq 0xd31c
incl %ebp
jmp 0x1a863
leaq 0x60(%rsp), %rsi
andq $0x0, 0x8(%rsi)
movq %rbx, (%rsi)
leaq 0xd11(%rip), %rax       # 0x1b5bc
movq %rax, 0x18(%rsi)
leaq 0xeb6(%rip), %rax       # 0x1b76c
movq %rax, 0x10(%rsi)
leaq 0x20(%rsp), %rdx
movq $0x1f4, (%rdx)          # imm = 0x1F4
leaq 0xf0(%rsp), %rdi
callq 0x1c006
leaq 0x60(%rsp), %rdi
callq 0xd31c
leaq 0x20(%rsp), %rsi
andq $0x0, 0x8(%rsi)
movq %rbx, (%rsi)
leaq 0xea1(%rip), %rax       # 0x1b792
movq %rax, 0x18(%rsi)
leaq 0xeaa(%rip), %rax       # 0x1b7a6
movq %rax, 0x10(%rsi)
leaq 0x10(%rsp), %rdx
movq $0x1, (%rdx)
leaq 0x60(%rsp), %rdi
callq 0x1c006
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0xd31c
movq 0x45686(%rip), %rdi     # 0x5ffb0
leaq 0x21499(%rip), %rsi     # 0x3bdca
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
movq %r15, 0x28(%rsp)
movq %r15, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
xorl %r12d, %r12d
leaq 0x8(%rsp), %r13
leaq 0x10(%rsp), %rbp
cmpl 0x24(%rbx), %r12d
jae 0x1a9f1
movq %r15, %rdi
callq 0x1a44c
movq %rax, %r14
movq %r15, 0x10(%rsp)
movq %rax, 0x18(%rsp)
andq $0x0, 0x10(%rax)
pushq $0x20
popq %rdi
callq 0xb510
movq %r14, %rdi
addq $0x10, %rdi
leaq 0x4410b(%rip), %rcx     # 0x5eaa0
movq %rcx, (%rax)
movq %rbx, 0x8(%rax)
leaq 0x180(%rsp), %rcx
movq %rcx, 0x10(%rax)
movl %r12d, 0x18(%rax)
movq %rax, 0x8(%rsp)
movq %r13, %rsi
xorl %edx, %edx
callq 0xb4c0
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1a9cb
movq (%rdi), %rax
callq *0x8(%rax)
andq $0x0, 0x18(%rsp)
movq %rbp, %rdi
callq 0x1a454
movq %r14, %rdi
movq %r15, %rsi
callq 0xb090
incq 0x30(%rsp)
incl %r12d
jmp 0x1a95b
movq 0x455b8(%rip), %r14     # 0x5ffb0
leaq 0x213e6(%rip), %rsi     # 0x3bde5
movq %r14, %rdi
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
movq (%r14), %rax
movq -0x18(%rax), %rax
movq $0x11, 0x8(%r14,%rax)
movq %r15, %r14
movq (%r14), %r14
cmpq %r15, %r14
je 0x1aa35
leaq 0x10(%r14), %rdi
callq 0xb9e0
jmp 0x1aa22
movq 0x45574(%rip), %rdi     # 0x5ffb0
leaq 0x213ba(%rip), %rsi     # 0x3bdfd
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
leaq 0xc0(%rsp), %rdi
callq 0xb9e0
addq $0x48, %rbx
movq %rbx, %rdi
callq 0xcbc2
leaq 0xf0(%rsp), %rdi
callq 0x1c0f6
movq 0x45533(%rip), %rdi     # 0x5ffb0
leaq 0x2138c(%rip), %rsi     # 0x3be10
callq 0xb4f0
movq %rax, %rdi
callq 0xb270
leaq 0x20(%rsp), %rdi
callq 0x13052
leaq 0x60(%rsp), %rdi
callq 0x1c10c
leaq 0xf0(%rsp), %rdi
callq 0x1c10c
leaq 0x180(%rsp), %rdi
callq 0x1e1e6
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xd31c
jmp 0x1ab33
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x1ab5d
movq %rax, %rbx
jmp 0x1ab29
movq %rax, %rbx
jmp 0x1ab40
jmp 0x1ab1c
jmp 0x1ab1c
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1ab10
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x1ab10
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x1a454
jmp 0x1ab1f
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x13052
leaq 0x60(%rsp), %rdi
callq 0x1c10c
leaq 0xf0(%rsp), %rdi
callq 0x1c10c
leaq 0x180(%rsp), %rdi
callq 0x1e1e6
movq %rbx, %rdi
callq 0xba30
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xd31c
jmp 0x1ab40