mirror of
https://github.com/pocoproject/poco.git
synced 2025-12-09 16:36:51 +01:00
enh(Poco::ActiveThreadPool): std::optional::value unavailable on earlier macOS versions
This commit is contained in:
@@ -24,7 +24,6 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
@@ -133,7 +132,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ActiveThreadPoolPrivate& _pool;
|
ActiveThreadPoolPrivate& _pool;
|
||||||
std::optional<std::reference_wrapper<Runnable>> _target{};
|
Runnable* _pTarget;
|
||||||
Condition _runnableReady;
|
Condition _runnableReady;
|
||||||
Thread _thread;
|
Thread _thread;
|
||||||
};
|
};
|
||||||
@@ -171,7 +170,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
ActivePooledThread::ActivePooledThread(ActiveThreadPoolPrivate& pool):
|
ActivePooledThread::ActivePooledThread(ActiveThreadPoolPrivate& pool):
|
||||||
_pool(pool)
|
_pool(pool),
|
||||||
|
_pTarget(nullptr)
|
||||||
{
|
{
|
||||||
std::ostringstream name;
|
std::ostringstream name;
|
||||||
name << _pool.name << "[#" << ++_pool.serial << "]";
|
name << _pool.name << "[#" << ++_pool.serial << "]";
|
||||||
@@ -188,8 +188,8 @@ void ActivePooledThread::start()
|
|||||||
|
|
||||||
void ActivePooledThread::setRunnable(Runnable& target)
|
void ActivePooledThread::setRunnable(Runnable& target)
|
||||||
{
|
{
|
||||||
poco_assert(_target.has_value() == false);
|
poco_assert(_pTarget == nullptr);
|
||||||
_target = std::ref(target);
|
_pTarget = ⌖
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -216,17 +216,17 @@ void ActivePooledThread::run()
|
|||||||
FastMutex::ScopedLock lock(_pool.mutex);
|
FastMutex::ScopedLock lock(_pool.mutex);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
auto r = _target;
|
auto r = _pTarget;
|
||||||
_target.reset();
|
_pTarget = nullptr;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (r.has_value())
|
if (r)
|
||||||
{
|
{
|
||||||
_pool.mutex.unlock();
|
_pool.mutex.unlock();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
r.value().get().run();
|
r->run();
|
||||||
}
|
}
|
||||||
catch (Exception& exc)
|
catch (Exception& exc)
|
||||||
{
|
{
|
||||||
@@ -246,11 +246,11 @@ void ActivePooledThread::run()
|
|||||||
|
|
||||||
if (_pool.runnables.empty())
|
if (_pool.runnables.empty())
|
||||||
{
|
{
|
||||||
r.reset();
|
r = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = std::ref(_pool.runnables.pop());
|
r = &_pool.runnables.pop();
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
ActivePooledThread::Ptr thisCopy(this, true);
|
ActivePooledThread::Ptr thisCopy(this, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user