// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/BuildQueue.cpp
// Function: t2::BuildQueueInit(t2::BuildQueue*, t2::BuildQueueConfig const*)
void BuildQueueInit(BuildQueue* queue, const BuildQueueConfig* config)
  {
    ProfilerScope prof_scope("Tundra BuildQueueInit", 0);
    CHECK(config->m_MaxExpensiveCount > 0 && config->m_MaxExpensiveCount <= config->m_ThreadCount);

    MutexInit(&queue->m_Lock);
    CondInit(&queue->m_WorkAvailable);

    // Compute queue capacity. Allocate space for a power of two number of
    // indices that's at least one larger than the max number of nodes. Because
    // the queue is treated as a ring buffer, we want W=R to mean an empty
    // buffer.
    uint32_t capacity = NextPowerOfTwo(config->m_MaxNodes + 1);

    MemAllocHeap* heap = config->m_Heap;

    queue->m_Queue              = HeapAllocateArray<int32_t>(heap, capacity);
    queue->m_QueueReadIndex     = 0;
    queue->m_QueueWriteIndex    = 0;
    queue->m_QueueCapacity      = capacity;
    queue->m_Config             = *config;
    queue->m_PendingNodeCount   = 0;
    queue->m_FailedNodeCount    = 0;
    queue->m_QuitSignalled      = false;
    queue->m_ExpensiveRunning   = 0;
    queue->m_ExpensiveWaitCount = 0;
    queue->m_ExpensiveWaitList  = HeapAllocateArray<NodeState*>(heap, capacity);

    queue->m_Threads = HeapAllocateArrayZeroed<ThreadId>(config->m_Heap, config->m_ThreadCount);
    queue->m_ThreadState = HeapAllocateArrayZeroed<ThreadState>(config->m_Heap, config->m_ThreadCount);

    CHECK(queue->m_Queue);

    Log(kDebug, "build queue initialized; ring buffer capacity = %u", queue->m_QueueCapacity);

    // Block all signals on the main thread.
    SignalBlockThread(true);
    SignalHandlerSetCondition(&queue->m_WorkAvailable);

    // Create build threads.
    for (int i = 0, thread_count = config->m_ThreadCount; i < thread_count; ++i)
    {
      ThreadState* thread_state = &queue->m_ThreadState[i];

      ThreadStateInit(thread_state, queue, MB(32), i);

      if (i > 0)
      {
        Log(kDebug, "starting build thread %d", i);
        queue->m_Threads[i] = ThreadStart(BuildThreadRoutine, thread_state);
      }
    }
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x14(%rbp), %rdi
leaq 0x1f364(%rip), %rsi     # 0x23972
xorl %edx, %edx
callq 0x67e0
jmp 0x4617
jmp 0x4619
movq -0x8(%rbp), %rdi
callq 0x6810
jmp 0x4624
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
callq 0x6850
jmp 0x4633
movq -0x10(%rbp), %rax
movl 0x28(%rax), %edi
incl %edi
callq 0x7ca0
movl %eax, -0x44(%rbp)
jmp 0x4646
movl -0x44(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x6890
movq %rax, -0x50(%rbp)
jmp 0x466c
movq -0x50(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x64(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x68(%rax)
movl -0x28(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x60(%rax)
movq -0x10(%rbp), %rcx
movq %rcx, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq 0x70(%rcx), %rdx
movq %rdx, 0xe0(%rax)
movups 0x60(%rcx), %xmm0
movups %xmm0, 0xd0(%rax)
movups 0x50(%rcx), %xmm0
movups %xmm0, 0xc0(%rax)
movups 0x40(%rcx), %xmm0
movups %xmm0, 0xb0(%rax)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups 0x30(%rcx), %xmm3
movups %xmm3, 0xa0(%rax)
movups %xmm2, 0x90(%rax)
movups %xmm1, 0x80(%rax)
movups %xmm0, 0x70(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xe8(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xec(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x118(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x108(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x10c(%rax)
movq -0x30(%rbp), %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x68c0
movq %rax, -0x58(%rbp)
jmp 0x4753
movq -0x58(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x110(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movslq 0x10(%rax), %rsi
callq 0x68f0
movq %rax, -0x70(%rbp)
jmp 0x4779
movq -0x70(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xf8(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movslq 0x10(%rax), %rsi
callq 0x6940
movq %rax, -0x78(%rbp)
jmp 0x479f
movq -0x78(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x100(%rax)
jmp 0x47b0
jmp 0x47b2
movq -0x8(%rbp), %rax
movl 0x60(%rax), %edx
leaq 0x1f1c8(%rip), %rsi     # 0x23988
xorl %eax, %eax
movl $0x8, %edi
callq 0x7a60
jmp 0x47ce
movl $0x1, %edi
callq 0x1db90
jmp 0x47da
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
callq 0x1db50
jmp 0x47e9
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x48af
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movslq -0x34(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x34(%rbp), %ecx
movl $0x2000000, %edx        # imm = 0x2000000
callq 0x48d0
jmp 0x483b
cmpl $0x0, -0x34(%rbp)
jle 0x489f
movl -0x34(%rbp), %edx
leaq 0x1f170(%rip), %rsi     # 0x239bb
xorl %eax, %eax
movl $0x8, %edi
callq 0x7a60
jmp 0x4859
movq -0x40(%rbp), %rsi
leaq 0xcc(%rip), %rdi        # 0x4930
callq 0x1eb30
movq %rax, -0x80(%rbp)
jmp 0x486f
movq -0x80(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0xf8(%rax), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x489f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x14(%rbp), %rdi
callq 0x6980
jmp 0x48c1
jmp 0x48a1
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x47fa
leaq -0x14(%rbp), %rdi
callq 0x6980
addq $0x80, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x35c0
nopw (%rax,%rax)