Remove old multi-threading code

This commit is contained in:
pixl 2022-01-29 00:48:16 -05:00
parent d9c64892be
commit c69ae325d3
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
5 changed files with 0 additions and 186 deletions

View File

@ -65,7 +65,6 @@ add_executable(logid
backend/hidpp20/features/WirelessDeviceStatus.cpp
backend/hidpp20/features/ThumbWheel.cpp
backend/dj/Report.cpp
util/thread.cpp
util/task.cpp
util/ExceptionHandler.cpp)

View File

@ -29,7 +29,6 @@
#include <list>
#include "defs.h"
#include "../../util/mutex_queue.h"
namespace logid::backend::raw
{

View File

@ -1,55 +0,0 @@
/*
* Copyright 2019-2020 PixlOne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef MUTEX_QUEUE_H
#define MUTEX_QUEUE_H
#include <queue>
#include <mutex>
template<typename data>
class mutex_queue
{
public:
mutex_queue() = default;
bool empty()
{
std::lock_guard<std::mutex> lock(_mutex);
return _queue.empty();
}
data& front()
{
std::lock_guard<std::mutex> lock(_mutex);
return _queue.front();
}
void push(const data& _data)
{
std::lock_guard<std::mutex> lock(_mutex);
_queue.push(_data);
}
void pop()
{
std::lock_guard<std::mutex> lock(_mutex);
_queue.pop();
}
private:
std::queue<data> _queue;
std::mutex _mutex;
};
#endif //MUTEX_QUEUE_H

View File

@ -1,72 +0,0 @@
/*
* Copyright 2019-2020 PixlOne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "thread.h"
using namespace logid;
thread::thread(const std::function<void()>& function,
const std::function<void(std::exception&)>& exception_handler)
: _function (std::make_shared<std::function<void()>>(function)),
_exception_handler (std::make_shared<std::function<void
(std::exception&)>> (exception_handler))
{
}
thread::~thread()
{
if(_thread)
if(_thread->joinable())
_thread->detach();
}
void thread::spawn(const std::function<void()>& function,
const std::function<void(std::exception&)>& exception_handler)
{
std::thread([function, exception_handler](){
thread t(function, exception_handler);
t.runSync();
}).detach();
}
void thread::run()
{
_thread = std::make_shared<std::thread>(
[f=this->_function,eh=this->_exception_handler]() {
try {
(*f)();
} catch (std::exception& e) {
(*eh)(e);
}
});
}
void thread::wait()
{
if(_thread)
if(_thread->joinable())
_thread->join();
}
void thread::runSync()
{
try {
(*_function)();
} catch(std::exception& e) {
(*_exception_handler)(e);
}
}

View File

@ -1,57 +0,0 @@
/*
* Copyright 2019-2020 PixlOne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef LOGID_THREAD_H
#define LOGID_THREAD_H
#include <functional>
#include <memory>
#include <thread>
#include "ExceptionHandler.h"
namespace logid
{
class thread
{
public:
explicit thread(const std::function<void()>& function,
const std::function<void(std::exception&)>&
exception_handler={[](std::exception& e)
{ExceptionHandler::Default(e);}});
~thread();
/* This function spawns a new thread and forgets about it,
* safe equivalent to std::thread{...}.detach()
*/
static void spawn(const std::function<void()>& function,
const std::function<void(std::exception&)>&
exception_handler={[](std::exception& e)
{ExceptionHandler::Default(e);}});
void run();
void wait();
void runSync();
private:
std::shared_ptr<std::function<void()>> _function;
std::shared_ptr<std::function<void(std::exception&)>>
_exception_handler;
std::shared_ptr<std::thread> _thread = nullptr;
};
}
#endif //LOGID_THREAD_H