| 1 | // | 
|---|---|
| 2 | // Condition.cpp | 
| 3 | // | 
| 4 | // Library: Foundation | 
| 5 | // Package: Threading | 
| 6 | // Module: Condition | 
| 7 | // | 
| 8 | // Copyright (c) 2007, Applied Informatics Software Engineering GmbH. | 
| 9 | // and Contributors. | 
| 10 | // | 
| 11 | // SPDX-License-Identifier: BSL-1.0 | 
| 12 | // | 
| 13 | |
| 14 | |
| 15 | #include "Poco/Condition.h" | 
| 16 | |
| 17 | |
| 18 | namespace Poco { | 
| 19 | |
| 20 | |
| 21 | Condition::Condition() | 
| 22 | { | 
| 23 | } | 
| 24 | |
| 25 | Condition::~Condition() | 
| 26 | { | 
| 27 | } | 
| 28 | |
| 29 | |
| 30 | void Condition::signal() | 
| 31 | { | 
| 32 | FastMutex::ScopedLock lock(_mutex); | 
| 33 | |
| 34 | if (!_waitQueue.empty()) | 
| 35 | { | 
| 36 | _waitQueue.front()->set(); | 
| 37 | dequeue(); | 
| 38 | } | 
| 39 | } | 
| 40 | |
| 41 | |
| 42 | void Condition::broadcast() | 
| 43 | { | 
| 44 | FastMutex::ScopedLock lock(_mutex); | 
| 45 | |
| 46 | for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it) | 
| 47 | { | 
| 48 | (*it)->set(); | 
| 49 | } | 
| 50 | _waitQueue.clear(); | 
| 51 | } | 
| 52 | |
| 53 | |
| 54 | void Condition::enqueue(Event& event) | 
| 55 | { | 
| 56 | _waitQueue.push_back(&event); | 
| 57 | } | 
| 58 | |
| 59 | |
| 60 | void Condition::dequeue() | 
| 61 | { | 
| 62 | _waitQueue.pop_front(); | 
| 63 | } | 
| 64 | |
| 65 | |
| 66 | void Condition::dequeue(Event& event) | 
| 67 | { | 
| 68 | for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it) | 
| 69 | { | 
| 70 | if (*it == &event) | 
| 71 | { | 
| 72 | _waitQueue.erase(it); | 
| 73 | break; | 
| 74 | } | 
| 75 | } | 
| 76 | } | 
| 77 | |
| 78 | |
| 79 | } // namespace Poco | 
| 80 | 
