Changeset 771d162 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:
da6bcc0
Parents:
4e484b5
git-author:
Dzejrou <dzejrou@…> (2018-03-29 15:25:36)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:20)
Message:

cpp: changed mutex destructor to default to allow it to be placed in once_flag, implemented call_once

Location:
uspace/lib/cpp
Files:
2 edited

Legend:

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

    r4e484b5 r771d162  
    3030#define LIBCPP_MUTEX
    3131
     32#include <functional>
    3233#include <internal/common.hpp>
    3334#include <internal/thread.hpp>
     
    4950            }
    5051
    51             ~mutex();
     52            ~mutex() = default;
    5253
    5354            mutex(const mutex&) = delete;
     
    712713    struct once_flag
    713714    {
    714         constexpr once_flag() noexcept;
     715        constexpr once_flag() noexcept
     716            : called_{false}, mtx_{}
     717        { /* DUMMY BODY */ }
    715718
    716719        once_flag(const once_flag&) = delete;
    717720        once_flag& operator=(const once_flag&) = delete;
     721
     722        private:
     723            bool called_;
     724            mutex mtx_;
     725
     726            template<class Callable, class... Args>
     727            friend void call_once(once_flag&, Callable&&, Args&&...);
    718728    };
    719729
    720730    template<class Callable, class... Args>
    721     void call_once(once_flag& flag, Callable&& func, Args&&... args);
     731    void call_once(once_flag& flag, Callable&& func, Args&&... args)
     732    {
     733        flag.mtx_.lock();
     734        if (!flag.called_)
     735        {
     736            // TODO: exception handling
     737
     738            aux::invoke(forward<Callable>(func), forward<Args>(args)...);
     739            flag.called_ = true;
     740        }
     741        flag.mtx_.unlock();
     742    }
    722743}
    723744
  • uspace/lib/cpp/src/mutex.cpp

    r4e484b5 r771d162  
    3131namespace std
    3232{
    33     mutex::~mutex()
    34     { /* DUMMY BODY */ }
    35 
    3633    void mutex::lock()
    3734    {
Note: See TracChangeset for help on using the changeset viewer.