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

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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.