Changeset 9283830 in mainline for uspace/lib/cpp/src/thread.cpp


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/src/thread.cpp

    rc4049e6 r9283830  
    2828
    2929#include <cstdlib>
     30#include <exception>
    3031#include <thread>
    3132#include <utility>
     33
     34#include <iostream>
    3235
    3336namespace std
     
    3942    thread::~thread()
    4043    {
    41         if (joinable())
    42         {
    43             // TODO: call std::terminate
    44         }
     44        // TODO: investigate joinable() in detail
     45        //       + std::terminate behaves weirdly on HelenOS
     46        if (joinable() && false)
     47            std::terminate();
    4548
     49        // TODO: check for finished too?
     50        // TODO: WAIT! if it's not detached, then
     51        //       we are joinable and std::terminate was called?
     52        // TODO: review this entire thing
    4653        if (joinable_wrapper_ && !joinable_wrapper_->detached())
    4754            delete joinable_wrapper_;
     
    4956
    5057    thread::thread(thread&& other) noexcept
    51         : id_{other.id_}
     58        : id_{other.id_}, joinable_wrapper_{other.joinable_wrapper_}
    5259    {
    53         other.id_ = fid_t{};
     60        other.id_ = aux::thread_t{};
     61        other.joinable_wrapper_ = nullptr;
    5462    }
    5563
     
    5765    {
    5866        if (joinable())
    59         {
    60             // TODO: call std::terminate
    61         }
     67            std::terminate();
    6268
    6369        id_ = other.id_;
    64         other.id_ = fid_t{};
     70        other.id_ = aux::thread_t{};
     71
     72        joinable_wrapper_ = other.joinable_wrapper_;
     73        other.joinable_wrapper_ = nullptr;
    6574
    6675        return *this;
     
    7079    {
    7180        std::swap(id_, other.id_);
     81        std::swap(joinable_wrapper_, other.joinable_wrapper_);
    7282    }
    7383
    7484    bool thread::joinable() const noexcept
    7585    {
    76         return id_ != fid_t{};
     86        return id_ != aux::thread_t{};
    7787    }
    7888
     
    8595    void thread::detach()
    8696    {
    87         id_ = fid_t{};
     97        id_ = aux::thread_t{};
    8898
    8999        if (joinable_wrapper_)
     
    124134        thread::id get_id() noexcept
    125135        {
    126             return thread::id{fibril_get_id()};
     136            return thread::id{aux::threading::thread::this_thread()};
    127137        }
    128138
    129139        void yield() noexcept
    130140        {
    131             fibril_yield();
     141            aux::threading::thread::yield();
    132142        }
    133143    }
Note: See TracChangeset for help on using the changeset viewer.