diff --git a/ethread/Pool.cpp b/ethread/Pool.cpp index de650ff..722ad46 100644 --- a/ethread/Pool.cpp +++ b/ethread/Pool.cpp @@ -15,7 +15,7 @@ ethread::Pool::Pool(uint16_t _numberOfThread): ememory::SharedPtr tmp = ememory::makeShared(*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 _call, uint64_t _exec } ememory::SharedPtr promise = ememory::makeShared(); ememory::SharedPtr action = ememory::makeShared(_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::Pool::getAction() { if (alreadyUsed == false) { ememory::SharedPtr out = (*it); if (uniquId != 0) { - m_listIdPool.push_back(uniquId); + m_listIdPool.pushBack(uniquId); } it = m_listActions.erase(it); return out; diff --git a/ethread/Pool.hpp b/ethread/Pool.hpp index 3862db7..8e42796 100644 --- a/ethread/Pool.hpp +++ b/ethread/Pool.hpp @@ -6,7 +6,7 @@ #pragma once #include -#include +#include #include #include #include @@ -19,9 +19,9 @@ namespace ethread { class Pool { private: std::mutex m_mutex; //!< global add and release some thread - std::vector> m_listThread; //!< Thread pool - std::vector> m_listActions; //!< Thread pool - std::vector m_listIdPool; //!< Thread pool + etk::Vector> m_listThread; //!< Thread pool + etk::Vector> m_listActions; //!< Thread pool + etk::Vector m_listIdPool; //!< Thread pool uint32_t m_lastTrandId; //!< to group the action in a single thread public: /** diff --git a/ethread/PoolAction.cpp b/ethread/PoolAction.cpp index 8532dc1..8c75b7e 100644 --- a/ethread/PoolAction.cpp +++ b/ethread/PoolAction.cpp @@ -10,7 +10,7 @@ ethread::PoolAction::PoolAction(uint64_t _currentPoolId, ememory::SharedPtr _promise, std::function _call) : m_currentPoolId(_currentPoolId), m_promise(_promise), - m_call(std::move(_call)) { + m_call(etk::move(_call)) { } diff --git a/ethread/PoolAction.hpp b/ethread/PoolAction.hpp index 153dd65..5868dbe 100644 --- a/ethread/PoolAction.hpp +++ b/ethread/PoolAction.hpp @@ -6,7 +6,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/ethread/PoolExecutor.cpp b/ethread/PoolExecutor.cpp index d4792ea..7346ca2 100644 --- a/ethread/PoolExecutor.cpp +++ b/ethread/PoolExecutor.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include @@ -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: diff --git a/ethread/PoolExecutor.hpp b/ethread/PoolExecutor.hpp index 4836385..34c9d50 100644 --- a/ethread/PoolExecutor.hpp +++ b/ethread/PoolExecutor.hpp @@ -6,7 +6,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/ethread/Promise.cpp b/ethread/Promise.cpp index bcb4826..825ff9f 100644 --- a/ethread/Promise.cpp +++ b/ethread/Promise.cpp @@ -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 _action) { std::unique_lock lock(m_mutex); - m_callback = std::move(_action); + m_callback = etk::move(_action); if (m_isFinished == true) { m_callback(); } diff --git a/ethread/tools.cpp b/ethread/tools.cpp index 8a07f48..359086f 100644 --- a/ethread/tools.cpp +++ b/ethread/tools.cpp @@ -5,12 +5,13 @@ */ #include +#include #include -#include +#include static std::mutex g_lock; -static std::map& getThreadList() { - static std::map g_val; +static etk::Map& getThreadList() { + static etk::Map 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()(_id); g_lock.lock(); - static std::map g_list; - std::map::iterator it = g_list.find(iddd); + static etk::Map g_list; + etk::Map::Iterator it = g_list.find(iddd); if (it == g_list.end()) { // attribute new ID : static uint32_t tmpId = 0; - g_list.insert(std::pair(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& list = getThreadList(); +static etk::String getThreadName(std::thread::id _id) { + etk::Map& list = getThreadList(); uint32_t threadID = getThreadHumanId(_id); - std::string out; + etk::String out; g_lock.lock(); - std::map::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& list = getThreadList(); +static void setThreadName(std::thread* _thread, const etk::String& _name) { + etk::Map& list = getThreadList(); uint32_t threadID = ethread::getId(); g_lock.lock(); - std::map::iterator it = list.find(threadID); - if (it == list.end()) { - list.insert(std::pair(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> g_listMetaData; +static etk::Map> 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 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 tmp; - tmp.insert(std::make_pair( _key, _value)); - g_listMetaData.insert(std::make_pair(currentThreadId, tmp)); + etk::Map 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 lock(g_localMutex); - auto it = g_listMetaData.find(currentThreadId); + etk::Map>::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 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; diff --git a/ethread/tools.hpp b/ethread/tools.hpp index 6e20d7f..0c6e30e 100644 --- a/ethread/tools.hpp +++ b/ethread/tools.hpp @@ -6,7 +6,7 @@ #pragma once #include -#include +#include /** * @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); } diff --git a/lutin_ethread-tools.py b/lutin_ethread-tools.py index a6cc8c9..120f8f3 100644 --- a/lutin_ethread-tools.py +++ b/lutin_ethread-tools.py @@ -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() \ diff --git a/lutin_ethread.py b/lutin_ethread.py index 9081812..1017b9d 100644 --- a/lutin_ethread.py +++ b/lutin_ethread.py @@ -50,6 +50,7 @@ def configure(target, my_module): my_module.add_depend([ 'cxx', 'elog', + 'etk', 'ethread-tools', 'echrono', 'ememory'