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