Changeset 8e24583 in mainline for uspace/lib/cpp/include/__bits/thread


Ignore:
Timestamp:
2019-07-03T16:59:49Z (6 years ago)
Author:
Jaroslav Jindrak <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
46c66f8
Parents:
96fec16
Message:

cpp: write tests for <future> and fix minor bugs they found

Location:
uspace/lib/cpp/include/__bits/thread
Files:
5 edited

Legend:

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

    r96fec16 r8e24583  
    101101                    state_ = move(rhs.state_);
    102102                    rhs.state_ = nullptr;
     103
     104                    return *this;
    103105                }
    104106
     
    183185
    184186            future(future&& rhs) noexcept
    185                 : aux::future_base<aux::future_inner_t<R>>{move(rhs.state_)}
     187                : aux::future_base<aux::future_inner_t<R>>{move(rhs)}
    186188            { /* DUMMY BODY */ }
    187189
     
    220222                }
    221223            }
     224
     225            /**
     226             * Useful for testing as we can check some information
     227             * otherwise unavailable to us without waiting, e.g.
     228             * to check whether the state is ready, its reference
     229             * count etc.
     230             */
     231            aux::shared_state<aux::future_inner_t<R>>* __state() noexcept
     232            {
     233                return this->state_;
     234            }
    222235    };
    223236}
  • uspace/lib/cpp/include/__bits/thread/packaged_task.hpp

    r96fec16 r8e24583  
    127127                func_ = move(rhs.func_);
    128128                state_ = move(rhs.state_);
     129                rhs.state_ = nullptr;
    129130
    130131                return *this;
  • uspace/lib/cpp/include/__bits/thread/promise.hpp

    r96fec16 r8e24583  
    109109                }
    110110
     111                /**
     112                 * Useful for testing as we can check some information
     113                 * otherwise unavailable to us without waiting, e.g.
     114                 * to check whether the state is ready, its reference
     115                 * count etc.
     116                 */
     117                aux::shared_state<R>* __state()
     118                {
     119                    return state_;
     120                }
     121
    111122            protected:
    112123                void abandon_state_()
     
    250261                try
    251262                {
    252                     this->state_->set_value(forward(val), false);
     263                    this->state_->set_value(forward<R>(val), false);
    253264                    aux::set_state_value_at_thread_exit(this->state_);
    254265                }
  • uspace/lib/cpp/include/__bits/thread/shared_future.hpp

    r96fec16 r8e24583  
    9696                }
    9797            }
     98
     99            /**
     100             * Useful for testing as we can check some information
     101             * otherwise unavailable to us without waiting, e.g.
     102             * to check whether the state is ready, its reference
     103             * count etc.
     104             */
     105            aux::shared_state<aux::future_inner_t<R>>* __state() noexcept
     106            {
     107                return this->state_;
     108            }
    98109    };
    99110}
  • uspace/lib/cpp/include/__bits/thread/shared_state.hpp

    r96fec16 r8e24583  
    115115            wait_for(const chrono::duration<Rep, Period>& rel_time)
    116116            {
     117                if (value_set_)
     118                    return future_status::ready;
     119
    117120                aux::threading::mutex::lock(mutex_);
    118121                auto res = timed_wait_(
     
    128131            wait_until(const chrono::time_point<Clock, Duration>& abs_time)
    129132            {
     133                if (value_set_)
     134                    return future_status::ready;
     135
    130136                aux::threading::mutex::lock(mutex_);
    131137                auto res = timed_wait_(
     
    189195                aux::threading::mutex::unlock(mutex_);
    190196
    191                 aux::threading::condvar::broadcast(condvar_);
     197                if (set)
     198                    aux::threading::condvar::broadcast(condvar_);
    192199            }
    193200
     
    199206                aux::threading::mutex::unlock(mutex_);
    200207
    201                 aux::threading::condvar::broadcast(condvar_);
     208                if (set)
     209                    aux::threading::condvar::broadcast(condvar_);
    202210            }
    203211
     
    293301
    294302        protected:
    295             future_status timed_wait_(aux::time_unit_t) override
     303            future_status timed_wait_(aux::time_unit_t time) override
    296304            {
    297305                /**
     
    299307                 *       behaviour should be compliant.
    300308                 */
    301                 return future_status::timeout;
     309                aux::threading::time::sleep(time);
     310                if (this->value_set_)
     311                    return future_status::ready;
     312                else
     313                    return future_status::timeout;
    302314            }
    303315
Note: See TracChangeset for help on using the changeset viewer.