WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Task.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2017. 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 #pragma once
9 
10 #include <stdint.h>
11 
12 #include <string>
13 #include <thread>
14 
15 #include "ErrorBase.h"
16 #include "HAL/HAL.h"
17 #include "support/deprecated.h"
18 
19 namespace frc {
20 
24 class WPI_DEPRECATED(
25  "Task API scheduled for removal in 2018. Replace with std::thread, and use "
26  "Threads API for setting priority") Task : public ErrorBase {
27  public:
28  static const int kDefaultPriority = 60;
29 
30  Task() = default;
31  Task(const Task&) = delete;
32  Task& operator=(const Task&) = delete;
33  Task& operator=(Task&& task);
34 
35  template <class Function, class... Args>
36  Task(const std::string& name, Function&& function, Args&&... args);
37 
38  virtual ~Task();
39 
40  bool joinable() const noexcept;
41  void join();
42  void detach();
43  std::thread::id get_id() const noexcept;
44  std::thread::native_handle_type native_handle();
45 
46  bool Verify();
47 
48  int GetPriority();
49 
50  bool SetPriority(int priority);
51 
52  std::string GetName() const;
53 
54  private:
55  std::thread m_thread;
56  std::string m_taskName;
57 
58  typedef int32_t TASK_STATUS;
59 
60  static constexpr int32_t TASK_OK = 0;
61  static constexpr int32_t TASK_ERROR = -1;
62  static constexpr int32_t TaskLib_ILLEGAL_PRIORITY = 22; // 22 is EINVAL
63 
64  bool HandleError(TASK_STATUS results);
65  TASK_STATUS VerifyTaskId();
66  TASK_STATUS GetTaskPriority(int32_t* priority);
67  TASK_STATUS SetTaskPriority(int32_t priority);
68 };
69 
70 } // namespace frc
71 
72 #include "Task.inc"
Base class for most objects.
Definition: ErrorBase.h:72