// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/bio.c
// Function: bioProcessBackgroundJobs
void *bioProcessBackgroundJobs(void *arg) {
    struct bio_job *job;
    unsigned long type = (unsigned long) arg;
    sigset_t sigset;

    /* Check that the type is within the right interval. */
    if (type >= BIO_NUM_OPS) {
        serverLog(LL_WARNING,
            "Warning: bio thread started with wrong type %lu",type);
        return NULL;
    }

    /* Make the thread killable at any time, so that bioKillThreads()
     * can work reliably. */
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

    pthread_mutex_lock(&bio_mutex[type]);
    /* Block SIGALRM so we are sure that only the main thread will
     * receive the watchdog signal. */
    sigemptyset(&sigset);
    sigaddset(&sigset, SIGALRM);
    if (pthread_sigmask(SIG_BLOCK, &sigset, NULL))
        serverLog(LL_WARNING,
            "Warning: can't mask SIGALRM in bio.c thread: %s", strerror(errno));

    while(1) {
        listNode *ln;

        /* The loop always starts with the lock hold. */
        if (listLength(bio_jobs[type]) == 0) {
            pthread_cond_wait(&bio_condvar[type],&bio_mutex[type]);
            continue;
        }
        /* Pop the job from the queue. */
        ln = listFirst(bio_jobs[type]);
        job = ln->value;
        /* It is now possible to unlock the background system as we know have
         * a stand alone job structure to process.*/
        pthread_mutex_unlock(&bio_mutex[type]);

        /* Process the job accordingly to its type. */
        if (type == BIO_CLOSE_FILE) {
            close((long)job->arg1);
        } else if (type == BIO_AOF_FSYNC) {
            aof_fsync((long)job->arg1);
        } else {
            serverPanic("Wrong job type in bioProcessBackgroundJobs().");
        }
        zfree(job);

        /* Lock again before reiterating the loop, if there are no longer
         * jobs to process we'll block again in pthread_cond_wait(). */
        pthread_mutex_lock(&bio_mutex[type]);
        listDelNode(bio_jobs[type],ln);
        bio_pending[type]--;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
cmpq $0x2, %rdi
jb 0x6685b
leaq 0x5573e(%rip), %rsi     # 0xbbf78
pushq $0x3
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2b699
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
xorl %esi, %esi
callq 0x26050
pushq $0x1
popq %rdi
xorl %esi, %esi
callq 0x26610
imulq $0x28, %rbx, %rax
leaq 0xa7d67(%rip), %r14     # 0x10e5e0
addq %rax, %r14
movq %r14, %rdi
callq 0x26b20
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x26ac0
pushq $0xe
popq %rsi
movq %r15, %rdi
callq 0x268c0
xorl %edi, %edi
movq %r15, %rsi
xorl %edx, %edx
callq 0x26170
testl %eax, %eax
je 0x668cc
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x556e9(%rip), %rsi     # 0xbbfa8
pushq $0x3
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2b699
imulq $0x30, %rbx, %rax
leaq 0xa7d59(%rip), %r15     # 0x10e630
addq %rax, %r15
leaq 0xa7daf(%rip), %rbp     # 0x10e690
movq (%rbp,%rbx,8), %rax
cmpq $0x0, 0x28(%rax)
je 0x6690d
movq (%rax), %r12
movq 0x10(%r12), %r13
movq %r14, %rdi
callq 0x26c30
movl 0x8(%r13), %edi
testq %rbx, %rbx
je 0x6691a
callq 0x26570
jmp 0x6691f
movq %r15, %rdi
movq %r14, %rsi
callq 0x26980
jmp 0x668e1
callq 0x26180
movq %r13, %rdi
callq 0x328f9
movq %r14, %rdi
callq 0x26b20
movq (%rbp,%rbx,8), %rdi
movq %r12, %rsi
callq 0x26fa8
leaq 0xa7d5d(%rip), %rax     # 0x10e6a0
decq (%rax,%rbx,8)
jmp 0x668e1