WPILibC++  2019.1.1-beta-2-1-g9bc998f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Work.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef WPIUTIL_WPI_UV_WORK_H_
9 #define WPIUTIL_WPI_UV_WORK_H_
10 
11 #include <uv.h>
12 
13 #include <functional>
14 #include <memory>
15 
16 #include "wpi/Signal.h"
17 #include "wpi/uv/Request.h"
18 
19 namespace wpi {
20 namespace uv {
21 
22 class Loop;
23 
28 class WorkReq : public RequestImpl<WorkReq, uv_work_t> {
29  public:
30  WorkReq();
31 
32  Loop& GetLoop() const { return *static_cast<Loop*>(GetRaw()->loop->data); }
33 
38 
44 };
45 
52 void QueueWork(Loop& loop, const std::shared_ptr<WorkReq>& req);
53 
60 inline void QueueWork(const std::shared_ptr<Loop>& loop,
61  const std::shared_ptr<WorkReq>& req) {
62  QueueWork(*loop, req);
63 }
64 
75 void QueueWork(Loop& loop, std::function<void()> work,
76  std::function<void()> afterWork);
77 
88 inline void QueueWork(const std::shared_ptr<Loop>& loop,
89  std::function<void()> work,
90  std::function<void()> afterWork) {
91  QueueWork(*loop, work, afterWork);
92 }
93 
94 } // namespace uv
95 } // namespace wpi
96 
97 #endif // WPIUTIL_WPI_UV_WORK_H_
sig::Signal work
Function(s) that will be run on the thread pool.
Definition: Work.h:37
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
uv_work_t * GetRaw() noexcept
Get the underlying request data structure.
Definition: Request.h:149
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.h:43
Work request.
Definition: Work.h:28
Event loop.
Definition: Loop.h:39
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495
Request.
Definition: Request.h:134