// File: /workspace/github_cpp_makefile_star2_O2/cybozu[P]yrmcds/src/server.cpp
// Function: yrmcds::server::serve_master()
void server::serve_master() {
    cybozu::logger::info() << "Entering master mode";

    for( auto& handler: m_handlers )
        handler->on_master_start();

    auto callback = [this](cybozu::reactor&) {
        std::time_t now = std::time(nullptr);
        g_current_time.store(now, std::memory_order_relaxed);

        if( ! m_syncer.empty() )
            m_syncer.check();
        for( auto& handler: m_handlers )
            handler->on_master_interval();

        if( reactor_gc_ready() ) {
            m_reactor.fix_garbage();
            m_syncer.add_request(
                std::unique_ptr<sync_request>(
                    new sync_request([this]{ m_reactor.gc(); })
                    ));
        }
    };

    for( unsigned int i = 0; i < g_config.workers(); ++i )
        m_workers.emplace_back(new cybozu::worker(WORKER_BUFSIZE));
    for( auto& w: m_workers )
        w->start();

    auto stop = [this] {
        m_reactor.invalidate();
        for( auto& w: m_workers )
            w->stop();
        for( auto& handler: m_handlers )
            handler->on_master_end();
    };

    try {
        cybozu::logger::info() << "Reactor thread id="
                               << std::this_thread::get_id();
        m_reactor.run(callback);
        cybozu::logger::info() << "Exiting";
    } catch( ... ) {
        stop();
        throw;
    }

    stop();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r15
movq %rsp, %r14
movq %r14, %rdi
callq 0xec96
leaq 0x183ea(%rip), %rsi     # 0x26a09
movq %r14, %rdi
callq 0xed72
movq %rsp, %rdi
callq 0x86e4
movq 0x120(%r15), %rbx
movq 0x128(%r15), %r14
cmpq %r14, %rbx
je 0xe651
movq (%rbx), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
addq $0x8, %rbx
jmp 0xe63d
movq %r15, 0x18(%rsp)
leaq 0xe0(%r15), %r14
xorl %ebp, %ebp
leaq 0x2d55a(%rip), %rbx     # 0x3bbc0
pushq $0x40
popq %r15
movq %rsp, %r12
cmpl 0x104(%rbx), %ebp
jae 0xe6a5
movl $0xc0, %edi
movq %r15, %rsi
callq 0x7550
movq %rax, %r13
movl $0x500000, %esi         # imm = 0x500000
movq %rax, %rdi
callq 0xedc2
movq %r13, (%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0xed8a
incl %ebp
jmp 0xe66d
movq 0x18(%rsp), %r15
movq 0xe0(%r15), %rbx
movq 0xe8(%r15), %r14
cmpq %r14, %rbx
je 0xe6cb
movq (%rbx), %rdi
callq 0xee5e
addq $0x8, %rbx
jmp 0xe6b8
movq %r15, 0x10(%rsp)
movq %rsp, %rdi
callq 0xec96
leaq 0x1833f(%rip), %rsi     # 0x26a1e
movq %rsp, %rdi
callq 0x9388
movq %rax, %r14
callq 0x7480
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
movq %r14, %rdi
callq 0xeee6
movq %rsp, %rdi
callq 0x86e4
leaq 0x28(%rsp), %rsi
andq $0x0, 0x8(%rsi)
movq %r15, (%rsi)
addq $0x8, %r15
leaq 0x38d(%rip), %rax       # 0xeaac
movq %rax, 0x18(%rsi)
leaq 0x498(%rip), %rax       # 0xebc2
movq %rax, 0x10(%rsi)
pushq $0x1
popq %rdx
movq %r15, %rdi
callq 0x99c6
leaq 0x28(%rsp), %rdi
callq 0x8d90
movq %rsp, %rdi
callq 0xec96
leaq 0x182df(%rip), %rsi     # 0x26a31
movq %rsp, %rdi
callq 0xef00
movq %rsp, %rdi
callq 0x86e4
leaq 0x10(%rsp), %rdi
callq 0xe7ec
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe790
jmp 0xe79d
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x8d90
jmp 0xe7a0
jmp 0xe790
movq %rax, %rbx
movq %rsp, %rdi
callq 0x86e4
jmp 0xe7a0
movq %rax, %rbx
movq %rbx, %rdi
callq 0x71a0
leaq 0x10(%rsp), %rdi
callq 0xe7ec
callq 0x77c0
movq %rax, %rbx
movq %rsp, %rdi
callq 0x86e4
jmp 0xe7e4
movq %rax, %rbx
callq 0x78e0
jmp 0xe7e4
movq %rax, %rdi
callq 0x870a
movq %rax, %rbx
pushq $0x40
popq %rsi
movq %r13, %rdi
callq 0x76a0
movq %rbx, %rdi
callq 0x7990