WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
Work.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <functional>
8#include <memory>
9#include <utility>
10
11#include <uv.h>
12
14#include "wpi/util/Signal.h"
15
16namespace wpi::net::uv {
17
18class Loop;
19
20/**
21 * Work request.
22 * For use with `QueueWork()` function family.
23 */
24class WorkReq : public RequestImpl<WorkReq, uv_work_t> {
25 public:
27
28 Loop& GetLoop() const { return *static_cast<Loop*>(GetRaw()->loop->data); }
29
30 /**
31 * Function(s) that will be run on the thread pool.
32 */
34
35 /**
36 * Function(s) that will be run on the loop thread after the work on the
37 * thread pool has been completed by the work callback.
38 */
40};
41
42/**
43 * Initializes a work request which will run on the thread pool.
44 *
45 * @param loop Event loop
46 * @param req request
47 */
48void QueueWork(Loop& loop, const std::shared_ptr<WorkReq>& req);
49
50/**
51 * Initializes a work request which will run on the thread pool.
52 *
53 * @param loop Event loop
54 * @param req request
55 */
56inline void QueueWork(const std::shared_ptr<Loop>& loop,
57 const std::shared_ptr<WorkReq>& req) {
58 QueueWork(*loop, req);
59}
60
61/**
62 * Initializes a work request which will run on the thread pool. The work
63 * callback will be run on a thread from the thread pool, and the afterWork
64 * callback will be called on the loop thread after the work completes. Any
65 * errors are forwarded to the loop.
66 *
67 * @param loop Event loop
68 * @param work Work callback (called from separate thread)
69 * @param afterWork After work callback (called on loop thread)
70 */
71void QueueWork(Loop& loop, std::function<void()> work,
72 std::function<void()> afterWork);
73
74/**
75 * Initializes a work request which will run on the thread pool. The work
76 * callback will be run on a thread from the thread pool, and the afterWork
77 * callback will be called on the loop thread after the work completes. Any
78 * errors are forwarded to the loop.
79 *
80 * @param loop Event loop
81 * @param work Work callback (called from separate thread)
82 * @param afterWork After work callback (called on loop thread)
83 */
84inline void QueueWork(const std::shared_ptr<Loop>& loop,
85 std::function<void()> work,
86 std::function<void()> afterWork) {
87 QueueWork(*loop, std::move(work), std::move(afterWork));
88}
89
90} // namespace wpi::net::uv
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
Event loop.
Definition Loop.hpp:35
uv_work_t * GetRaw() noexcept
Definition Request.hpp:149
wpi::util::sig::Signal work
Function(s) that will be run on the thread pool.
Definition Work.hpp:33
wpi::util::sig::Signal afterWork
Function(s) that will be run on the loop thread after the work on the thread pool has been completed ...
Definition Work.hpp:39
Loop & GetLoop() const
Definition Work.hpp:28
Definition Prepare.hpp:14
void QueueWork(Loop &loop, const std::shared_ptr< WorkReq > &req)
Initializes a work request which will run on the thread pool.
SignalBase< detail::NullMutex, T... > Signal
Specialization of SignalBase to be used in single threaded contexts.
Definition Signal.h:809
void * data
Definition uv.h:1907
UV_REQ_FIELDS uv_loop_t * loop
Definition uv.h:1161