Changeset 857d4cc in mainline for uspace/lib/cpp/src/mutex.cpp


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:
a97b838
Parents:
befead8
git-author:
Dzejrou <dzejrou@…> (2018-03-29 12:04:13)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:20)
Message:

cpp: added recursive_timed_mutex

File:
1 edited

Legend:

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

    rbefead8 r857d4cc  
    6969    }
    7070
    71     bool recursive_mutex::try_lock()
     71    bool recursive_mutex::try_lock() noexcept
    7272    {
    7373        if (owner_ != this_thread::get_id())
     
    129129        return &mtx_;
    130130    }
     131
     132    recursive_timed_mutex::~recursive_timed_mutex()
     133    { /* DUMMY BODY */ }
     134
     135    void recursive_timed_mutex::lock()
     136    {
     137        if (owner_ != this_thread::get_id())
     138        {
     139            aux::threading::mutex::lock(mtx_);
     140            owner_ = this_thread::get_id();
     141            lock_level_ = 1;
     142        }
     143        else
     144            ++lock_level_;
     145    }
     146
     147    bool recursive_timed_mutex::try_lock()
     148    {
     149        if (owner_ != this_thread::get_id())
     150        {
     151            bool res = aux::threading::mutex::try_lock(mtx_);
     152            if (res)
     153            {
     154                owner_ = this_thread::get_id();
     155                lock_level_ = 1;
     156            }
     157
     158            return res;
     159        }
     160        else
     161            ++lock_level_;
     162
     163        return true;
     164    }
     165
     166    void recursive_timed_mutex::unlock()
     167    {
     168        if (owner_ != this_thread::get_id())
     169            return;
     170        else if (--lock_level_ == 0)
     171            aux::threading::mutex::unlock(mtx_);
     172    }
     173
     174    recursive_timed_mutex::native_handle_type recursive_timed_mutex::native_handle()
     175    {
     176        return &mtx_;
     177    }
    131178}
Note: See TracChangeset for help on using the changeset viewer.