Changeset 3946
- Timestamp:
- Jul 20, 2020, 7:42:26 AM (2 years ago)
- Location:
- trunk/yat/utility
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/BasicQueue.h
r3938 r3946 21 21 #include "config_public.h" 22 22 23 #include <boost/thread.hpp> 23 #include <condition_variable> 24 #include <mutex> 24 25 25 26 namespace theplu { … … 53 54 BasicQueue(const BasicQueue& other) 54 55 { 55 boost::unique_lock<boost::mutex> lock(other.mutex_);56 std::unique_lock<std::mutex> lock(other.mutex_); 56 57 q_ = other.q_; 57 58 } // lock is released here … … 69 70 void clear(void) 70 71 { 71 boost::unique_lock<boost::mutex> lock(mutex_);72 std::unique_lock<std::mutex> lock(mutex_); 72 73 return q_.clear(); 73 74 } … … 79 80 bool empty(void) const 80 81 { 81 boost::unique_lock<boost::mutex> lock(mutex_);82 std::unique_lock<std::mutex> lock(mutex_); 82 83 return q_.empty(); 83 84 } // lock is released here … … 93 94 void pop(T& value) 94 95 { 95 boost::unique_lock<boost::mutex> lock(mutex_);96 std::unique_lock<std::mutex> lock(mutex_); 96 97 while (q_.empty()) 97 98 condition_.wait(lock); … … 110 111 void push(const T& t) 111 112 { 112 boost::unique_lock<boost::mutex> lock(mutex_);113 std::unique_lock<std::mutex> lock(mutex_); 113 114 static_cast<Derived*>(this)->push_impl(t, lock); 114 115 lock.unlock(); // unlock the mutex … … 128 129 void push(T&& t) 129 130 { 130 boost::unique_lock<boost::mutex> lock(mutex_);131 std::unique_lock<std::mutex> lock(mutex_); 131 132 static_cast<Derived*>(this)->push_impl(std::move(t), lock); 132 133 lock.unlock(); // unlock the mutex … … 142 143 size_type size(void) const 143 144 { 144 boost::unique_lock<boost::mutex> lock(mutex_);145 std::unique_lock<std::mutex> lock(mutex_); 145 146 return q_.size(); 146 147 } // lock is released here … … 153 154 bool try_pop(T& value) 154 155 { 155 boost::unique_lock<boost::mutex> lock(mutex_);156 std::unique_lock<std::mutex> lock(mutex_); 156 157 if (q_.empty()) 157 158 return false; … … 167 168 { 168 169 if (this != &other) { 169 // boost::lock guarantees that the two mutexes are locked in170 // std::lock guarantees that the two mutexes are locked in 170 171 // the same order regardless of passed order and thereby 171 172 // avoiding deadlock when two threads are calling 172 173 // 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()); 177 178 q_ = other.q_; 178 179 } … … 182 183 Container q_; 183 184 private: 184 mutable boost::mutex mutex_;185 boost::condition_variable condition_;185 mutable std::mutex mutex_; 186 std::condition_variable condition_; 186 187 }; 187 188 -
trunk/yat/utility/PriorityQueue.h
r3938 r3946 91 91 92 92 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) 94 94 { 95 95 // The obvious choice would be to create a temp copy of front, … … 105 105 } 106 106 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) 108 108 { 109 109 this->q_.insert(value); … … 111 111 112 112 113 void push_impl(T&& value, boost::unique_lock<boost::mutex>& lock)113 void push_impl(T&& value, std::unique_lock<std::mutex>& lock) 114 114 { 115 115 this->q_.insert(std::move(value)); -
trunk/yat/utility/Queue.h
r3938 r3946 86 86 87 87 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) 89 89 { 90 90 YAT_ASSERT(this->q_.size()); … … 94 94 95 95 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) 97 97 { 98 98 this->q_.push_back(value); … … 100 100 101 101 102 void push_impl(T&& value, boost::unique_lock<boost::mutex>& lock)102 void push_impl(T&& value, std::unique_lock<std::mutex>& lock) 103 103 { 104 104 this->q_.push_back(std::move(value));
Note: See TracChangeset
for help on using the changeset viewer.