source: mainline/uspace/lib/cpp/include/__bits/refcount_obj.hpp@ c6f23a7

Last change on this file since c6f23a7 was b57ba05, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Update headers in C++ files

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2019 Jaroslav Jindrak
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef LIBCPP_BITS_REFCOUNT_OBJ
8#define LIBCPP_BITS_REFCOUNT_OBJ
9
10namespace std::aux
11{
12 /**
13 * At the moment we do not have atomics, change this
14 * to std::atomic<long> once we do.
15 */
16 using refcount_t = long;
17
18 class refcount_obj
19 {
20 public:
21 refcount_obj() = default;
22
23 void increment() noexcept;
24 void increment_weak() noexcept;
25 bool decrement() noexcept;
26 bool decrement_weak() noexcept;
27 refcount_t refs() const noexcept;
28 refcount_t weak_refs() const noexcept;
29 bool expired() const noexcept;
30
31 virtual ~refcount_obj() = default;
32 virtual void destroy() = 0;
33
34 protected:
35 /**
36 * We're using a trick where refcount_ > 0
37 * means weak_refcount_ has 1 added to it,
38 * this makes it easier for weak_ptrs that
39 * can't decrement the weak_refcount_ to
40 * zero with shared_ptrs using this object.
41 */
42 refcount_t refcount_{1};
43 refcount_t weak_refcount_{1};
44 };
45}
46
47#endif
Note: See TracBrowser for help on using the repository browser.