ewmscp  ..
Public Member Functions | Private Attributes | List of all members
copyRequest::base::hashCalculator Class Reference
Collaboration diagram for copyRequest::base::hashCalculator:
[legend]

Public Member Functions

 hashCalculator (blockQueue &blocksToHash, blockQueue &hashedBlocks, base *request, bool mayParallelize, exceptionList &exceptions)
 
 ~hashCalculator () noexcept(false)
 
bool joinable () const
 
bool parallelized () const
 

Private Attributes

std::vector< std::thread > workers
 
checksum::parallelparallelSum
 
blockQueueoutputQueue
 

Detailed Description

Definition at line 186 of file copyRequest.h.

Constructor & Destructor Documentation

◆ hashCalculator()

copyRequest::base::hashCalculator::hashCalculator ( blockQueue blocksToHash,
blockQueue hashedBlocks,
base request,
bool  mayParallelize,
exceptionList exceptions 
)

Definition at line 669 of file copyRequest.cpp.

673  :
674  outputQueue(hashedBlocks) {
675  if (request->checkSums.empty() || (request->state & stateBitType::append)) {
676  return;
677  }
678  unsigned nBlocks = request->readInitialStat->size / request->memoryBlockSize;
679  if (request->checkSums.size() == 1
680  && request->checkSums.front()->parallelizable()
681  && nSumThreads > 1
682  && mayParallelize
683  && nBlocks >= nSumThreads ) {
684  workers.resize(std::min(nSumThreads.fGetValue(), nBlocks));
685  parallelSum = dynamic_cast<checksum::parallel*>(request->checkSums.front());
686  for (auto& worker : workers) {
687  worker = std::thread(&copyRequest::base::hash_worker, request,
688  parallelSum,
689  std::ref(blocksToHash),
690  std::ref(outputQueue),
691  std::ref(exceptions));
692  }
693  } else { // use one thread to calculate all checksums
694  workers.emplace_back(std::thread(&copyRequest::base::hasher, request,
695  std::ref(blocksToHash),
696  std::ref(outputQueue),
697  std::ref(exceptions)));
698  }
699 }

References copyRequest::append, copyRequest::base::checkSums, options::single< T >::fGetValue(), copyRequest::base::hash_worker(), copyRequest::base::hasher(), copyRequest::base::memoryBlockSize, copyRequest::base::nSumThreads, outputQueue, parallelSum, copyRequest::base::readInitialStat, copyRequest::base::state, and workers.

Here is the call graph for this function:

◆ ~hashCalculator()

copyRequest::base::hashCalculator::~hashCalculator ( )
noexcept

Definition at line 701 of file copyRequest.cpp.

701  {
702  if (workers.empty()) {
703  return;
704  }
705  for (auto& worker : workers) {
706  worker.join();
707  }
708  if (workers.size() > 1) {
710  }
712 }

Member Function Documentation

◆ joinable()

bool copyRequest::base::hashCalculator::joinable ( ) const

Definition at line 713 of file copyRequest.cpp.

713  {
714  return ! workers.empty();
715 }

Referenced by copyRequest::base::doThreadedCopy().

Here is the caller graph for this function:

◆ parallelized()

bool copyRequest::base::hashCalculator::parallelized ( ) const

Definition at line 716 of file copyRequest.cpp.

716  {
717  return workers.size() != 1; // we also do nothing in parallel
718 }

Referenced by copyRequest::base::doThreadedCopy().

Here is the caller graph for this function:

Member Data Documentation

◆ outputQueue

blockQueue& copyRequest::base::hashCalculator::outputQueue
private

Definition at line 189 of file copyRequest.h.

Referenced by hashCalculator().

◆ parallelSum

checksum::parallel* copyRequest::base::hashCalculator::parallelSum
private

Definition at line 188 of file copyRequest.h.

Referenced by hashCalculator().

◆ workers

std::vector<std::thread> copyRequest::base::hashCalculator::workers
private

Definition at line 187 of file copyRequest.h.

Referenced by hashCalculator().


The documentation for this class was generated from the following files:
waitQueues::simple::size
decltype(queue.size()) size() const
Definition: waitQueues.h:99
copyRequest::base::hasher
void hasher(blockQueue &blocksToHash, blockQueue &hashedBlocks, exceptionList &exceptions)
Definition: copyRequest.cpp:738
copyRequest::base::hash_worker
void hash_worker(checksum::parallel *sum, blockQueue &blocksToHash, blockQueue &hashedBlocks, exceptionList &exceptions)
Definition: copyRequest.cpp:720
copyRequest::base::hashCalculator::parallelSum
checksum::parallel * parallelSum
Definition: copyRequest.h:188
options::single::fGetValue
const T & fGetValue() const
Definition: Options.h:589
checksum::parallel::parallelFinish
virtual void parallelFinish()=0
waitQueues::simple::signalDone
void signalDone()
Definition: waitQueues.h:49
checksum::parallel
Definition: checksumBase.h:82
copyRequest::base::hashCalculator::workers
std::vector< std::thread > workers
Definition: copyRequest.h:187
copyRequest::base::hashCalculator::outputQueue
blockQueue & outputQueue
Definition: copyRequest.h:189
copyRequest::stateBitType::append
@ append
copyRequest::base::nSumThreads
static options::single< unsigned > nSumThreads
Definition: copyRequest.h:127