| 53 | */ |
| 54 | template<class T> |
| 55 | bool Post(T callback, SchedulerPolicy) |
| 56 | { |
| 57 | boost::shared_lock<decltype(m_Mutex)> lock (m_Mutex); |
| 58 | |
| 59 | if (m_Pool) { |
| 60 | m_Pending.fetch_add(1); |
| 61 | |
| 62 | boost::asio::post(*m_Pool, [this, callback]() { |
| 63 | m_Pending.fetch_sub(1); |
| 64 | |
| 65 | try { |
| 66 | callback(); |
| 67 | } catch (const std::exception& ex) { |
| 68 | Log(LogCritical, "ThreadPool") |
| 69 | << "Exception thrown in event handler:\n" |
| 70 | << DiagnosticInformation(ex); |
| 71 | } catch (...) { |
| 72 | Log(LogCritical, "ThreadPool", "Exception of unknown type thrown in event handler."); |
| 73 | } |
| 74 | }); |
| 75 | |
| 76 | return true; |
| 77 | } else { |
| 78 | return false; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns the amount of queued tasks not started yet. |