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-03-14 12:33:06 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         674 : Thread_barrier_standard::Thread_barrier_standard(const uint32_t n_threads)
      13         674 :   : n_threads(n_threads)
      14         674 :   , count(0)
      15             : {
      16         674 : }
      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        8947 : Thread_barrier_standard::arrive()
      26             : {
      27        8947 :     this->count++;
      28        9156 :     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        8987 : }
      36             : 
      37             : void
      38        1180 : Thread_barrier_standard::reset()
      39             : {
      40        1180 :     this->count = 0;
      41        1178 : }
      42             : 
      43             : void
      44        1173 : Thread_barrier_standard::wait()
      45             : {
      46       59518 :     while (this->count != this->n_threads)
      47       58343 :         std::this_thread::sleep_for(std::chrono::microseconds(1));
      48        1174 :     this->reset();
      49        1179 : }
      50             : 
      51             : }
      52             : }

Generated by: LCOV version 1.14