mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-27 17:28:41 +00:00
Remove unneeded freeminer code.
This commit is contained in:
parent
eae9fa4e95
commit
9ff9b30e0f
10 changed files with 9 additions and 428 deletions
|
@ -3,6 +3,5 @@ set(JTHREAD_SRCS
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/thread.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/semaphore.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lock.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/thread_vector.cpp
|
||||
PARENT_SCOPE)
|
||||
|
||||
|
|
|
@ -1,118 +0,0 @@
|
|||
#include "thread_vector.h"
|
||||
#include "fm_porting.h"
|
||||
#include "log.h"
|
||||
#include "porting.h"
|
||||
|
||||
thread_vector::thread_vector(const std::string &name, int priority) :
|
||||
m_name(name), m_priority(priority)
|
||||
{
|
||||
request_stop = false;
|
||||
};
|
||||
|
||||
thread_vector::~thread_vector()
|
||||
{
|
||||
join();
|
||||
};
|
||||
|
||||
void thread_vector::func()
|
||||
{
|
||||
reg();
|
||||
run();
|
||||
};
|
||||
|
||||
void thread_vector::reg(const std::string &name, int priority)
|
||||
{
|
||||
if (!name.empty())
|
||||
m_name = name;
|
||||
|
||||
porting::setThreadName(m_name.c_str());
|
||||
g_logger.registerThread(m_name);
|
||||
|
||||
if (priority)
|
||||
m_priority = priority;
|
||||
if (m_priority)
|
||||
porting::setThreadPriority(m_priority);
|
||||
};
|
||||
|
||||
void thread_vector::start(const size_t n)
|
||||
{
|
||||
#if !NDEBUG
|
||||
infostream << "start thread " << m_name << " n=" << n << std::endl;
|
||||
#endif
|
||||
request_stop = false;
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
workers.emplace_back(&thread_vector::func, this);
|
||||
}
|
||||
}
|
||||
|
||||
void thread_vector::stop()
|
||||
{
|
||||
request_stop = true;
|
||||
}
|
||||
|
||||
void thread_vector::join()
|
||||
{
|
||||
stop();
|
||||
for (auto &worker : workers) {
|
||||
try {
|
||||
if (worker.joinable()) {
|
||||
worker.join();
|
||||
}
|
||||
} catch (...) {
|
||||
}
|
||||
}
|
||||
workers.clear();
|
||||
}
|
||||
|
||||
void thread_vector::restart(size_t n)
|
||||
{
|
||||
join();
|
||||
start(n);
|
||||
}
|
||||
void thread_vector::reanimate(size_t n)
|
||||
{
|
||||
if (workers.empty()) {
|
||||
start(n);
|
||||
}
|
||||
}
|
||||
|
||||
void thread_vector::sleep(const int seconds)
|
||||
{
|
||||
for (int i = 0; i <= seconds; ++i) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if (request_stop) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// JThread compat:
|
||||
bool thread_vector::stopRequested()
|
||||
{
|
||||
return request_stop;
|
||||
}
|
||||
bool thread_vector::isRunning()
|
||||
{
|
||||
return !workers.empty();
|
||||
}
|
||||
void thread_vector::wait()
|
||||
{
|
||||
join();
|
||||
};
|
||||
void thread_vector::kill()
|
||||
{
|
||||
join();
|
||||
};
|
||||
void *thread_vector::run()
|
||||
{
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
bool thread_vector::isCurrentThread()
|
||||
{
|
||||
auto thread_me = std::hash<std::thread::id>()(std::this_thread::get_id());
|
||||
for (auto &worker : workers)
|
||||
if (thread_me == std::hash<std::thread::id>()(worker.get_id()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class thread_vector {
|
||||
public:
|
||||
std::vector<std::thread> workers;
|
||||
std::atomic_bool request_stop;
|
||||
|
||||
thread_vector(const std::string &name = "Unnamed", int priority = 0);
|
||||
virtual ~thread_vector();
|
||||
|
||||
virtual void func();
|
||||
|
||||
void reg (const std::string &name = "", int priority = 0);
|
||||
void start (const size_t n = 1);
|
||||
void restart (const size_t n = 1);
|
||||
void reanimate (const size_t n = 1);
|
||||
void stop ();
|
||||
void join ();
|
||||
|
||||
void sleep(const int second);
|
||||
// Thread compat:
|
||||
|
||||
bool stopRequested();
|
||||
bool isRunning();
|
||||
void wait();
|
||||
void kill();
|
||||
virtual void * run() = 0;
|
||||
bool isCurrentThread();
|
||||
protected:
|
||||
std::string m_name;
|
||||
int m_priority = 0;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue