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

STEllAR-GROUP / hpx / #853

19 Dec 2022 01:01AM UTC coverage: 86.287% (+0.4%) from 85.912%
#853

push

StellarBot
Merge #6109

6109: Modernize serialization module r=hkaiser a=hkaiser

- flyby separate serialization of Boost types

working towards https://github.com/STEllAR-GROUP/hpx/issues/5497

Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

53 of 53 new or added lines in 6 files covered. (100.0%)

173939 of 201582 relevant lines covered (86.29%)

1931657.12 hits per line

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

95.35
/libs/core/synchronization/include/hpx/synchronization/recursive_mutex.hpp
1
//  Copyright (c) 2007-2022 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
//  Part of this code has been adopted from code published under the BSL by:
8
//
9
//  (C) Copyright 2006-7 Anthony Williams
10

11
#pragma once
12

13
#include <hpx/config.hpp>
14
#include <hpx/assert.hpp>
15
#include <hpx/execution_base/agent_ref.hpp>
16
#include <hpx/execution_base/this_thread.hpp>
17
#include <hpx/synchronization/spinlock.hpp>
18

19
#include <atomic>
20
#include <cstddef>
21
#include <cstdint>
22

23
///////////////////////////////////////////////////////////////////////////////
24
namespace hpx {
25

26
    namespace detail {
27

28
        /// An exclusive-ownership recursive mutex which implements Boost.Thread's
29
        /// TimedLockable concept.
30
        template <typename Mutex = hpx::spinlock>
31
        struct recursive_mutex_impl
32
        {
33
        public:
34
            HPX_NON_COPYABLE(recursive_mutex_impl);
35

36
        private:
37
            std::atomic<std::uint64_t> recursion_count;
38
            std::atomic<hpx::execution_base::agent_ref> locking_context;
39
            Mutex mtx;
40

41
        public:
42
            recursive_mutex_impl(
5,890✔
43
                char const* const desc = "recursive_mutex_impl")
44
              : recursion_count(0)
5,890✔
45
              , mtx(desc)
5,890✔
46
            {
47
            }
5,890✔
48

49
            /// Attempts to acquire ownership of the \a recursive_mutex.
50
            /// Never blocks.
51
            ///
52
            /// \returns \a true if ownership was acquired; otherwise, \a false.
53
            ///
54
            /// \throws Never throws.
55
            bool try_lock()
267✔
56
            {
57
                auto ctx = hpx::execution_base::this_thread::agent();
267✔
58
                HPX_ASSERT(ctx);
267✔
59

60
                return try_recursive_lock(ctx) || try_basic_lock(ctx);
267✔
61
            }
62

63
            /// Acquires ownership of the \a recursive_mutex. Suspends the
64
            /// current HPX-thread if ownership cannot be obtained immediately.
65
            ///
66
            /// \throws Throws \a hpx#error#bad_parameter if an error occurs
67
            ///         while suspending. Throws \a hpx#error#yield_aborted if
68
            ///         the mutex is destroyed while suspended. Throws \a
69
            ///         hpx#error#null_thread_id if called outside of a
70
            ///         HPX-thread.
71
            void lock()
40,336✔
72
            {
73
                auto ctx = hpx::execution_base::this_thread::agent();
40,336✔
74
                HPX_ASSERT(ctx);
40,336✔
75

76
                if (!try_recursive_lock(ctx))
40,336✔
77
                {
78
                    mtx.lock();
29,581✔
79
                    locking_context.exchange(ctx);
29,581✔
80
                    util::ignore_lock(&mtx);
29,581✔
81
                    util::register_lock(this);
29,581✔
82
                    recursion_count.store(1);
29,581✔
83
                }
29,581✔
84
            }
40,336✔
85

86
            /// Release ownership of the \a recursive_mutex.
87
            ///
88
            /// \throws Throws \a hpx#error#bad_parameter if an error occurs
89
            ///         while releasing the mutex. Throws \a
90
            ///         hpx#error#null_thread_id if called outside of a
91
            ///         HPX-thread.
92
            void unlock()
40,603✔
93
            {
94
                if (0 == --recursion_count)
40,603✔
95
                {
96
                    locking_context.exchange(hpx::execution_base::agent_ref());
29,848✔
97
                    util::unregister_lock(this);
29,848✔
98
                    util::reset_ignored(&mtx);
29,848✔
99
                    mtx.unlock();
29,848✔
100
                }
29,848✔
101
            }
40,603✔
102

103
        private:
104
            bool try_recursive_lock(
40,603✔
105
                hpx::execution_base::agent_ref current_context)
106
            {
107
                if (locking_context.load(std::memory_order_acquire) ==
40,603✔
108
                    current_context)
109
                {
110
                    if (++recursion_count == 1)
10,755✔
111
                        util::register_lock(this);
×
112
                    return true;
10,755✔
113
                }
114
                return false;
29,848✔
115
            }
40,603✔
116

117
            bool try_basic_lock(hpx::execution_base::agent_ref current_context)
267✔
118
            {
119
                if (mtx.try_lock())
267✔
120
                {
121
                    locking_context.exchange(current_context);
267✔
122
                    util::ignore_lock(&mtx);
267✔
123
                    util::register_lock(this);
267✔
124
                    recursion_count.store(1);
267✔
125
                    return true;
267✔
126
                }
127
                return false;
×
128
            }
267✔
129
        };
130
    }    // namespace detail
131

132
    using recursive_mutex = detail::recursive_mutex_impl<>;
133
}    // namespace hpx
134

135
namespace hpx::lcos::local {
136

137
    using recursive_mutex HPX_DEPRECATED_V(1, 8,
138
        "hpx::lcos::local::recursive_mutex is deprecated, use "
139
        "hpx::recursive_mutex instead") = hpx::recursive_mutex;
140
}    // namespace hpx::lcos::local
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