Changeset 3946


Ignore:
Timestamp:
Jul 20, 2020, 7:42:26 AM (2 years ago)
Author:
Peter
Message:

use mutex and locks from std:: rather than boost::. refs #953

Location:
trunk/yat/utility
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/BasicQueue.h

    r3938 r3946  
    2121#include "config_public.h"
    2222
    23 #include <boost/thread.hpp>
     23#include <condition_variable>
     24#include <mutex>
    2425
    2526namespace theplu {
     
    5354    BasicQueue(const BasicQueue& other)
    5455    {
    55       boost::unique_lock<boost::mutex> lock(other.mutex_);
     56      std::unique_lock<std::mutex> lock(other.mutex_);
    5657      q_ = other.q_;
    5758    } // lock is released here
     
    6970    void clear(void)
    7071    {
    71       boost::unique_lock<boost::mutex> lock(mutex_);
     72      std::unique_lock<std::mutex> lock(mutex_);
    7273      return q_.clear();
    7374    }
     
    7980    bool empty(void) const
    8081    {
    81       boost::unique_lock<boost::mutex> lock(mutex_);
     82      std::unique_lock<std::mutex> lock(mutex_);
    8283      return q_.empty();
    8384    } // lock is released here
     
    9394    void pop(T& value)
    9495    {
    95       boost::unique_lock<boost::mutex> lock(mutex_);
     96      std::unique_lock<std::mutex> lock(mutex_);
    9697      while (q_.empty())
    9798        condition_.wait(lock);
     
    110111    void push(const T& t)
    111112    {
    112       boost::unique_lock<boost::mutex> lock(mutex_);
     113      std::unique_lock<std::mutex> lock(mutex_);
    113114      static_cast<Derived*>(this)->push_impl(t, lock);
    114115      lock.unlock(); // unlock the mutex
     
    128129    void push(T&& t)
    129130    {
    130       boost::unique_lock<boost::mutex> lock(mutex_);
     131      std::unique_lock<std::mutex> lock(mutex_);
    131132      static_cast<Derived*>(this)->push_impl(std::move(t), lock);
    132133      lock.unlock(); // unlock the mutex
     
    142143    size_type size(void) const
    143144    {
    144       boost::unique_lock<boost::mutex> lock(mutex_);
     145      std::unique_lock<std::mutex> lock(mutex_);
    145146      return q_.size();
    146147    } // lock is released here
     
    153154    bool try_pop(T& value)
    154155    {
    155       boost::unique_lock<boost::mutex> lock(mutex_);
     156      std::unique_lock<std::mutex> lock(mutex_);
    156157      if (q_.empty())
    157158        return false;
     
    167168    {
    168169      if (this != &other) {
    169         // boost::lock guarantees that the two mutexes are locked in
     170        // std::lock guarantees that the two mutexes are locked in
    170171        // the same order regardless of passed order and thereby
    171172        // avoiding deadlock when two threads are calling
    172173        // lhs.assign(rhs) and rhs.assign(lhs) simultaneously.
    173         boost::lock(mutex_, other.mutex_);
    174         boost::unique_lock<boost::mutex> lock(mutex_, boost::adopt_lock_t());
    175         boost::unique_lock<boost::mutex> other_lock(other.mutex_,
    176                                                     boost::adopt_lock_t());
     174        std::lock(mutex_, other.mutex_);
     175        std::unique_lock<std::mutex> lock(mutex_, std::adopt_lock_t());
     176        std::unique_lock<std::mutex> other_lock(other.mutex_,
     177                                                std::adopt_lock_t());
    177178        q_ = other.q_;
    178179      }
     
    182183    Container q_;
    183184  private:
    184     mutable boost::mutex mutex_;
    185     boost::condition_variable condition_;
     185    mutable std::mutex mutex_;
     186    std::condition_variable condition_;
    186187  };
    187188
  • trunk/yat/utility/PriorityQueue.h

    r3938 r3946  
    9191
    9292  private:
    93     void pop_impl(T& value, const boost::unique_lock<boost::mutex>& lock)
     93    void pop_impl(T& value, const std::unique_lock<std::mutex>& lock)
    9494    {
    9595      // The obvious choice would be to create a temp copy of front,
     
    105105    }
    106106
    107     void push_impl(const T& value, boost::unique_lock<boost::mutex>& lock)
     107    void push_impl(const T& value, std::unique_lock<std::mutex>& lock)
    108108    {
    109109      this->q_.insert(value);
     
    111111
    112112
    113     void push_impl(T&& value, boost::unique_lock<boost::mutex>& lock)
     113    void push_impl(T&& value, std::unique_lock<std::mutex>& lock)
    114114    {
    115115      this->q_.insert(std::move(value));
  • trunk/yat/utility/Queue.h

    r3938 r3946  
    8686
    8787  private:
    88     void pop_impl(T& value, boost::unique_lock<boost::mutex>& lock)
     88    void pop_impl(T& value, std::unique_lock<std::mutex>& lock)
    8989    {
    9090      YAT_ASSERT(this->q_.size());
     
    9494
    9595
    96     void push_impl(const T& value, boost::unique_lock<boost::mutex>& lock)
     96    void push_impl(const T& value, std::unique_lock<std::mutex>& lock)
    9797    {
    9898      this->q_.push_back(value);
     
    100100
    101101
    102     void push_impl(T&& value, boost::unique_lock<boost::mutex>& lock)
     102    void push_impl(T&& value, std::unique_lock<std::mutex>& lock)
    103103    {
    104104      this->q_.push_back(std::move(value));
Note: See TracChangeset for help on using the changeset viewer.