2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2014-08-14 00:07:02 -07:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <thread>
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "ErrorBase.h"
|
2016-05-22 21:41:22 -07:00
|
|
|
#include "HAL/Task.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
2015-08-12 03:36:42 -07:00
|
|
|
* Wrapper class around std::thread that allows changing thread priority
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
class Task : public ErrorBase {
|
|
|
|
|
public:
|
2016-09-06 00:01:45 -07:00
|
|
|
static const int kDefaultPriority = 60;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2014-08-14 00:07:02 -07:00
|
|
|
Task() = default;
|
|
|
|
|
Task(const Task&) = delete;
|
|
|
|
|
Task& operator=(const Task&) = delete;
|
|
|
|
|
Task& operator=(Task&& task);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2014-08-14 00:07:02 -07:00
|
|
|
template <class Function, class... Args>
|
2015-06-30 15:01:20 -04:00
|
|
|
Task(const std::string& name, Function&& function, Args&&... args);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2014-08-14 00:07:02 -07:00
|
|
|
virtual ~Task();
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2014-08-14 00:07:02 -07:00
|
|
|
bool joinable() const noexcept;
|
|
|
|
|
void join();
|
|
|
|
|
void detach();
|
|
|
|
|
std::thread::id get_id() const noexcept;
|
|
|
|
|
std::thread::native_handle_type native_handle();
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2014-08-14 00:07:02 -07:00
|
|
|
bool Verify();
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetPriority();
|
2014-08-14 00:07:02 -07:00
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
bool SetPriority(int priority);
|
2014-08-14 00:07:02 -07:00
|
|
|
|
|
|
|
|
std::string GetName() const;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
private:
|
2014-08-14 00:07:02 -07:00
|
|
|
std::thread m_thread;
|
|
|
|
|
std::string m_taskName;
|
2015-06-25 15:07:55 -04:00
|
|
|
bool HandleError(STATUS results);
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2014-08-14 00:07:02 -07:00
|
|
|
|
|
|
|
|
#include "Task.inc"
|