• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.59
/libs/core/concurrency/src/barrier.cpp
1
//  Copyright (c) 2017-2023 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/config.hpp>
8
#include <hpx/concurrency/barrier.hpp>
9

10
#include <cstddef>
11

12
namespace hpx::util {
13

14
    barrier::barrier(std::size_t number_of_threads)
484✔
15
      : number_of_threads_(number_of_threads)
484✔
16
      , total_(barrier_flag)
484✔
17
      , mtx_()
484✔
18
      , cond_()
484✔
19
    {
20
    }
484✔
21

22
    barrier::~barrier()
484✔
23
    {
24
        std::unique_lock<mutex_type> l(mtx_);
484✔
25

26
        while (total_ > barrier_flag)
484✔
27
        {
28
            // Wait until everyone exits the barrier
29
            cond_.wait(l);    //-V1089
×
30
        }
31
    }
484✔
32

33
    void barrier::wait()
254✔
34
    {
35
        std::unique_lock<mutex_type> l(mtx_);
254✔
36

37
        while (total_ > barrier_flag)
254✔
38
        {
39
            // wait until everyone exits the barrier
40
            cond_.wait(l);    //-V1089
×
41
        }
42

43
        // Are we the first to enter?
44
        if (total_ == barrier_flag)
254✔
45
            total_ = 0;
84✔
46

47
        ++total_;
254✔
48

49
        if (total_ == number_of_threads_)
254✔
50
        {
51
            total_ += barrier_flag - 1;
84✔
52
            cond_.notify_all();
84✔
53
        }
54
        else
55
        {
56
            while (total_ < barrier_flag)
340✔
57
            {
58
                // wait until enough threads enter the barrier
59
                cond_.wait(l);    //-V1089
170✔
60
            }
61
            --total_;
170✔
62

63
            // get entering threads to wake up
64
            if (total_ == barrier_flag)
170✔
65
            {
66
                cond_.notify_all();
84✔
67
            }
68
        }
69
    }
254✔
70
}    // namespace hpx::util
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc