aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Foundation/src/PriorityNotificationQueue.cpp
diff options
context:
space:
mode:
authororivej <orivej@yandex-team.ru>2022-02-10 16:44:49 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:49 +0300
commit718c552901d703c502ccbefdfc3c9028d608b947 (patch)
tree46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/libs/poco/Foundation/src/PriorityNotificationQueue.cpp
parente9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff)
downloadydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/poco/Foundation/src/PriorityNotificationQueue.cpp')
-rw-r--r--contrib/libs/poco/Foundation/src/PriorityNotificationQueue.cpp390
1 files changed, 195 insertions, 195 deletions
diff --git a/contrib/libs/poco/Foundation/src/PriorityNotificationQueue.cpp b/contrib/libs/poco/Foundation/src/PriorityNotificationQueue.cpp
index b0e5523ce2..e52f6db3fe 100644
--- a/contrib/libs/poco/Foundation/src/PriorityNotificationQueue.cpp
+++ b/contrib/libs/poco/Foundation/src/PriorityNotificationQueue.cpp
@@ -1,195 +1,195 @@
-//
-// PriorityNotificationQueue.cpp
-//
-// Library: Foundation
-// Package: Notifications
-// Module: PriorityNotificationQueue
-//
-// Copyright (c) 2009, Applied Informatics Software Engineering GmbH.
-// and Contributors.
-//
-// SPDX-License-Identifier: BSL-1.0
-//
-
-
-#include "Poco/PriorityNotificationQueue.h"
-#include "Poco/NotificationCenter.h"
-#include "Poco/Notification.h"
-#include "Poco/SingletonHolder.h"
-
-
-namespace Poco {
-
-
-PriorityNotificationQueue::PriorityNotificationQueue()
-{
-}
-
-
-PriorityNotificationQueue::~PriorityNotificationQueue()
-{
- try
- {
- clear();
- }
- catch (...)
- {
- poco_unexpected();
- }
-}
-
-
-void PriorityNotificationQueue::enqueueNotification(Notification::Ptr pNotification, int priority)
-{
- poco_check_ptr (pNotification);
- FastMutex::ScopedLock lock(_mutex);
- if (_waitQueue.empty())
- {
- _nfQueue.insert(NfQueue::value_type(priority, pNotification));
- }
- else
- {
- poco_assert_dbg(_nfQueue.empty());
- WaitInfo* pWI = _waitQueue.front();
- _waitQueue.pop_front();
- pWI->pNf = pNotification;
- pWI->nfAvailable.set();
- }
-}
-
-
-Notification* PriorityNotificationQueue::dequeueNotification()
-{
- FastMutex::ScopedLock lock(_mutex);
- return dequeueOne().duplicate();
-}
-
-
-Notification* PriorityNotificationQueue::waitDequeueNotification()
-{
- Notification::Ptr pNf;
- WaitInfo* pWI = 0;
- {
- FastMutex::ScopedLock lock(_mutex);
- pNf = dequeueOne();
- if (pNf) return pNf.duplicate();
- pWI = new WaitInfo;
- _waitQueue.push_back(pWI);
- }
- pWI->nfAvailable.wait();
- pNf = pWI->pNf;
- delete pWI;
- return pNf.duplicate();
-}
-
-
-Notification* PriorityNotificationQueue::waitDequeueNotification(long milliseconds)
-{
- Notification::Ptr pNf;
- WaitInfo* pWI = 0;
- {
- FastMutex::ScopedLock lock(_mutex);
- pNf = dequeueOne();
- if (pNf) return pNf.duplicate();
- pWI = new WaitInfo;
- _waitQueue.push_back(pWI);
- }
- if (pWI->nfAvailable.tryWait(milliseconds))
- {
- pNf = pWI->pNf;
- }
- else
- {
- FastMutex::ScopedLock lock(_mutex);
- pNf = pWI->pNf;
- for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
- {
- if (*it == pWI)
- {
- _waitQueue.erase(it);
- break;
- }
- }
- }
- delete pWI;
- return pNf.duplicate();
-}
-
-
-void PriorityNotificationQueue::dispatch(NotificationCenter& notificationCenter)
-{
- FastMutex::ScopedLock lock(_mutex);
- Notification::Ptr pNf = dequeueOne();
- while (pNf)
- {
- notificationCenter.postNotification(pNf);
- pNf = dequeueOne();
- }
-}
-
-
-void PriorityNotificationQueue::wakeUpAll()
-{
- FastMutex::ScopedLock lock(_mutex);
- for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
- {
- (*it)->nfAvailable.set();
- }
- _waitQueue.clear();
-}
-
-
-bool PriorityNotificationQueue::empty() const
-{
- FastMutex::ScopedLock lock(_mutex);
- return _nfQueue.empty();
-}
-
-
-int PriorityNotificationQueue::size() const
-{
- FastMutex::ScopedLock lock(_mutex);
- return static_cast<int>(_nfQueue.size());
-}
-
-
-void PriorityNotificationQueue::clear()
-{
- FastMutex::ScopedLock lock(_mutex);
- _nfQueue.clear();
-}
-
-
-bool PriorityNotificationQueue::hasIdleThreads() const
-{
- FastMutex::ScopedLock lock(_mutex);
- return !_waitQueue.empty();
-}
-
-
-Notification::Ptr PriorityNotificationQueue::dequeueOne()
-{
- Notification::Ptr pNf;
- NfQueue::iterator it = _nfQueue.begin();
- if (it != _nfQueue.end())
- {
- pNf = it->second;
- _nfQueue.erase(it);
- }
- return pNf;
-}
-
-
-namespace
-{
- static SingletonHolder<PriorityNotificationQueue> sh;
-}
-
-
-PriorityNotificationQueue& PriorityNotificationQueue::defaultQueue()
-{
- return *sh.get();
-}
-
-
-} // namespace Poco
+//
+// PriorityNotificationQueue.cpp
+//
+// Library: Foundation
+// Package: Notifications
+// Module: PriorityNotificationQueue
+//
+// Copyright (c) 2009, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// SPDX-License-Identifier: BSL-1.0
+//
+
+
+#include "Poco/PriorityNotificationQueue.h"
+#include "Poco/NotificationCenter.h"
+#include "Poco/Notification.h"
+#include "Poco/SingletonHolder.h"
+
+
+namespace Poco {
+
+
+PriorityNotificationQueue::PriorityNotificationQueue()
+{
+}
+
+
+PriorityNotificationQueue::~PriorityNotificationQueue()
+{
+ try
+ {
+ clear();
+ }
+ catch (...)
+ {
+ poco_unexpected();
+ }
+}
+
+
+void PriorityNotificationQueue::enqueueNotification(Notification::Ptr pNotification, int priority)
+{
+ poco_check_ptr (pNotification);
+ FastMutex::ScopedLock lock(_mutex);
+ if (_waitQueue.empty())
+ {
+ _nfQueue.insert(NfQueue::value_type(priority, pNotification));
+ }
+ else
+ {
+ poco_assert_dbg(_nfQueue.empty());
+ WaitInfo* pWI = _waitQueue.front();
+ _waitQueue.pop_front();
+ pWI->pNf = pNotification;
+ pWI->nfAvailable.set();
+ }
+}
+
+
+Notification* PriorityNotificationQueue::dequeueNotification()
+{
+ FastMutex::ScopedLock lock(_mutex);
+ return dequeueOne().duplicate();
+}
+
+
+Notification* PriorityNotificationQueue::waitDequeueNotification()
+{
+ Notification::Ptr pNf;
+ WaitInfo* pWI = 0;
+ {
+ FastMutex::ScopedLock lock(_mutex);
+ pNf = dequeueOne();
+ if (pNf) return pNf.duplicate();
+ pWI = new WaitInfo;
+ _waitQueue.push_back(pWI);
+ }
+ pWI->nfAvailable.wait();
+ pNf = pWI->pNf;
+ delete pWI;
+ return pNf.duplicate();
+}
+
+
+Notification* PriorityNotificationQueue::waitDequeueNotification(long milliseconds)
+{
+ Notification::Ptr pNf;
+ WaitInfo* pWI = 0;
+ {
+ FastMutex::ScopedLock lock(_mutex);
+ pNf = dequeueOne();
+ if (pNf) return pNf.duplicate();
+ pWI = new WaitInfo;
+ _waitQueue.push_back(pWI);
+ }
+ if (pWI->nfAvailable.tryWait(milliseconds))
+ {
+ pNf = pWI->pNf;
+ }
+ else
+ {
+ FastMutex::ScopedLock lock(_mutex);
+ pNf = pWI->pNf;
+ for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
+ {
+ if (*it == pWI)
+ {
+ _waitQueue.erase(it);
+ break;
+ }
+ }
+ }
+ delete pWI;
+ return pNf.duplicate();
+}
+
+
+void PriorityNotificationQueue::dispatch(NotificationCenter& notificationCenter)
+{
+ FastMutex::ScopedLock lock(_mutex);
+ Notification::Ptr pNf = dequeueOne();
+ while (pNf)
+ {
+ notificationCenter.postNotification(pNf);
+ pNf = dequeueOne();
+ }
+}
+
+
+void PriorityNotificationQueue::wakeUpAll()
+{
+ FastMutex::ScopedLock lock(_mutex);
+ for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
+ {
+ (*it)->nfAvailable.set();
+ }
+ _waitQueue.clear();
+}
+
+
+bool PriorityNotificationQueue::empty() const
+{
+ FastMutex::ScopedLock lock(_mutex);
+ return _nfQueue.empty();
+}
+
+
+int PriorityNotificationQueue::size() const
+{
+ FastMutex::ScopedLock lock(_mutex);
+ return static_cast<int>(_nfQueue.size());
+}
+
+
+void PriorityNotificationQueue::clear()
+{
+ FastMutex::ScopedLock lock(_mutex);
+ _nfQueue.clear();
+}
+
+
+bool PriorityNotificationQueue::hasIdleThreads() const
+{
+ FastMutex::ScopedLock lock(_mutex);
+ return !_waitQueue.empty();
+}
+
+
+Notification::Ptr PriorityNotificationQueue::dequeueOne()
+{
+ Notification::Ptr pNf;
+ NfQueue::iterator it = _nfQueue.begin();
+ if (it != _nfQueue.end())
+ {
+ pNf = it->second;
+ _nfQueue.erase(it);
+ }
+ return pNf;
+}
+
+
+namespace
+{
+ static SingletonHolder<PriorityNotificationQueue> sh;
+}
+
+
+PriorityNotificationQueue& PriorityNotificationQueue::defaultQueue()
+{
+ return *sh.get();
+}
+
+
+} // namespace Poco