Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | #include "HAL/HAL.hpp" |
| 2 | #include <atomic> |
| 3 | |
| 4 | /** |
| 5 | * Create and launch a task. |
| 6 | * |
| 7 | * @param name The name of the task. "FRC_" will be prepended to the task name. |
| 8 | * @param function The address of the function to run as the new task. |
| 9 | * @param args A parameter pack of arguments to pass to the function. |
| 10 | */ |
| 11 | template <class Function, class... Args> |
| 12 | Task::Task(const std::string& name, Function&& function, Args&&... args) { |
| 13 | m_taskName = "FRC_"; |
| 14 | m_taskName += name; |
| 15 | |
| 16 | std::cout << "[HAL] Starting task " << m_taskName << "..." << std::endl; |
| 17 | |
| 18 | m_thread = std::thread(std::forward<std::decay_t<Function>>(function), |
| 19 | std::forward<Args>(args)...); |
| 20 | //TODO: lvuser does not currently have permissions to set the priority. |
| 21 | //SetPriority(kDefaultPriority); |
| 22 | |
| 23 | static std::atomic<int32_t> instances{0}; |
| 24 | instances++; |
| 25 | HALReport(HALUsageReporting::kResourceType_Task, instances, 0, m_taskName.c_str()); |
| 26 | } |