Ignore:
Timestamp:
2019-07-03T16:59:49Z (5 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.