Changeset baed175 in mainline
- Timestamp:
- 2018-07-05T21:41:23Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 09e02ee
- Parents:
- db54a9d
- git-author:
- Dzejrou <dzejrou@…> (2018-05-09 23:06:44)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:23)
- Location:
- uspace/lib/cpp/include/internal/memory
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/internal/memory/shared_payload.hpp
rdb54a9d rbaed175 72 72 virtual refcount_t weak_refs() const noexcept = 0; 73 73 virtual bool expired() const noexcept = 0; 74 virtual shared_payload_base* lock() noexcept = 0; 74 75 75 76 virtual ~shared_payload_base() = default; … … 145 146 { 146 147 if (__atomic_sub_fetch(&refcount_, 1, __ATOMIC_ACQ_REL) == 0) 147 return decrement_weak(); 148 { 149 /** 150 * First call to destroy() will delete the held object, 151 * so it doesn't matter what the weak_refcount_ is, 152 * but we added one and we need to remove it now. 153 */ 154 decrement_weak(); 155 156 return true; 157 } 148 158 else 149 159 return false; … … 168 178 { 169 179 return refs() == 0; 180 } 181 182 shared_payload_base<T>* lock() noexcept override 183 { 184 refcount_t rfs = refs(); 185 while (rfs != 0L) 186 { 187 if (__atomic_compare_exchange_n(&refcount_, &rfs, rfs + 1, 188 true, __ATOMIC_RELAXED, 189 __ATOMIC_RELAXED)) 190 { 191 return this; 192 } 193 } 194 195 return nullptr; 170 196 } 171 197 -
uspace/lib/cpp/include/internal/memory/shared_ptr.hpp
rdb54a9d rbaed175 31 31 32 32 #include <exception> 33 #include < functional>33 #include <internal/functional/arithmetic_operations.hpp> 34 34 #include <internal/memory/allocator_arg.hpp> 35 35 #include <internal/memory/shared_payload.hpp> … … 333 333 { 334 334 if (payload_) 335 return payload_->ref count();335 return payload_->refs(); 336 336 else 337 337 return 0L;
Note:
See TracChangeset
for help on using the changeset viewer.