Changeset 9fe2fd7 in mainline for uspace/lib/cpp/include/__bits/refcount_obj.hpp
- Timestamp:
- 2019-07-24T11:44:40Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a448937, f42ee6f
- Parents:
- 9fb280c (diff), 8c0b781 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Jaroslav Jindrak <Dzejrou@…> (2019-07-24 11:44:40)
- git-committer:
- GitHub <noreply@…> (2019-07-24 11:44:40)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/__bits/refcount_obj.hpp
r9fb280c r9fe2fd7 1 1 /* 2 * Copyright (c) 201 8Jaroslav Jindrak2 * Copyright (c) 2019 Jaroslav Jindrak 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 #ifndef LIBCPP_BITS_RE SULT_OF30 #define LIBCPP_BITS_RE SULT_OF29 #ifndef LIBCPP_BITS_REFCOUNT_OBJ 30 #define LIBCPP_BITS_REFCOUNT_OBJ 31 31 32 /** 33 * TODO: We have two implementations and I can't remember which 34 * one is the correnct one, investigate! 35 */ 36 #include <__bits/invoke.hpp> 37 38 namespace std 32 namespace std::aux 39 33 { 40 34 /** 41 * Note: This doesn't work, C++14 standard allows for F 42 * to be any complete type, our implementation 43 * currently works like the C++11 version where 44 * F has to be callable. 45 * TODO: Fix this. 35 * At the moment we do not have atomics, change this 36 * to std::atomic<long> once we do. 46 37 */ 38 using refcount_t = long; 47 39 48 template<class> 49 struct result_of; 40 class refcount_obj 41 { 42 public: 43 refcount_obj() = default; 50 44 51 template<class F, class... Args> 52 class result_of<F(Args...)>: aux::type_is< 53 decltype(aux::invoke(declval<F>(), declval<ArgTypes>()...)) 54 > 55 { /* DUMMY BODY */ }; 45 void increment() noexcept; 46 void increment_weak() noexcept; 47 bool decrement() noexcept; 48 bool decrement_weak() noexcept; 49 refcount_t refs() const noexcept; 50 refcount_t weak_refs() const noexcept; 51 bool expired() const noexcept; 56 52 57 template<class T> 58 using result_of_t = typename result_of<T>::type; 53 virtual ~refcount_obj() = default; 54 virtual void destroy() = 0; 55 56 protected: 57 /** 58 * We're using a trick where refcount_ > 0 59 * means weak_refcount_ has 1 added to it, 60 * this makes it easier for weak_ptrs that 61 * can't decrement the weak_refcount_ to 62 * zero with shared_ptrs using this object. 63 */ 64 refcount_t refcount_{1}; 65 refcount_t weak_refcount_{1}; 66 }; 59 67 } 60 68
Note:
See TracChangeset
for help on using the changeset viewer.