blob: e56b5eeba88ff5444a4a01fbed31f72802181eb1 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2016-2017. 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 <stdint.h>
11
12#include <atomic>
13#include <iostream>
14#include <string>
15#include <utility>
16
17namespace frc {
18
19/**
20 * Create and launch a task.
21 *
22 * @param name The name of the task. "FRC_" will be prepended to the task name.
23 * @param function The address of the function to run as the new task.
24 * @param args A parameter pack of arguments to pass to the function.
25 */
26template <class Function, class... Args>
27Task::Task(const std::string& name, Function&& function, Args&&... args) {
28 m_taskName = "FRC_";
29 m_taskName += name;
30
31 std::cout << "[HAL] Starting task " << m_taskName << "..." << std::endl;
32
33 m_thread = std::thread(std::forward<std::decay_t<Function>>(function),
34 std::forward<Args>(args)...);
35 // TODO: lvuser does not currently have permissions to set the priority.
36 // SetPriority(kDefaultPriority);
37
38 static std::atomic<int32_t> instances{0};
39 instances++;
40 HAL_Report(HALUsageReporting::kResourceType_Task, instances, 0,
41 m_taskName.c_str());
42}
43
44} // namespace frc