Ignore:
Timestamp:
2019-07-24T11:44:40Z (6 years ago)
Author:
GitHub <noreply@…>
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)
Message:

Merge pull request #171 from Dzejrou/hackweek

C++ stdlib: <future>

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/__bits/refcount_obj.hpp

    r9fb280c r9fe2fd7  
    11/*
    2  * Copyright (c) 2018 Jaroslav Jindrak
     2 * Copyright (c) 2019 Jaroslav Jindrak
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #ifndef LIBCPP_BITS_RESULT_OF
    30 #define LIBCPP_BITS_RESULT_OF
     29#ifndef LIBCPP_BITS_REFCOUNT_OBJ
     30#define LIBCPP_BITS_REFCOUNT_OBJ
    3131
    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
     32namespace std::aux
    3933{
    4034    /**
    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.
    4637     */
     38    using refcount_t = long;
    4739
    48     template<class>
    49     struct result_of;
     40    class refcount_obj
     41    {
     42        public:
     43            refcount_obj() = default;
    5044
    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;
    5652
    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    };
    5967}
    6068
Note: See TracChangeset for help on using the changeset viewer.