Changeset 69e5838 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:20Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
55aa951
Parents:
4bea22a
git-author:
Dzejrou <dzejrou@…> (2018-03-28 20:40:27)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:20)
Message:

cpp: added timed_mutex

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/mutex.hpp

    r4bea22a r69e5838  
    7272    {
    7373        public:
    74             constexpr recursive_mutex() noexcept;
     74            constexpr recursive_mutex() noexcept
     75                : mtx_{}, lock_level_{}, owner_{}
     76            {
     77                aux::threading::mutex::init(mtx_);
     78            }
     79
    7580            ~recursive_mutex();
    7681
     
    95100     */
    96101
    97     // TODO: implement
    98     class timed_mutex;
     102    class timed_mutex
     103    {
     104        public:
     105            timed_mutex() noexcept;
     106            ~timed_mutex();
     107
     108            timed_mutex(const timed_mutex&) = delete;
     109            timed_mutex& operator=(const timed_mutex&) = delete;
     110
     111            void lock();
     112            bool try_lock();
     113            void unlock();
     114
     115            template<class Rep, class Period>
     116            bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
     117            {
     118                auto time = aux::threading::time::convert(rel_time);
     119
     120                return aux::threading::mutex::try_lock_for(time);
     121            }
     122
     123            template<class Clock, class Duration>
     124            bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time)
     125            {
     126                auto dur = (abs_time - Clock::now());
     127                auto time = aux::threading::time::convert(dur);
     128
     129                return aux::threading::mutex::try_lock_for(time);
     130            }
     131
     132            using native_handle_type = aux::mutex_t*;
     133            native_handle_type native_handle();
     134
     135        private:
     136            aux::mutex_t mtx_;
     137    };
    99138
    100139    /**
Note: See TracChangeset for help on using the changeset viewer.