// File: yangwanyuan[P]HLKVDS/src/Tier.cc
// Function: hlkvds::FastTier::ReqMerge(hlkvds::Request*)
void FastTier::ReqMerge(Request* req) {
    int shard_id = req->GetShardsWQId();

    std::unique_lock<std::mutex> lck_seg_map(segMapMtx_, std::defer_lock);

    std::mutex *seg_mtx = segMtxVec_[shard_id];
    std::unique_lock<std::mutex> lck_seg(*seg_mtx);

    lck_seg_map.lock();
    SegForReq *seg = segMap_[shard_id];
    lck_seg_map.unlock();

    if (seg->TryPut(req)) {
        seg->Put(req);
    } else {
        seg->Completion();
        segWteWQ_->Add_task(seg);

        seg = new SegForReq(vol_, idxMgr_, options_.expired_time);

        lck_seg_map.lock();
        std::map<int, SegForReq*>::iterator iter = segMap_.find(shard_id);
        segMap_.erase(iter);
        segMap_.insert( make_pair(shard_id, seg) );
        lck_seg_map.unlock();

        seg->Put(req);
    }

}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x16da0
movq 0x58(%rsp), %rsi
movl %eax, 0xe4(%rsp)
addq $0x128, %rsi            # imm = 0x128
leaq 0xd0(%rsp), %rdi
callq 0x16db0
movq 0x58(%rsp), %rdi
addq $0x180, %rdi            # imm = 0x180
movslq 0xe4(%rsp), %rsi
callq 0x16d00
movq (%rax), %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x15a10
jmp 0x4c5fc
leaq 0xd0(%rsp), %rdi
callq 0x16dd0
jmp 0x4c60b
movq 0x58(%rsp), %rdi
addq $0x150, %rdi            # imm = 0x150
leaq 0xe4(%rsp), %rsi
callq 0x16c10
movq %rax, 0x50(%rsp)
jmp 0x4c62b
movq 0x50(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x98(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x16e30
jmp 0x4c64a
movq 0x98(%rsp), %rdi
movq 0xe8(%rsp), %rsi
callq 0x42bf0
movb %al, 0x4f(%rsp)
jmp 0x4c665
movb 0x4f(%rsp), %al
testb $0x1, %al
jne 0x4c66f
jmp 0x4c6bd
movq 0x98(%rsp), %rdi
movq 0xe8(%rsp), %rsi
callq 0x42c50
jmp 0x4c686
jmp 0x4c856
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
jmp 0x4c885
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
jmp 0x4c878
movq 0x98(%rsp), %rdi
callq 0x42ce0
jmp 0x4c6cc
movq 0x58(%rsp), %rax
movq 0x208(%rax), %rdi
movq 0x98(%rsp), %rsi
callq 0x16e80
jmp 0x4c6e7
movl $0xd8, %edi
callq 0x84f0
movq %rax, 0x40(%rsp)
jmp 0x4c6f8
movq 0x40(%rsp), %rdi
movq 0x58(%rsp), %rcx
movq 0x1d8(%rcx), %rsi
movq (%rcx), %rax
movq 0x10(%rcx), %rdx
movl 0x10(%rax), %ecx
callq 0x42b00
jmp 0x4c71a
movq 0x40(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x16dd0
jmp 0x4c736
movq 0x58(%rsp), %rdi
addq $0x150, %rdi            # imm = 0x150
leaq 0xe4(%rsp), %rsi
callq 0x16f00
movq %rax, 0x38(%rsp)
jmp 0x4c756
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rax
movq %rax, 0x90(%rsp)
addq $0x150, %rdi            # imm = 0x150
movq 0x90(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rsi
callq 0x16f30
movq %rax, 0x30(%rsp)
jmp 0x4c793
movq 0x58(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x80(%rsp)
addq $0x150, %rax            # imm = 0x150
movq %rax, 0x18(%rsp)
leaq 0xe4(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x15b90
movq %rdx, 0x20(%rsp)
movl %eax, 0x2c(%rsp)
jmp 0x4c7d0
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rax
movl 0x2c(%rsp), %ecx
movl %ecx, 0x70(%rsp)
movq %rax, 0x78(%rsp)
leaq 0x70(%rsp), %rsi
callq 0x15b40
movb %dl, 0xf(%rsp)
movq %rax, 0x10(%rsp)
jmp 0x4c7fc
movb 0xf(%rsp), %al
movq 0x10(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movb %al, 0x68(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x16e30
jmp 0x4c81d
movq 0x98(%rsp), %rdi
movq 0xe8(%rsp), %rsi
callq 0x42c50
jmp 0x4c834
jmp 0x4c856
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
callq 0x84b0
jmp 0x4c878
leaq 0xb0(%rsp), %rdi
callq 0x15c30
leaq 0xd0(%rsp), %rdi
callq 0x15c30
addq $0xf8, %rsp
retq
leaq 0xb0(%rsp), %rdi
callq 0x15c30
leaq 0xd0(%rsp), %rdi
callq 0x15c30
movq 0xa8(%rsp), %rdi
callq 0x8820
nop