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