29 async->wakeup.connect(
35 if (
auto async =
m_async.lock()) {
41 std::weak_ptr<uv::Async<AfterWorkFunction, R>>
m_async;
57 if (
auto async =
m_async.lock()) {
63 std::weak_ptr<uv::Async<AfterWorkFunction>>
m_async;
66template <
typename R,
typename... T>
73 std::tuple<T...> params_)
78 std::tuple<T...> params_)
90template <
typename R,
typename... T>
102template <
typename R,
typename... T>
105 R result = std::apply(req.
work, std::move(req.
params));
107 if (
auto async = thr.
m_async.m_async.lock()) {
108 async->Send(std::move(req.
afterWork), std::move(result));
115template <
typename... T>
120 if (
auto async = thr.
m_async.m_async.lock()) {
128template <
typename R,
typename... T>
130 std::vector<Request> requests;
132 std::unique_lock lock(
m_mutex);
142 for (
auto&& req : requests) {
158template <
typename R,
typename... T>
177 if (
auto thr = m_owner.GetThread()) {
178 thr->m_async.SetLoop(
loop);
196 if (
auto thr = m_owner.GetThread()) {
197 thr->m_async.UnsetLoop();
209 if (
auto thr = m_owner.GetThread()) {
210 return thr->m_async.m_async.lock();
229 template <
typename... U>
231 if (
auto thr = m_owner.GetThread()) {
233 uint64_t req = thr->m_promises.CreateRequest();
236 thr->m_requests.emplace_back(
237 req, std::move(
work), std::forward_as_tuple(std::forward<U>(u)...));
240 thr->m_cond.notify_one();
243 return thr->m_promises.CreateFuture(req);
265 template <
typename... U>
267 if (
auto thr = m_owner.GetThread()) {
269 thr->m_requests.emplace_back(
270 std::move(
work), std::move(afterWork),
271 std::forward_as_tuple(std::forward<U>(u)...));
274 thr->m_cond.notify_one();
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or glfw and nanopb were modified for use in Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the work(an example is provided in the Appendix below). "Derivative Works" shall mean any work
WorkerThread()
Definition WorkerThread.hpp:167
std::shared_ptr< uv::Handle > GetHandle() const
Get the handle used by QueueWorkThen() to run afterWork.
Definition WorkerThread.hpp:208
typename detail::WorkerThreadAsync< R >::AfterWorkFunction AfterWorkFunction
Definition WorkerThread.hpp:164
void UnsetLoop()
Unset the loop.
Definition WorkerThread.hpp:195
void QueueWorkThen(WorkFunction work, AfterWorkFunction afterWork, U &&... u)
Wakeup the worker thread, call the work function, and call the afterWork function with the result on ...
Definition WorkerThread.hpp:266
void SetLoop(std::shared_ptr< uv::Loop > loop)
Set the loop.
Definition WorkerThread.hpp:189
std::function< R(T...)> WorkFunction
Definition WorkerThread.hpp:163
wpi::util::future< R > QueueWork(WorkFunction work, U &&... u)
Wakeup the worker thread, call the work function, and return a future for the result.
Definition WorkerThread.hpp:230
void SetLoop(uv::Loop &loop)
Set the loop.
Definition WorkerThread.hpp:176
Definition WorkerThread.hpp:156
Definition WorkerThread.hpp:91
wpi::util::PromiseFactory< R > m_promises
Definition WorkerThread.hpp:98
detail::WorkerThreadAsync< R > m_async
Definition WorkerThread.hpp:99
WorkerThreadRequest< R, T... > Request
Definition WorkerThread.hpp:93
void Main() override
Definition WorkerThread.hpp:129
std::vector< Request > m_requests
Definition WorkerThread.hpp:97
static std::shared_ptr< Async > Create(Loop &loop)
Create an async handle.
Definition Async.hpp:53
Event loop.
Definition Loop.hpp:35
A promise factory for lightweight futures.
Definition future.hpp:122
void SetValue(uint64_t request, const T &value)
Sets a value directly for a future without creating a promise object.
Definition future.hpp:728
wpi::util::mutex m_mutex
Definition SafeThread.hpp:27
std::atomic_bool m_active
Definition SafeThread.hpp:28
Definition SafeThread.hpp:32
wpi::util::condition_variable m_cond
Definition SafeThread.hpp:36
Definition SafeThread.hpp:123
A lightweight version of std::future.
Definition future.hpp:270
Converts a string literal into a format string that will be parsed at compile time and converted into...
Definition printf.h:50
Definition StringMap.hpp:773
void RunWorkerThreadRequest(WorkerThreadThread< R, T... > &thr, WorkerThreadRequest< R, T... > &req)
Definition WorkerThread.hpp:103
Definition raw_socket_ostream.hpp:9
std::function< void()> AfterWorkFunction
Definition WorkerThread.hpp:46
void RemoveLoop()
Definition WorkerThread.hpp:56
~WorkerThreadAsync()
Definition WorkerThread.hpp:48
void SetLoop(uv::Loop &loop)
Definition WorkerThread.hpp:50
std::weak_ptr< uv::Async< AfterWorkFunction > > m_async
Definition WorkerThread.hpp:63
Definition WorkerThread.hpp:22
void UnsetLoop()
Definition WorkerThread.hpp:34
std::weak_ptr< uv::Async< AfterWorkFunction, R > > m_async
Definition WorkerThread.hpp:41
void SetLoop(uv::Loop &loop)
Definition WorkerThread.hpp:27
~WorkerThreadAsync()
Definition WorkerThread.hpp:25
std::function< void(R)> AfterWorkFunction
Definition WorkerThread.hpp:23
Definition WorkerThread.hpp:67
AfterWorkFunction afterWork
Definition WorkerThread.hpp:86
std::tuple< T... > params
Definition WorkerThread.hpp:87
std::function< R(T...)> WorkFunction
Definition WorkerThread.hpp:68
typename WorkerThreadAsync< R >::AfterWorkFunction AfterWorkFunction
Definition WorkerThread.hpp:69
uint64_t promiseId
Definition WorkerThread.hpp:84
WorkerThreadRequest()=default
WorkerThreadRequest(uint64_t promiseId_, WorkFunction work_, std::tuple< T... > params_)
Definition WorkerThread.hpp:72
WorkerThreadRequest(WorkFunction work_, AfterWorkFunction afterWork_, std::tuple< T... > params_)
Definition WorkerThread.hpp:77
WorkFunction work
Definition WorkerThread.hpp:85