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

STEllAR-GROUP / hpx / #879

02 Feb 2023 09:18PM UTC coverage: 86.575% (+0.05%) from 86.523%
#879

push

StellarBot
Merge #6161

6161: Update EVE integration r=hkaiser a=srinivasyadav18

## Proposed Changes

  - use new tag for eve fetch content : hpx-v1.9.0
  - delete FindEve.cmake, instead use `find_package(eve)`
  - replace alias `Eve::eve` with `eve::eve`
  - cleanup eve header inclusions

Co-authored-by: srinivasyadav18 <srinivasyadav227@icloud.com>

174856 of 201970 relevant lines covered (86.58%)

1949482.83 hits per line

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

77.92
/libs/core/synchronization/src/mutex.cpp
1
//  Copyright (c) 2007-2023 Hartmut Kaiser
2
//  Copyright (c) 2013-2015 Agustin Berge
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/synchronization/mutex.hpp>
9

10
#include <hpx/assert.hpp>
11
#include <hpx/coroutines/thread_enums.hpp>
12
#include <hpx/lock_registration/detail/register_locks.hpp>
13
#include <hpx/modules/errors.hpp>
14
#include <hpx/modules/itt_notify.hpp>
15
#include <hpx/synchronization/condition_variable.hpp>
16
#include <hpx/synchronization/spinlock.hpp>
17
#include <hpx/threading_base/thread_data.hpp>
18
#include <hpx/timing/steady_clock.hpp>
19

20
#include <mutex>
21
#include <utility>
22

23
namespace hpx {
24

25
    ///////////////////////////////////////////////////////////////////////////
26
#if HPX_HAVE_ITTNOTIFY != 0
27
    mutex::mutex(char const* const description)
28
      : owner_id_(threads::invalid_thread_id)
29
    {
30
        HPX_ITT_SYNC_CREATE(this, "hpx::mutex", description);
31
        HPX_ITT_SYNC_RENAME(this, "hpx::mutex");
32
    }
33
#endif
34

35
#if HPX_HAVE_ITTNOTIFY != 0
36
    mutex::~mutex()
37
    {
38
        HPX_ITT_SYNC_DESTROY(this);
39
    }
40
#else
41
    mutex::~mutex() = default;
307,714✔
42
#endif
43

44
    void mutex::lock(char const* description, error_code& ec)
1,663,385✔
45
    {
46
        HPX_ASSERT(threads::get_self_ptr() != nullptr);
1,663,385✔
47

48
        HPX_ITT_SYNC_PREPARE(this);
1,662,815✔
49
        std::unique_lock<mutex_type> l(mtx_);
1,662,815✔
50

51
        threads::thread_id_type self_id = threads::get_self_id();
1,662,815✔
52
        if (owner_id_ == self_id)
1,662,815✔
53
        {
54
            HPX_ITT_SYNC_CANCEL(this);
×
55
            l.unlock();
×
56
            HPX_THROWS_IF(ec, hpx::error::deadlock, description,
×
57
                "The calling thread already owns the mutex");
58
            return;
×
59
        }
60

61
        while (owner_id_ != threads::invalid_thread_id)
1,662,891✔
62
        {
63
            cond_.wait(l, ec);
76✔
64
            if (ec)
76✔
65
            {
66
                HPX_ITT_SYNC_CANCEL(this);
×
67
                return;
×
68
            }
69
        }
70

71
        util::register_lock(this);
1,663,017✔
72
        HPX_ITT_SYNC_ACQUIRED(this);
1,663,017✔
73
        owner_id_ = self_id;
1,663,017✔
74
    }
1,662,782✔
75

76
    bool mutex::try_lock(char const* /* description */, error_code& /* ec */)
130✔
77
    {
78
        HPX_ASSERT(threads::get_self_ptr() != nullptr);
130✔
79

80
        HPX_ITT_SYNC_PREPARE(this);
130✔
81
        std::unique_lock<mutex_type> l(mtx_);
130✔
82

83
        if (owner_id_ != threads::invalid_thread_id)
130✔
84
        {
85
            HPX_ITT_SYNC_CANCEL(this);
×
86
            return false;
×
87
        }
88

89
        threads::thread_id_type self_id = threads::get_self_id();
130✔
90
        util::register_lock(this);
130✔
91
        HPX_ITT_SYNC_ACQUIRED(this);
130✔
92
        owner_id_ = self_id;
130✔
93
        return true;
130✔
94
    }
130✔
95

96
    void mutex::unlock(error_code& ec)
1,663,675✔
97
    {
98
        HPX_ASSERT(threads::get_self_ptr() != nullptr);
1,663,675✔
99

100
        HPX_ITT_SYNC_RELEASING(this);
1,663,023✔
101
        // Unregister lock early as the lock guard below may suspend.
102
        util::unregister_lock(this);
1,663,023✔
103
        std::unique_lock<mutex_type> l(mtx_);
1,663,023✔
104

105
        threads::thread_id_type self_id = threads::get_self_id();
1,663,023✔
106
        if (HPX_UNLIKELY(owner_id_ != self_id))
1,663,023✔
107
        {
108
            l.unlock();
×
109
            HPX_THROWS_IF(ec, hpx::error::lock_error, "mutex::unlock",
×
110
                "The calling thread does not own the mutex");
111
            return;
×
112
        }
113

114
        HPX_ITT_SYNC_RELEASED(this);
1,663,149✔
115
        owner_id_ = threads::invalid_thread_id;
1,663,149✔
116

117
        {
118
            [[maybe_unused]] util::ignore_while_checking il(&l);
1,663,149✔
119

120
            // Failing to release lock 'no_mtx' in function
121
#if defined(HPX_MSVC)
122
#pragma warning(push)
123
#pragma warning(disable : 26115)
124
#endif
125

126
            cond_.notify_one(HPX_MOVE(l), threads::thread_priority::boost, ec);
1,663,023✔
127

128
#if defined(HPX_MSVC)
129
#pragma warning(pop)
130
#endif
131
        }
1,663,149✔
132
    }
1,663,149✔
133

134
    ///////////////////////////////////////////////////////////////////////////
135
    timed_mutex::timed_mutex(char const* const description)
4✔
136
      : mutex(description)
4✔
137
    {
4✔
138
    }
4✔
139

140
    timed_mutex::~timed_mutex() = default;
4✔
141

142
    bool timed_mutex::try_lock_until(
6✔
143
        hpx::chrono::steady_time_point const& abs_time,
144
        char const* /* description */, error_code& ec)
145
    {
146
        HPX_ASSERT(threads::get_self_ptr() != nullptr);
6✔
147

148
        HPX_ITT_SYNC_PREPARE(this);
6✔
149
        std::unique_lock<mutex_type> l(mtx_);
6✔
150

151
        threads::thread_id_type self_id = threads::get_self_id();
6✔
152
        if (owner_id_ != threads::invalid_thread_id)
6✔
153
        {
154
            threads::thread_restart_state const reason =
2✔
155
                cond_.wait_until(l, abs_time, ec);
2✔
156
            if (ec)
2✔
157
            {
158
                HPX_ITT_SYNC_CANCEL(this);
×
159
                return false;
×
160
            }
161

162
            if (reason == threads::thread_restart_state::timeout)    //-V110
2✔
163
            {
164
                HPX_ITT_SYNC_CANCEL(this);
2✔
165
                return false;
2✔
166
            }
167

168
            if (owner_id_ != threads::invalid_thread_id)    //-V110
×
169
            {
170
                HPX_ITT_SYNC_CANCEL(this);
×
171
                return false;
×
172
            }
173
        }
×
174

175
        util::register_lock(this);
4✔
176
        HPX_ITT_SYNC_ACQUIRED(this);
4✔
177
        owner_id_ = self_id;
4✔
178
        return true;
4✔
179
    }
6✔
180
}    // namespace hpx
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

© 2025 Coveralls, Inc