[DEV] continue removing stl
This commit is contained in:
parent
a4641e67a3
commit
5cabc85f98
@ -15,7 +15,7 @@ ethread::Pool::Pool(uint16_t _numberOfThread):
|
||||
ememory::SharedPtr<ethread::PoolExecutor> tmp = ememory::makeShared<ethread::PoolExecutor>(*this);
|
||||
if (tmp != nullptr) {
|
||||
tmp->start();
|
||||
m_listThread.push_back(tmp);
|
||||
m_listThread.pushBack(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -38,7 +38,7 @@ ethread::Future ethread::Pool::async(std::function<void()> _call, uint64_t _exec
|
||||
}
|
||||
ememory::SharedPtr<ethread::Promise> promise = ememory::makeShared<ethread::Promise>();
|
||||
ememory::SharedPtr<ethread::PoolAction> action = ememory::makeShared<ethread::PoolAction>(_executionInGroupId, promise, _call);
|
||||
m_listActions.push_back(action);
|
||||
m_listActions.pushBack(action);
|
||||
for(auto &it : m_listThread) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
@ -89,7 +89,7 @@ ememory::SharedPtr<ethread::PoolAction> ethread::Pool::getAction() {
|
||||
if (alreadyUsed == false) {
|
||||
ememory::SharedPtr<ethread::PoolAction> out = (*it);
|
||||
if (uniquId != 0) {
|
||||
m_listIdPool.push_back(uniquId);
|
||||
m_listIdPool.pushBack(uniquId);
|
||||
}
|
||||
it = m_listActions.erase(it);
|
||||
return out;
|
||||
|
@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <etk/Vector.hpp>
|
||||
#include <thread>
|
||||
#include <ethread/Future.hpp>
|
||||
#include <ethread/PoolAction.hpp>
|
||||
@ -19,9 +19,9 @@ namespace ethread {
|
||||
class Pool {
|
||||
private:
|
||||
std::mutex m_mutex; //!< global add and release some thread
|
||||
std::vector<ememory::SharedPtr<ethread::PoolExecutor>> m_listThread; //!< Thread pool
|
||||
std::vector<ememory::SharedPtr<ethread::PoolAction>> m_listActions; //!< Thread pool
|
||||
std::vector<uint64_t> m_listIdPool; //!< Thread pool
|
||||
etk::Vector<ememory::SharedPtr<ethread::PoolExecutor>> m_listThread; //!< Thread pool
|
||||
etk::Vector<ememory::SharedPtr<ethread::PoolAction>> m_listActions; //!< Thread pool
|
||||
etk::Vector<uint64_t> m_listIdPool; //!< Thread pool
|
||||
uint32_t m_lastTrandId; //!< to group the action in a single thread
|
||||
public:
|
||||
/**
|
||||
|
@ -10,7 +10,7 @@
|
||||
ethread::PoolAction::PoolAction(uint64_t _currentPoolId, ememory::SharedPtr<ethread::Promise> _promise, std::function<void()> _call) :
|
||||
m_currentPoolId(_currentPoolId),
|
||||
m_promise(_promise),
|
||||
m_call(std::move(_call)) {
|
||||
m_call(etk::move(_call)) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <etk/Vector.hpp>
|
||||
#include <thread>
|
||||
#include <ethread/Future.hpp>
|
||||
#include <ememory/memory.hpp>
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <etk/Vector.hpp>
|
||||
#include <thread>
|
||||
#include <ethread/Future.hpp>
|
||||
#include <ethread/PoolExecutor.hpp>
|
||||
@ -22,7 +22,7 @@ ethread::PoolExecutor::PoolExecutor(ethread::Pool& _pool):
|
||||
|
||||
void ethread::PoolExecutor::threadCallback() {
|
||||
ETHREAD_DEBUG("RUN: thread in Pool [START]");
|
||||
ethread::setName("pool " + etk::to_string(ethread::getId()));
|
||||
ethread::setName("pool " + etk::toString(ethread::getId()));
|
||||
// get datas:
|
||||
while (m_running == true) {
|
||||
// get an action:
|
||||
|
@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <etk/Vector.hpp>
|
||||
#include <thread>
|
||||
#include <ethread/Future.hpp>
|
||||
#include <ethread/PoolAction.hpp>
|
||||
|
@ -29,7 +29,7 @@ void ethread::Promise::finish() {
|
||||
m_isFinished = true;
|
||||
if (m_callback != nullptr) {
|
||||
// call callbacks ...
|
||||
callback = std::move(m_callback);
|
||||
callback = etk::move(m_callback);
|
||||
}
|
||||
}
|
||||
if (callback != nullptr) {
|
||||
@ -59,7 +59,7 @@ bool ethread::Promise::wait(echrono::Duration _delay) {
|
||||
|
||||
void ethread::Promise::andThen(std::function<void()> _action) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
m_callback = std::move(_action);
|
||||
m_callback = etk::move(_action);
|
||||
if (m_isFinished == true) {
|
||||
m_callback();
|
||||
}
|
||||
|
@ -5,12 +5,13 @@
|
||||
*/
|
||||
|
||||
#include <ethread/tools.hpp>
|
||||
#include <etk/Pair.hpp>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <etk/Map.hpp>
|
||||
|
||||
static std::mutex g_lock;
|
||||
static std::map<uint32_t, std::string>& getThreadList() {
|
||||
static std::map<uint32_t, std::string> g_val;
|
||||
static etk::Map<uint32_t, etk::String>& getThreadList() {
|
||||
static etk::Map<uint32_t, etk::String> g_val;
|
||||
return g_val;
|
||||
}
|
||||
|
||||
@ -18,45 +19,40 @@ static uint32_t getThreadHumanId(std::thread::id _id) {
|
||||
uint32_t out = 0;
|
||||
uint64_t iddd = std::hash<std::thread::id>()(_id);
|
||||
g_lock.lock();
|
||||
static std::map<uint64_t, uint32_t> g_list;
|
||||
std::map<uint64_t, uint32_t>::iterator it = g_list.find(iddd);
|
||||
static etk::Map<uint64_t, uint32_t> g_list;
|
||||
etk::Map<uint64_t, uint32_t>::Iterator it = g_list.find(iddd);
|
||||
if (it == g_list.end()) {
|
||||
// attribute new ID :
|
||||
static uint32_t tmpId = 0;
|
||||
g_list.insert(std::pair<uint64_t, uint32_t>(iddd,tmpId));
|
||||
g_list.set(iddd,tmpId);
|
||||
out = tmpId;
|
||||
tmpId++;
|
||||
} else {
|
||||
out = it->second;
|
||||
out = it.getValue();
|
||||
}
|
||||
g_lock.unlock();
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
static std::string getThreadName(std::thread::id _id) {
|
||||
std::map<uint32_t,std::string>& list = getThreadList();
|
||||
static etk::String getThreadName(std::thread::id _id) {
|
||||
etk::Map<uint32_t,etk::String>& list = getThreadList();
|
||||
uint32_t threadID = getThreadHumanId(_id);
|
||||
std::string out;
|
||||
etk::String out;
|
||||
g_lock.lock();
|
||||
std::map<uint32_t,std::string>::iterator it = list.find(threadID);
|
||||
auto it = list.find(threadID);
|
||||
if (it != list.end()) {
|
||||
out = it->second;
|
||||
out = it.getValue();
|
||||
}
|
||||
g_lock.unlock();
|
||||
return out;
|
||||
}
|
||||
|
||||
static void setThreadName(std::thread* _thread, const std::string& _name) {
|
||||
std::map<uint32_t,std::string>& list = getThreadList();
|
||||
static void setThreadName(std::thread* _thread, const etk::String& _name) {
|
||||
etk::Map<uint32_t,etk::String>& list = getThreadList();
|
||||
uint32_t threadID = ethread::getId();
|
||||
g_lock.lock();
|
||||
std::map<uint32_t,std::string>::iterator it = list.find(threadID);
|
||||
if (it == list.end()) {
|
||||
list.insert(std::pair<uint32_t, std::string>(threadID, _name));
|
||||
} else {
|
||||
it->second = _name;
|
||||
}
|
||||
list.set(threadID, _name);
|
||||
g_lock.unlock();
|
||||
// try now to set the thread name with Pthread
|
||||
#if defined(__TARGET_OS__Linux) \
|
||||
@ -67,7 +63,7 @@ static void setThreadName(std::thread* _thread, const std::string& _name) {
|
||||
} else {
|
||||
pthreadID = (pthread_t) _thread->native_handle();
|
||||
}
|
||||
std::string name = _name;
|
||||
etk::String name = _name;
|
||||
if (name.size() > 15) {
|
||||
name.resize(15);
|
||||
}
|
||||
@ -87,19 +83,19 @@ uint32_t ethread::getId(std::thread& _thread) {
|
||||
return getThreadHumanId(_thread.get_id());
|
||||
}
|
||||
|
||||
void ethread::setName(const std::string& _name) {
|
||||
void ethread::setName(const etk::String& _name) {
|
||||
setThreadName(nullptr, _name);
|
||||
}
|
||||
|
||||
void ethread::setName(std::thread& _thread, const std::string& _name) {
|
||||
void ethread::setName(std::thread& _thread, const etk::String& _name) {
|
||||
setThreadName(&_thread, _name);
|
||||
}
|
||||
|
||||
std::string ethread::getName() {
|
||||
etk::String ethread::getName() {
|
||||
return getThreadName(std::this_thread::get_id());
|
||||
}
|
||||
|
||||
std::string ethread::getName(std::thread& _thread) {
|
||||
etk::String ethread::getName(std::thread& _thread) {
|
||||
return getThreadName(_thread.get_id());
|
||||
}
|
||||
|
||||
@ -184,46 +180,41 @@ int32_t ethread::getPriority(std::thread& _thread) {
|
||||
}
|
||||
|
||||
static std::mutex g_localMutex;
|
||||
static std::map<uint32_t, std::map<std::string, uint64_t>> g_listMetaData;
|
||||
static etk::Map<uint32_t, etk::Map<etk::String, uint64_t>> g_listMetaData;
|
||||
|
||||
void ethread::metadataSet(const std::string& _key, uint64_t _value) {
|
||||
void ethread::metadataSet(const etk::String& _key, uint64_t _value) {
|
||||
uint32_t currentThreadId = ethread::getId();
|
||||
std::unique_lock<std::mutex> lock(g_localMutex);
|
||||
auto it = g_listMetaData.find(currentThreadId);
|
||||
if (it != g_listMetaData.end()) {
|
||||
auto it2 = it->second.find(_key);
|
||||
if (it2 != it->second.end()) {
|
||||
it2->second = _value;
|
||||
} else {
|
||||
it->second.insert(std::make_pair( _key, _value));
|
||||
}
|
||||
it.getValue().set(_key, _value);
|
||||
} else {
|
||||
std::map<std::string, uint64_t> tmp;
|
||||
tmp.insert(std::make_pair( _key, _value));
|
||||
g_listMetaData.insert(std::make_pair(currentThreadId, tmp));
|
||||
etk::Map<etk::String, uint64_t> tmp;
|
||||
tmp.set(_key, _value);
|
||||
g_listMetaData.set(currentThreadId, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void ethread::metadataRemove(const std::string& _key) {
|
||||
void ethread::metadataRemove(const etk::String& _key) {
|
||||
uint32_t currentThreadId = ethread::getId();
|
||||
std::unique_lock<std::mutex> lock(g_localMutex);
|
||||
auto it = g_listMetaData.find(currentThreadId);
|
||||
etk::Map<uint32_t, etk::Map<etk::String, uint64_t>>::Iterator it = g_listMetaData.find(currentThreadId);
|
||||
if (it != g_listMetaData.end()) {
|
||||
auto it2 = it->second.find(_key);
|
||||
if (it2 != it->second.end()) {
|
||||
it->second.erase(it2);
|
||||
auto it2 = it.getValue().find(_key);
|
||||
if (it2 != it.getValue().end()) {
|
||||
it.getValue().erase(it2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t ethread::metadataGetU64(const std::string& _key) {
|
||||
uint64_t ethread::metadataGetU64(const etk::String& _key) {
|
||||
uint32_t currentThreadId = ethread::getId();
|
||||
std::unique_lock<std::mutex> lock(g_localMutex);
|
||||
auto it = g_listMetaData.find(currentThreadId);
|
||||
if (it != g_listMetaData.end()) {
|
||||
auto it2 = it->second.find(_key);
|
||||
if (it2 != it->second.end()) {
|
||||
return it2->second;
|
||||
auto it2 = it.getValue().find(_key);
|
||||
if (it2 != it.getValue().end()) {
|
||||
return it2.getValue();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <thread>
|
||||
#include <string>
|
||||
#include <etk/String.hpp>
|
||||
|
||||
/**
|
||||
* @brief ethread main namespace
|
||||
@ -27,24 +27,24 @@ namespace ethread {
|
||||
* @brief Set the Current thread name
|
||||
* @param[in] _name New name of the thread
|
||||
*/
|
||||
void setName(const std::string& _name);
|
||||
void setName(const etk::String& _name);
|
||||
/**
|
||||
* @brief Set an other thread name
|
||||
* @param[in] _thread Thread handle
|
||||
* @param[in] _name New name of the thread
|
||||
*/
|
||||
void setName(std::thread& _thread, const std::string& _name);
|
||||
void setName(std::thread& _thread, const etk::String& _name);
|
||||
/**
|
||||
* @brief Set the Current thread name
|
||||
* @return The current name of the thread
|
||||
*/
|
||||
std::string getName();
|
||||
etk::String getName();
|
||||
/**
|
||||
* @brief Get an other thread name
|
||||
* @param[in] _thread Thread handle
|
||||
* @return The external thread name of the thread
|
||||
*/
|
||||
std::string getName(std::thread& _thread);
|
||||
etk::String getName(std::thread& _thread);
|
||||
/**
|
||||
* @brief Set the Current thread priority [-20..0] for RT and ]0..50] for normal priority
|
||||
* @param[in] _priority New priority of the thread
|
||||
@ -74,16 +74,16 @@ namespace ethread {
|
||||
* @param[in] _key key to store the value
|
||||
* @param[in] _value Value to store
|
||||
*/
|
||||
void metadataSet(const std::string& _key, uint64_t _value);
|
||||
void metadataSet(const etk::String& _key, uint64_t _value);
|
||||
/**
|
||||
* @brief Remove the information with a key on the current thread
|
||||
* @param[in] _key key to remove
|
||||
*/
|
||||
void metadataRemove(const std::string& _key);
|
||||
void metadataRemove(const etk::String& _key);
|
||||
/**
|
||||
* @brief get the information with a key on the current thread
|
||||
* @param[in] _key key to store the value
|
||||
* @return the uint 64 value to stored
|
||||
*/
|
||||
uint64_t metadataGetU64(const std::string& _key);
|
||||
uint64_t metadataGetU64(const etk::String& _key);
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ def configure(target, my_module):
|
||||
# add dependency of the generic C++ library:
|
||||
my_module.add_depend([
|
||||
'cxx',
|
||||
'etk-base',
|
||||
])
|
||||
#pthread is not availlable on Windows
|
||||
if "Linux" in target.get_type() \
|
||||
|
@ -50,6 +50,7 @@ def configure(target, my_module):
|
||||
my_module.add_depend([
|
||||
'cxx',
|
||||
'elog',
|
||||
'etk',
|
||||
'ethread-tools',
|
||||
'echrono',
|
||||
'ememory'
|
||||
|
Loading…
x
Reference in New Issue
Block a user