mirror of
				https://github.com/cjcliffe/CubicSDR.git
				synced 2025-11-03 13:10:27 -05:00 
			
		
		
		
	ThreadBlockingQueue : remove useless/dangerous operations, forbid both copy and assignment.
This commit is contained in:
		
							parent
							
								
									afedca05c6
								
							
						
					
					
						commit
						aec0100f78
					
				@ -42,12 +42,11 @@ public:
 | 
				
			|||||||
        m_max_num_items = MIN_ITEM_NB;
 | 
					        m_max_num_items = MIN_ITEM_NB;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    //Copy constructor
 | 
					    //Forbid Copy construction.
 | 
				
			||||||
    ThreadBlockingQueue(const ThreadBlockingQueue& sq) {
 | 
						ThreadBlockingQueue(const ThreadBlockingQueue& sq) = delete;
 | 
				
			||||||
        std::lock_guard < std::mutex > lock(sq.m_mutex);
 | 
					
 | 
				
			||||||
        m_queue = sq.m_queue;
 | 
						/*! Forbid copy assignment. */
 | 
				
			||||||
        m_max_num_items = sq.m_max_num_items;
 | 
						ThreadBlockingQueue& operator=(const ThreadBlockingQueue& sq) = delete;
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*! Destroy safe queue. */
 | 
					    /*! Destroy safe queue. */
 | 
				
			||||||
    ~ThreadBlockingQueue() {
 | 
					    ~ThreadBlockingQueue() {
 | 
				
			||||||
@ -216,54 +215,7 @@ public:
 | 
				
			|||||||
        m_cond_not_full.notify_all();
 | 
					        m_cond_not_full.notify_all();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     *  Swaps the contents.
 | 
					 | 
				
			||||||
     * \param[out] sq The ThreadBlockingQueue to swap with 'this'.
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    void swap(ThreadBlockingQueue& sq) {
 | 
					 | 
				
			||||||
        if (this != &sq) {
 | 
					 | 
				
			||||||
            std::lock_guard < std::mutex > lock1(m_mutex);
 | 
					 | 
				
			||||||
            std::lock_guard < std::mutex > lock2(sq.m_mutex);
 | 
					 | 
				
			||||||
            m_queue.swap(sq.m_queue);
 | 
					 | 
				
			||||||
            std::swap(m_max_num_items, sq.m_max_num_items);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!m_queue.empty()) {
 | 
					 | 
				
			||||||
                m_cond_not_empty.notify_all();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (!sq.m_queue.empty()) {
 | 
					 | 
				
			||||||
                sq.m_cond_not_empty.notify_all();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (!m_queue.full()) {
 | 
					 | 
				
			||||||
                m_cond_not_full.notify_all();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (!sq.m_queue.full()) {
 | 
					 | 
				
			||||||
                sq.m_cond_not_full.notify_all();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /*! The copy assignment operator */
 | 
					 | 
				
			||||||
    ThreadBlockingQueue& operator=(const ThreadBlockingQueue& sq) {
 | 
					 | 
				
			||||||
        if (this != &sq) {
 | 
					 | 
				
			||||||
            std::lock_guard < std::mutex > lock1(m_mutex);
 | 
					 | 
				
			||||||
            std::lock_guard < std::mutex > lock2(sq.m_mutex);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
            m_queue = sq.m_queue;
 | 
					 | 
				
			||||||
            m_max_num_items = sq.m_max_num_items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (!m_queue.empty()) {
 | 
					 | 
				
			||||||
                m_cond_not_empty.notify_all();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (!m_queue.full()) {
 | 
					 | 
				
			||||||
                m_cond_not_full.notify_all();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return *this;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -274,9 +226,3 @@ private:
 | 
				
			|||||||
    std::condition_variable m_cond_not_full;
 | 
					    std::condition_variable m_cond_not_full;
 | 
				
			||||||
    size_t m_max_num_items = MIN_ITEM_NB;
 | 
					    size_t m_max_num_items = MIN_ITEM_NB;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					 | 
				
			||||||
/*! Swaps the contents of two ThreadBlockingQueue objects. (external operator) */
 | 
					 | 
				
			||||||
template<typename T>
 | 
					 | 
				
			||||||
void swap(ThreadBlockingQueue<T>& q1, ThreadBlockingQueue<T>& q2) {
 | 
					 | 
				
			||||||
    q1.swap(q2);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user