// File: /workspace/github_c_makefile_star2_O0/ttoobne[P]bohttpd/src/core/threadpool.c
// Function: threadpool_add_task
int threadpool_add_task(threadpool_t* threadpool, task_function_t* func, void* args) {
    if (threadpool == NULL || func == NULL) {
        log_error("arguments invalid.");
        return -1;
    }

    /* 加锁 */
    pthread_mutex_lock(&(threadpool->lock_mutex));

    /* 如果任务队列中任务已满，则阻塞在条件 nfull_cond 上 */
    while ((threadpool->task_num == threadpool->task_queue_size) && (!threadpool->shutdown)) {
        pthread_cond_wait(&(threadpool->nfull_cond), &(threadpool->lock_mutex));
    }

    /* 如果线程池已经关闭 */
    if (threadpool->shutdown) {
        pthread_mutex_unlock(&(threadpool->lock_mutex));
        log_error("threadpool already shutdown.");
        return -1;
    }

    /* 添加任务到任务队列尾部 */
    threadpool->task_queue[threadpool->task_queue_rear].func = func;
    threadpool->task_queue[threadpool->task_queue_rear].args = args;
    threadpool->task_queue_rear = (threadpool->task_queue_rear + 1) % threadpool->task_queue_size;
    threadpool->task_num ++ ;

    /* 通知一个阻塞在 nempty_cond 上的线程并解锁互斥锁 */
    pthread_cond_signal(&(threadpool->nempty_cond));
    pthread_mutex_unlock(&(threadpool->lock_mutex));

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x7e42
cmpq $0x0, -0x18(%rbp)
jne 0x7e74
movl $0x4, %edi
leaq 0x2048(%rip), %rsi      # 0x9e96
leaq 0x2105(%rip), %rdx      # 0x9f5a
movl $0x8b, %ecx
leaq 0x205d(%rip), %r8       # 0x9ebe
movb $0x0, %al
callq 0x6450
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7f96
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
callq 0x24a0
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
movq -0x10(%rbp), %rdx
xorl %eax, %eax
cmpl 0x18(%rdx), %ecx
movb %al, -0x21(%rbp)
jne 0x7ea6
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
setne %al
xorb $-0x1, %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0x7eaf
jmp 0x7ec6
movq -0x10(%rbp), %rdi
addq $0x58, %rdi
movq -0x10(%rbp), %rsi
addq $0x30, %rsi
callq 0x2110
jmp 0x7e81
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x7f0f
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
callq 0x22d0
movl $0x4, %edi
leaq 0x1fad(%rip), %rsi      # 0x9e96
leaq 0x206a(%rip), %rdx      # 0x9f5a
movl $0x9a, %ecx
leaq 0x2072(%rip), %r8       # 0x9f6e
movb $0x0, %al
callq 0x6450
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7f96
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rdx
movslq 0x20(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rdx
movslq 0x20(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
cltd
idivl 0x18(%rcx)
movq -0x10(%rbp), %rax
movl %edx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rdi
addq $0x88, %rdi
callq 0x2240
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
callq 0x22d0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop