blob: 3c90aba8e929098d8ec7434a5fbbfab5f363da7c [file] [log] [blame]
Brian Silverman1a675112016-02-20 20:42:49 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 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
Brian Silverman26e4e522015-12-17 01:56:40 -05008#include "HAL/HAL.hpp"
9#include <atomic>
10
11/**
12 * Create and launch a task.
13 *
14 * @param name The name of the task. "FRC_" will be prepended to the task name.
15 * @param function The address of the function to run as the new task.
16 * @param args A parameter pack of arguments to pass to the function.
17 */
18template <class Function, class... Args>
19Task::Task(const std::string& name, Function&& function, Args&&... args) {
20 m_taskName = "FRC_";
21 m_taskName += name;
22
23 std::cout << "[HAL] Starting task " << m_taskName << "..." << std::endl;
24
25 m_thread = std::thread(std::forward<std::decay_t<Function>>(function),
26 std::forward<Args>(args)...);
27 //TODO: lvuser does not currently have permissions to set the priority.
28 //SetPriority(kDefaultPriority);
29
30 static std::atomic<int32_t> instances{0};
31 instances++;
32 HALReport(HALUsageReporting::kResourceType_Task, instances, 0, m_taskName.c_str());
33}