Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008. All Rights Reserved. |
| 3 | */ |
| 4 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 5 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | #pragma once |
| 8 | |
| 9 | #include "ErrorBase.h" |
| 10 | #include "HAL/Task.hpp" |
| 11 | #include <iostream> |
| 12 | #include <string> |
| 13 | #include <thread> |
| 14 | |
| 15 | /** |
| 16 | * Wrapper class around std::thread that allows changing thread priority |
| 17 | */ |
| 18 | class Task : public ErrorBase { |
| 19 | public: |
| 20 | static const uint32_t kDefaultPriority = 60; |
| 21 | |
| 22 | Task() = default; |
| 23 | Task(const Task&) = delete; |
| 24 | Task& operator=(const Task&) = delete; |
| 25 | Task& operator=(Task&& task); |
| 26 | |
| 27 | template <class Function, class... Args> |
| 28 | Task(const std::string& name, Function&& function, Args&&... args); |
| 29 | |
| 30 | virtual ~Task(); |
| 31 | |
| 32 | bool joinable() const noexcept; |
| 33 | void join(); |
| 34 | void detach(); |
| 35 | std::thread::id get_id() const noexcept; |
| 36 | std::thread::native_handle_type native_handle(); |
| 37 | |
| 38 | bool Verify(); |
| 39 | |
| 40 | int32_t GetPriority(); |
| 41 | |
| 42 | bool SetPriority(int32_t priority); |
| 43 | |
| 44 | std::string GetName() const; |
| 45 | |
| 46 | private: |
| 47 | std::thread m_thread; |
| 48 | std::string m_taskName; |
| 49 | bool HandleError(STATUS results); |
| 50 | }; |
| 51 | |
| 52 | #include "Task.inc" |