// File: cybozu[P]yrmcds/src/server.cpp
// Function: yrmcds::server::server()
server::server(): m_syncer(m_workers) {
    auto finder = [this]() ->cybozu::worker* {
        std::size_t n_workers = m_workers.size();
        for( std::size_t i = 0; i < n_workers; ++i ) {
            cybozu::worker* pw = m_workers[m_worker_index].get();
            m_worker_index = (m_worker_index + 1) % n_workers;
            if( ! pw->is_running() )
                return pw;
        }
        return nullptr;
    };

    m_handlers.emplace_back(new memcache::handler(finder, m_reactor, m_syncer));
    if( g_config.counter().enable() )
        m_handlers.emplace_back(new counter::handler(finder, m_reactor));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x98(%rbp)
movb $0x0, (%rdi)
addq $0x8, %rdi
movq %rdi, -0xa0(%rbp)
callq 0xe7b0
movq -0x98(%rbp), %rdi
addq $0xe0, %rdi
movq %rdi, -0x90(%rbp)
callq 0x21fe0
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
movl $0x0, 0xf8(%rdi)
addq $0x100, %rdi            # imm = 0x100
movq %rdi, -0x88(%rbp)
callq 0x22000
jmp 0x1f924
movq -0x98(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq %rdi, -0xb8(%rbp)
movq %rdi, %rax
movq %rax, -0xb0(%rbp)
callq 0x22030
movq -0x98(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0xb0, %edi
callq 0x8640
movq %rax, -0xa8(%rbp)
jmp 0x1f966
movb $0x1, -0x49(%rbp)
leaq -0x48(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
leaq -0x20(%rbp), %rsi
callq 0x1fb40
movq -0x98(%rbp), %rcx
movq -0xa8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq %rcx, %rdx
addq $0x8, %rdx
addq $0x100, %rcx            # imm = 0x100
callq 0x36c50
jmp 0x1f9a8
movq -0xb8(%rbp), %rdi
movq -0xa8(%rbp), %rax
movb $0x0, -0x49(%rbp)
movq %rax, -0x28(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x22050
jmp 0x1f9c9
leaq -0x48(%rbp), %rdi
callq 0x220d0
leaq 0x90327(%rip), %rdi     # 0xafd00
callq 0x220f0
movq %rax, %rdi
callq 0x22110
testb $0x1, %al
jne 0x1f9ef
jmp 0x1faf9
movq -0x98(%rbp), %rax
addq $0x120, %rax            # imm = 0x120
movq %rax, -0xd0(%rbp)
movl $0x60, %edi
callq 0x8640
movq %rax, -0xc8(%rbp)
jmp 0x1fa16
movb $0x1, -0x79(%rbp)
leaq -0x78(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
leaq -0x20(%rbp), %rsi
callq 0x1fb40
movq -0x98(%rbp), %rdx
movq -0xc8(%rbp), %rdi
movq -0xd8(%rbp), %rsi
addq $0x8, %rdx
callq 0x2b340
jmp 0x1fa4e
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rax
movb $0x0, -0x79(%rbp)
movq %rax, -0x58(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x22130
jmp 0x1fa6f
leaq -0x78(%rbp), %rdi
callq 0x220d0
jmp 0x1faf9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1fb1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1fb02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x220d0
testb $0x1, -0x49(%rbp)
jne 0x1fab6
jmp 0x1fac7
movq -0xa8(%rbp), %rdi
movl $0xb0, %esi
callq 0x8650
jmp 0x1fb02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x220d0
testb $0x1, -0x79(%rbp)
jne 0x1fae6
jmp 0x1faf7
movq -0xc8(%rbp), %rdi
movl $0x60, %esi
callq 0x8650
jmp 0x1fb02
addq $0xe0, %rsp
popq %rbp
retq
movq -0xb0(%rbp), %rdi
callq 0xb850
movq -0x88(%rbp), %rdi
callq 0xb8b0
movq -0x90(%rbp), %rdi
callq 0xb8d0
movq -0xa0(%rbp), %rdi
callq 0xe970
movq -0x10(%rbp), %rdi
callq 0x8bc0
nopl (%rax,%rax)