blob: 3514b92a4549b0f0e2b0beda882b0207631bd64a [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001#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 */
11template <class Function, class... Args>
12Task::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}