LCOV - code coverage report
Current view: top level - include/Tools/Thread/Thread_barrier/Standard - Thread_barrier_standard.hxx (source / functions) Hit Total Coverage
Test: streampu_clean.info Lines: 16 25 64.0 %
Date: 2025-01-11 12:25:42 Functions: 4 5 80.0 %

          Line data    Source code
       1             : #include <iostream>
       2             : #include <sstream>
       3             : 
       4             : #include "Tools/Exception/exception.hpp"
       5             : #include "Tools/Thread/Thread_barrier/Standard/Thread_barrier_standard.hpp"
       6             : 
       7             : namespace spu
       8             : {
       9             : namespace tools
      10             : {
      11             : 
      12         592 : Thread_barrier_standard::Thread_barrier_standard(const uint32_t n_threads)
      13         592 :   : n_threads(n_threads)
      14         592 :   , count(0)
      15             : {
      16         592 : }
      17             : 
      18           0 : Thread_barrier_standard::Thread_barrier_standard(const Thread_barrier_standard& other)
      19           0 :   : n_threads(other.n_threads)
      20           0 :   , count(0)
      21             : {
      22           0 : }
      23             : 
      24             : void
      25        7538 : Thread_barrier_standard::arrive()
      26             : {
      27        7538 :     this->count++;
      28        7946 :     if (this->count > this->n_threads)
      29             :     {
      30           0 :         std::stringstream message;
      31           0 :         message << "Something went wrong, 'count' cannot be higher than 'n_threads' ('count' = " << this->count
      32           0 :                 << " , 'n_threads' = " << n_threads << ").";
      33           0 :         throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str());
      34           0 :     }
      35        7641 : }
      36             : 
      37             : void
      38        1028 : Thread_barrier_standard::reset()
      39             : {
      40        1028 :     this->count = 0;
      41        1034 : }
      42             : 
      43             : void
      44        1028 : Thread_barrier_standard::wait()
      45             : {
      46       78421 :     while (this->count != this->n_threads)
      47       77377 :         std::this_thread::sleep_for(std::chrono::microseconds(1));
      48        1027 :     this->reset();
      49        1034 : }
      50             : 
      51             : }
      52             : }

Generated by: LCOV version 1.14