// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/redis.c
// Function: databasesCron
void databasesCron(void) {

    // 函数先从数据库中删除过期键，然后再对数据库的大小进行修改

    /* Expire keys by random sampling. Not required for slaves
     * as master will synthesize DELs for us. */
    // 如果服务器不是从服务器，那么执行主动过期键清除
    if (server.active_expire_enabled && server.masterhost == NULL)
        // 清除模式为 CYCLE_SLOW ，这个模式会尽量多清除过期键
        activeExpireCycle(ACTIVE_EXPIRE_CYCLE_SLOW);

    /* Perform hash tables rehashing if needed, but only if there are no
     * other processes saving the DB on disk. Otherwise rehashing is bad
     * as will cause a lot of copy-on-write of memory pages. */
    // 在没有 BGSAVE 或者 BGREWRITEAOF 执行时，对哈希表进行 rehash
    if (server.rdb_child_pid == -1 && server.aof_child_pid == -1) {
        /* We use global counters so if we stop the computation at a given
         * DB we'll be able to start from the successive in the next
         * cron loop iteration. */
        static unsigned int resize_db = 0;
        static unsigned int rehash_db = 0;
        unsigned int dbs_per_call = REDIS_DBCRON_DBS_PER_CALL;
        unsigned int j;

        /* Don't test more DBs than we have. */
        // 设定要测试的数据库数量
        if (dbs_per_call > server.dbnum) dbs_per_call = server.dbnum;

        /* Resize */
        // 调整字典的大小
        for (j = 0; j < dbs_per_call; j++) {
            tryResizeHashTables(resize_db % server.dbnum);
            resize_db++;
        }

        /* Rehash */
        // 对字典进行渐进式 rehash
        if (server.activerehashing) {
            for (j = 0; j < dbs_per_call; j++) {
                int work_done = incrementallyRehash(rehash_db % server.dbnum);
                rehash_db++;
                if (work_done) {
                    /* If the function did some work, stop here, we'll do
                     * more at the next cron loop. */
                    break;
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
cmpl $0x0, 0xedcc9(%rip)     # 0x113d68
je 0x260b2
cmpq $0x0, 0xede9f(%rip)     # 0x113f48
jne 0x260b2
xorl %edi, %edi
callq 0x259c0
cmpl $-0x1, 0xeddaf(%rip)    # 0x113e68
jne 0x2617d
cmpl $-0x1, 0xedd36(%rip)    # 0x113dfc
jne 0x2617d
movl $0x10, -0x4(%rbp)
movl -0x4(%rbp), %eax
cmpl 0xedc9c(%rip), %eax     # 0x113d78
jbe 0x260e7
movl 0xedc94(%rip), %eax     # 0x113d78
movl %eax, -0x4(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x4(%rbp), %eax
jae 0x26125
movl 0xee04c(%rip), %eax     # 0x114148
xorl %edx, %edx
divl 0xedc74(%rip)           # 0x113d78
movl %edx, %edi
callq 0x25780
movl 0xee037(%rip), %eax     # 0x114148
addl $0x1, %eax
movl %eax, 0xee02e(%rip)     # 0x114148
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x260ee
cmpl $0x0, 0xed804(%rip)     # 0x113930
je 0x2617b
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x4(%rbp), %eax
jae 0x26179
movl 0xee009(%rip), %eax     # 0x11414c
xorl %edx, %edx
divl 0xedc2d(%rip)           # 0x113d78
movl %edx, %edi
callq 0x25810
movl %eax, -0xc(%rbp)
movl 0xedff1(%rip), %eax     # 0x11414c
addl $0x1, %eax
movl %eax, 0xedfe8(%rip)     # 0x11414c
cmpl $0x0, -0xc(%rbp)
je 0x2616c
jmp 0x26179
jmp 0x2616e
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x26135
jmp 0x2617b
jmp 0x2617d
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)