WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Task.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2016. 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 "ErrorBase.h"
11 #include "HAL/Task.hpp"
12 #include <iostream>
13 #include <string>
14 #include <thread>
15 
19 class Task : public ErrorBase {
20  public:
21  static const uint32_t kDefaultPriority = 60;
22 
23  Task() = default;
24  Task(const Task&) = delete;
25  Task& operator=(const Task&) = delete;
26  Task& operator=(Task&& task);
27 
28  template <class Function, class... Args>
29  Task(const std::string& name, Function&& function, Args&&... args);
30 
31  virtual ~Task();
32 
33  bool joinable() const noexcept;
34  void join();
35  void detach();
36  std::thread::id get_id() const noexcept;
37  std::thread::native_handle_type native_handle();
38 
39  bool Verify();
40 
41  int32_t GetPriority();
42 
43  bool SetPriority(int32_t priority);
44 
45  std::string GetName() const;
46 
47  private:
48  std::thread m_thread;
49  std::string m_taskName;
50  bool HandleError(STATUS results);
51 };
52 
53 #include "Task.inc"
std::string GetName() const
Returns the name of the task.
Definition: Task.cpp:99
bool SetPriority(int32_t priority)
This routine changes a task's priority to a specified priority.
Definition: Task.cpp:89
Base class for most objects.
Definition: ErrorBase.h:66
int32_t GetPriority()
Gets the priority of a task.
Definition: Task.cpp:72
Wrapper class around std::thread that allows changing thread priority.
Definition: Task.h:19
bool Verify()
Verifies a task still exists.
Definition: Task.cpp:62