Changeset 9283830 in mainline for uspace/lib/cpp/src/mutex.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/mutex.cpp

    rc4049e6 r9283830  
    3131namespace std
    3232{
    33     constexpr mutex::mutex() noexcept
    34         : mtx_{}
    35     {
    36         fibril_mutex_initialize(&mtx_);
    37     }
    38 
    3933    mutex::~mutex()
    40     {
    41         if (fibril_mutex_is_locked(&mtx_))
    42         {
    43             /**
    44              * According to the standard, this is
    45              * undefined behavior, we could unlock the
    46              * mutex, but that could cause issues if we
    47              * are not the current owner.
    48              */
    49             // fibril_mutex_unlock(&mtx_);
    50         }
    51     }
     34    { /* DUMMY BODY */ }
    5235
    5336    void mutex::lock()
    5437    {
    55         fibril_mutex_lock(&mtx_);
     38        aux::threading::mutex::lock(mtx_);
    5639    }
    5740
    5841    bool mutex::try_lock()
    5942    {
    60         return fibril_mutex_trylock(&mtx_);
     43        return aux::threading::mutex::try_lock(mtx_);
    6144    }
    6245
    6346    void mutex::unlock()
    6447    {
    65         fibril_mutex_unlock(&mtx_);
     48        aux::threading::mutex::unlock(mtx_);
    6649    }
    6750
     
    7457        : mtx_{}, lock_level_{}, owner_{}
    7558    {
    76         fibril_mutex_initialize(&mtx_);
     59        aux::threading::mutex::init(mtx_);
    7760    }
    7861
     
    8467        if (owner_ != this_thread::get_id())
    8568        {
    86             fibril_mutex_lock(&mtx_);
     69            aux::threading::mutex::lock(mtx_);
    8770            owner_ = this_thread::get_id();
    8871            lock_level_ = 1;
     
    9679        if (owner_ != this_thread::get_id())
    9780        {
    98             bool res = fibril_mutex_trylock(&mtx_);
     81            bool res = aux::threading::mutex::try_lock(mtx_);
    9982            if (res)
    10083            {
     
    11699            return;
    117100        else if (--lock_level_ == 0)
    118             fibril_mutex_unlock(&mtx_);
     101            aux::threading::mutex::unlock(mtx_);
    119102    }
    120103
Note: See TracChangeset for help on using the changeset viewer.