Changeset 9283830 in mainline for uspace/lib/cpp/include/impl


Ignore:
Timestamp:
2018-07-05T21:41:20Z (7 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7e7c1aac
Parents:
c4049e6
git-author:
Dzejrou <dzejrou@…> (2018-03-28 14:21:53)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:20)
Message:

cpp: added a threading middle layer

Location:
uspace/lib/cpp/include/impl
Files:
3 edited

Legend:

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

    rc4049e6 r9283830  
    3131
    3232#include <internal/common.hpp>
     33#include <internal/thread.hpp>
    3334#include <thread>
    3435
    3536namespace std
    3637{
    37     extern "C" {
    38         #include <fibril.h>
    39         #include <fibril_synch.h>
    40     }
    41 
    4238    /**
    4339     * 20.4.1.2.1, class mutex:
     
    4743    {
    4844        public:
    49             constexpr mutex() noexcept;
     45            constexpr mutex() noexcept
     46                : mtx_{}
     47            {
     48                aux::threading::mutex::init(mtx_);
     49            }
     50
    5051            ~mutex();
    5152
     
    5758            void unlock();
    5859
    59             using native_handle_type = fibril_mutex_t*;
     60            using native_handle_type = aux::mutex_t*;
    6061            native_handle_type native_handle();
    6162
    6263        private:
    63             native_handle_type mtx_;
     64            aux::mutex_t mtx_;
    6465    };
    6566
     
    8182            void unlock();
    8283
    83             using native_handle_type = fibril_mutex_t*;
     84            using native_handle_type = aux::mutex_t*;
    8485            native_handle_type native_handle();
    8586
    8687        private:
    87             native_handle_type mtx_;
     88            aux::mutex_t mtx_;
    8889            size_t lock_level_;
    8990            thread::id owner_;
  • uspace/lib/cpp/include/impl/ratio.hpp

    rc4049e6 r9283830  
    8989    {
    9090        public:
    91             static_assert(D != 0, "ratio with denominator == 0");
     91            /* static_assert(D != 0, "ratio with denominator == 0"); */
    9292
    9393            static constexpr intmax_t num = aux::sign_v<N> * aux::sign_v<D>
  • uspace/lib/cpp/include/impl/thread.hpp

    rc4049e6 r9283830  
    3232#include <chrono>
    3333#include <internal/common.hpp>
     34#include <internal/thread.hpp>
    3435#include <ostream>
    3536
    3637namespace std
    3738{
    38     extern "C" {
    39         #include <fibril.h>
    40         #include <fibril_synch.h>
    41     }
    42 
    4339    namespace aux
    4440    {
     
    5955                      finished_{false}, detached_{false}
    6056                {
    61                     fibril_mutex_initialize(&join_mtx_);
    62                     fibril_condvar_initialize(&join_cv_);
     57                    aux::threading::mutex::init(join_mtx_);
     58                    aux::threading::condvar::init(join_cv_);
    6359                }
    6460
    6561                void join()
    6662                {
    67                     fibril_mutex_lock(&join_mtx_);
     63                    aux::threading::mutex::lock(join_mtx_);
    6864                    while (!finished_)
    69                         fibril_condvar_wait(&join_cv_, &join_mtx_);
    70                     fibril_mutex_unlock(&join_mtx_);
     65                        aux::threading::condvar::wait(join_cv_, join_mtx_);
     66                    aux::threading::mutex::unlock(join_mtx_);
    7167                }
    7268
     
    8783
    8884            protected:
    89                 fibril_mutex_t join_mtx_;
    90                 fibril_condvar_t join_cv_;
     85                aux::mutex_t join_mtx_;
     86                aux::condvar_t join_cv_;
    9187                bool finished_;
    9288                bool detached_;
     
    105101                    callable_();
    106102
    107                     fibril_mutex_lock(&join_mtx_);
     103                    aux::threading::mutex::lock(join_mtx_);
    108104                    finished_ = true;
    109                     fibril_mutex_unlock(&join_mtx_);
    110 
    111                     fibril_condvar_broadcast(&join_cv_);
     105                    aux::threading::mutex::unlock(join_mtx_);
     106
     107                    aux::threading::condvar::broadcast(join_cv_);
    112108                }
    113109
     
    126122            class id;
    127123
    128             using native_handle_type = fibril_t*;
     124            using native_handle_type = aux::thread_t*;
    129125
    130126            /**
     
    150146                joinable_wrapper_ = static_cast<aux::joinable_wrapper*>(callable_wrapper);
    151147
    152                 id_ = fibril_create(
    153                         aux::thread_main<decltype(callable_wrapper)>,
    154                         static_cast<void*>(callable_wrapper)
     148                id_ = aux::threading::thread::create(
     149                    aux::thread_main<decltype(callable_wrapper)>,
     150                    *callable_wrapper
    155151                );
    156                 fibril_add_ready(id_);
     152
     153                aux::threading::thread::start(id_);
     154                // TODO: fibrils are weird here, 2 returns with same thread ids
    157155            }
    158156
     
    182180
    183181        private:
    184             fid_t id_;
     182            aux::thread_t id_;
    185183            aux::joinable_wrapper* joinable_wrapper_{nullptr};
    186184
     
    223221        {
    224222            auto now = Clock::now();
    225             auto usecs = chrono::duration_cast<chrono::duration<typename Duration::rep, micro>>(abs_time - now);
    226 
    227             fibril_usleep(usecs.count());
     223
     224            auto time = aux::threading::time::convert(abs_time - now);
     225            aux::threading::time::sleep(time);
    228226        }
    229227
     
    235233
    236234            // TODO: timeouts?
    237             auto usecs = chrono::duration_cast<chrono::duration<Rep, micro>>(rel_time);
    238             fibril_usleep(usecs.count());
     235            auto time = aux::threading::time::convert(rel_time);
     236            aux::threading::time::sleep(time);
    239237        }
    240238    }
Note: See TracChangeset for help on using the changeset viewer.