LCOV - code coverage report
Current view: top level - irohad/ordering/impl/ordering_gate_cache - on_demand_cache.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 22 22 100.0 %
Date: 2018-12-05 17:11:35 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "ordering/impl/ordering_gate_cache/on_demand_cache.hpp"
       7             : 
       8             : #include "interfaces/iroha_internal/transaction_batch.hpp"
       9             : 
      10             : using namespace iroha::ordering::cache;
      11             : 
      12             : // TODO: IR-1864 13.11.18 kamilsa use nvi to separate business logic and locking
      13             : // logic
      14             : 
      15             : void OnDemandCache::addToBack(
      16             :     const OrderingGateCache::BatchesSetType &batches) {
      17           5 :   std::unique_lock<std::shared_timed_mutex> lock(mutex_);
      18           5 :   circ_buffer.back().insert(batches.begin(), batches.end());
      19           5 : }
      20             : 
      21             : void OnDemandCache::remove(const OrderingGateCache::HashesSetType &hashes) {
      22           1 :   std::unique_lock<std::shared_timed_mutex> lock(mutex_);
      23           4 :   for (auto &batches : circ_buffer) {
      24           6 :     for (auto it = batches.begin(); it != batches.end();) {
      25           3 :       if (hashes.find(it->get()->reducedHash()) != hashes.end()) {
      26             :         // returns iterator following the last removed element
      27             :         // hence there is no increment in loop iteration_expression
      28           2 :         it = batches.erase(it);
      29           2 :       } else {
      30           1 :         ++it;
      31             :       }
      32             :     }
      33             :   }
      34           1 : }
      35             : 
      36             : OrderingGateCache::BatchesSetType OnDemandCache::pop() {
      37           8 :   std::unique_lock<std::shared_timed_mutex> lock(mutex_);
      38           8 :   auto res = circ_buffer.front();
      39             :   // push empty set to remove front element
      40           8 :   circ_buffer.push_back(BatchesSetType{});
      41           8 :   return res;
      42           8 : }
      43             : 
      44             : const OrderingGateCache::BatchesSetType &OnDemandCache::head() const {
      45           2 :   std::shared_lock<std::shared_timed_mutex> lock(mutex_);
      46           2 :   return circ_buffer.front();
      47           2 : }
      48             : 
      49             : const OrderingGateCache::BatchesSetType &OnDemandCache::tail() const {
      50           1 :   std::shared_lock<std::shared_timed_mutex> lock(mutex_);
      51           1 :   return circ_buffer.back();
      52           1 : }

Generated by: LCOV version 1.13