remove virtual
git-svn-id: svn://db.shs.com.ru/pip@894 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -41,7 +41,8 @@ public:
|
|||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
other.mutex.unlock();
|
other.mutex.unlock();
|
||||||
}
|
}
|
||||||
virtual ~PIBlockingDequeue() {
|
|
||||||
|
~PIBlockingDequeue() {
|
||||||
delete cond_var_add;
|
delete cond_var_add;
|
||||||
delete cond_var_rem;
|
delete cond_var_rem;
|
||||||
}
|
}
|
||||||
@@ -51,7 +52,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param v the element to add
|
* @param v the element to add
|
||||||
*/
|
*/
|
||||||
virtual void put(const T & v) {
|
void put(const T & v) {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
cond_var_rem->wait(mutex, [&]() { return PIDeque<T>::size() < max_size; });
|
cond_var_rem->wait(mutex, [&]() { return PIDeque<T>::size() < max_size; });
|
||||||
PIDeque<T>::push_back(v);
|
PIDeque<T>::push_back(v);
|
||||||
@@ -66,7 +67,7 @@ public:
|
|||||||
* @param v the element to add
|
* @param v the element to add
|
||||||
* @return true if the element was added to this queue, else false
|
* @return true if the element was added to this queue, else false
|
||||||
*/
|
*/
|
||||||
virtual bool offer(const T & v) {
|
bool offer(const T & v) {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
if (PIDeque<T>::size() >= max_size) {
|
if (PIDeque<T>::size() >= max_size) {
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
@@ -86,7 +87,7 @@ public:
|
|||||||
* @param timeoutMs how long to wait before giving up, in milliseconds
|
* @param timeoutMs how long to wait before giving up, in milliseconds
|
||||||
* @return true if successful, or false if the specified waiting time elapses before space is available
|
* @return true if successful, or false if the specified waiting time elapses before space is available
|
||||||
*/
|
*/
|
||||||
virtual bool offer(const T & v, int timeoutMs) {
|
bool offer(const T & v, int timeoutMs) {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
bool isOk = cond_var_rem->waitFor(mutex, timeoutMs, [&]() { return PIDeque<T>::size() < max_size; } );
|
bool isOk = cond_var_rem->waitFor(mutex, timeoutMs, [&]() { return PIDeque<T>::size() < max_size; } );
|
||||||
if (isOk) PIDeque<T>::push_back(v);
|
if (isOk) PIDeque<T>::push_back(v);
|
||||||
@@ -100,7 +101,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return the head of this queue
|
* @return the head of this queue
|
||||||
*/
|
*/
|
||||||
virtual T take() {
|
T take() {
|
||||||
T t;
|
T t;
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
cond_var_add->wait(mutex, [&]() { return !PIDeque<T>::isEmpty(); });
|
cond_var_add->wait(mutex, [&]() { return !PIDeque<T>::isEmpty(); });
|
||||||
@@ -118,7 +119,7 @@ public:
|
|||||||
* @param defaultVal value, which returns if the specified waiting time elapses before an element is available
|
* @param defaultVal value, which returns if the specified waiting time elapses before an element is available
|
||||||
* @return the head of this queue, or defaultVal if the specified waiting time elapses before an element is available
|
* @return the head of this queue, or defaultVal if the specified waiting time elapses before an element is available
|
||||||
*/
|
*/
|
||||||
virtual T poll(int timeoutMs, const T & defaultVal) {
|
T poll(int timeoutMs, const T & defaultVal) {
|
||||||
T t;
|
T t;
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
bool isOk = cond_var_add->waitFor(mutex, timeoutMs, [&]() { return !PIDeque<T>::isEmpty(); });
|
bool isOk = cond_var_add->waitFor(mutex, timeoutMs, [&]() { return !PIDeque<T>::isEmpty(); });
|
||||||
@@ -134,7 +135,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return the capacity
|
* @return the capacity
|
||||||
*/
|
*/
|
||||||
virtual size_t capacity() {
|
size_t capacity() {
|
||||||
size_t c;
|
size_t c;
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
c = max_size;
|
c = max_size;
|
||||||
@@ -148,7 +149,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return the remaining capacity
|
* @return the remaining capacity
|
||||||
*/
|
*/
|
||||||
virtual size_t remainingCapacity() {
|
size_t remainingCapacity() {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
size_t c = max_size - PIDeque<T>::size();
|
size_t c = max_size - PIDeque<T>::size();
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
@@ -158,7 +159,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Returns the number of elements in this collection.
|
* @brief Returns the number of elements in this collection.
|
||||||
*/
|
*/
|
||||||
virtual size_t size() {
|
size_t size() {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
size_t s = PIDeque<T>::size();
|
size_t s = PIDeque<T>::size();
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
@@ -168,7 +169,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Removes all available elements from this queue and adds them to other given queue.
|
* @brief Removes all available elements from this queue and adds them to other given queue.
|
||||||
*/
|
*/
|
||||||
virtual size_t drainTo(PIDeque<T>& other, size_t maxCount = SIZE_MAX) {
|
size_t drainTo(PIDeque<T>& other, size_t maxCount = SIZE_MAX) {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
size_t count = maxCount > PIDeque<T>::size() ? PIDeque<T>::size() : maxCount;
|
size_t count = maxCount > PIDeque<T>::size() ? PIDeque<T>::size() : maxCount;
|
||||||
for (size_t i = 0; i < count; ++i) other.push_back(PIDeque<T>::take_front());
|
for (size_t i = 0; i < count; ++i) other.push_back(PIDeque<T>::take_front());
|
||||||
@@ -179,7 +180,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Removes all available elements from this queue and adds them to other given queue.
|
* @brief Removes all available elements from this queue and adds them to other given queue.
|
||||||
*/
|
*/
|
||||||
virtual size_t drainTo(PIBlockingDequeue<T>& other, size_t maxCount = SIZE_MAX) {
|
size_t drainTo(PIBlockingDequeue<T>& other, size_t maxCount = SIZE_MAX) {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
other.mutex.lock();
|
other.mutex.lock();
|
||||||
size_t count = maxCount > PIDeque<T>::size() ? PIDeque<T>::size() : maxCount;
|
size_t count = maxCount > PIDeque<T>::size() ? PIDeque<T>::size() : maxCount;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
class PIP_EXPORT PIConditionLock {
|
class PIP_EXPORT PIConditionLock {
|
||||||
public:
|
public:
|
||||||
explicit PIConditionLock();
|
explicit PIConditionLock();
|
||||||
virtual ~PIConditionLock();
|
~PIConditionLock();
|
||||||
|
|
||||||
//! \brief lock
|
//! \brief lock
|
||||||
void lock();
|
void lock();
|
||||||
|
|||||||
@@ -15,24 +15,24 @@
|
|||||||
class PIP_EXPORT PIConditionVariable {
|
class PIP_EXPORT PIConditionVariable {
|
||||||
public:
|
public:
|
||||||
explicit PIConditionVariable();
|
explicit PIConditionVariable();
|
||||||
virtual ~PIConditionVariable();
|
~PIConditionVariable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unblocks one of the threads currently waiting for this condition. If no threads are waiting, the function
|
* @brief Unblocks one of the threads currently waiting for this condition. If no threads are waiting, the function
|
||||||
* does nothing. If more than one, it is unspecified which of the threads is selected.
|
* does nothing. If more than one, it is unspecified which of the threads is selected.
|
||||||
*/
|
*/
|
||||||
virtual void notifyOne();
|
void notifyOne();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unblocks all threads currently waiting for this condition. If no threads are waiting, the function does
|
* @brief Unblocks all threads currently waiting for this condition. If no threads are waiting, the function does
|
||||||
* nothing.
|
* nothing.
|
||||||
*/
|
*/
|
||||||
virtual void notifyAll();
|
void notifyAll();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief see wait(PIConditionLock&, const std::function<bool()>&)
|
* @brief see wait(PIConditionLock&, const std::function<bool()>&)
|
||||||
*/
|
*/
|
||||||
virtual void wait(PIConditionLock& lk);
|
void wait(PIConditionLock& lk);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Wait until notified
|
* @brief Wait until notified
|
||||||
@@ -58,12 +58,12 @@ public:
|
|||||||
* @param condition A callable object or function that takes no arguments and returns a value that can be evaluated
|
* @param condition A callable object or function that takes no arguments and returns a value that can be evaluated
|
||||||
* as a bool. This is called repeatedly until it evaluates to true.
|
* as a bool. This is called repeatedly until it evaluates to true.
|
||||||
*/
|
*/
|
||||||
virtual void wait(PIConditionLock& lk, const std::function<bool()>& condition);
|
void wait(PIConditionLock& lk, const std::function<bool()>& condition);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief see waitFor(PIConditionLock&, int, const std::function<bool()>&)
|
* @brief see waitFor(PIConditionLock&, int, const std::function<bool()>&)
|
||||||
*/
|
*/
|
||||||
virtual bool waitFor(PIConditionLock& lk, int timeoutMs);
|
bool waitFor(PIConditionLock& lk, int timeoutMs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Wait for timeout or until notified
|
* @brief Wait for timeout or until notified
|
||||||
@@ -90,7 +90,7 @@ public:
|
|||||||
* as a bool. This is called repeatedly until it evaluates to true.
|
* as a bool. This is called repeatedly until it evaluates to true.
|
||||||
* @return false if timeout reached or true if wakeup condition is true
|
* @return false if timeout reached or true if wakeup condition is true
|
||||||
*/
|
*/
|
||||||
virtual bool waitFor(PIConditionLock& lk, int timeoutMs, const std::function<bool()>& condition);
|
bool waitFor(PIConditionLock& lk, int timeoutMs, const std::function<bool()>& condition);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NO_COPY_CLASS(PIConditionVariable)
|
NO_COPY_CLASS(PIConditionVariable)
|
||||||
|
|||||||
Reference in New Issue
Block a user