[DEV] remove STL

This commit is contained in:
Edouard DUPIN 2017-09-07 23:38:26 +02:00
parent d5e1e1f47e
commit a395da2619
21 changed files with 165 additions and 120 deletions

View File

@ -28,7 +28,7 @@ bool ethread::Future::wait(echrono::Duration _delay) {
return m_promise->wait(_delay);
}
void ethread::Future::andThen(std::function<void()> _action) {
void ethread::Future::andThen(etk::Function<void()> _action) {
if (m_promise == nullptr) {
ETHREAD_ERROR("Promise does not exist...");
return;

View File

@ -5,8 +5,8 @@
*/
#pragma once
#include <mutex>
#include <thread>
#include <ethread/Mutex.hpp>
#include <ethread/Thread.hpp>
#include <ethread/Promise.hpp>
#include <ememory/memory.hpp>
@ -38,6 +38,6 @@ namespace ethread {
* @brief Action to do when the action is finished
* @param[in] _action New action to do.
*/
void andThen(std::function<void()> _action);
void andThen(etk::Function<void()> _action);
};
}

View File

@ -5,7 +5,7 @@
*/
#include <ethread/os/Mutex.h>
#include <ethread/Mutex.hpp>
ethread::Mutex::Mutex() {
InitializeCriticalSection(&m_mutex);

View File

@ -4,7 +4,7 @@
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.h>
#include <etk/types.hpp>
#ifdef __TARGET_OS__Windows
#include <windows.h>
@ -50,7 +50,7 @@ namespace ethread {
/**
* @brief AutoLock and un-lock when exit fuction.
*/
class uniqueLock {
class UniqueLock {
private:
// Keep a reference on the mutex
ethread::Mutex &m_protect;
@ -59,17 +59,16 @@ namespace ethread {
* @brief constructor that automaticly lock the mutex.
* @param[in] _protect Mutex to Lock.
*/
uniqueLock(ethread::Mutex& _protect) :
UniqueLock(ethread::Mutex& _protect) :
m_protect(_protect) {
m_protect.lock();
}
/**
* @brief Destructor that Auto Unlock mutex when remove.
*/
virtual ~uniqueLock(){
virtual ~UniqueLock(){
m_protect.unLock();
}
};
};
}
#endif

View File

@ -4,21 +4,21 @@
* @license MPL v2.0 (see license file)
*/
#include <etk/types.h>
#include <ethread/Mutex.h>
#include <ethread/debug.h>
#include <etk/types.hpp>
#include <ethread/Mutex.hpp>
//#include <ethread/debug.hpp>
ethread::Mutex::Mutex() {
// create interface mutex :
int ret = pthread_mutex_init(&m_mutex, nullptr);
ETHREAD_ASSERT(ret == 0, "Error creating Mutex ...");
//ETHREAD_ASSERT(ret == 0, "Error creating Mutex ...");
}
ethread::Mutex::~Mutex() {
// Remove mutex
int ret = pthread_mutex_destroy(&m_mutex);
ETHREAD_ASSERT(ret == 0, "Error destroying Mutex ...");
//ETHREAD_ASSERT(ret == 0, "Error destroying Mutex ...");
}

View File

@ -10,7 +10,7 @@
ethread::Pool::Pool(uint16_t _numberOfThread):
m_lastTrandId(1) {
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
for (uint32_t iii=0; iii<_numberOfThread; ++iii) {
ememory::SharedPtr<ethread::PoolExecutor> tmp = ememory::makeShared<ethread::PoolExecutor>(*this);
if (tmp != nullptr) {
@ -26,12 +26,12 @@ ethread::Pool::~Pool() {
}
uint32_t ethread::Pool::createGroupId() {
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
return m_lastTrandId++;
}
ethread::Future ethread::Pool::async(std::function<void()> _call, uint64_t _executionInGroupId) {
std::unique_lock<std::mutex> lock(m_mutex);
ethread::Future ethread::Pool::async(etk::Function<void()> _call, uint64_t _executionInGroupId) {
std::unique_lock<ethread::Mutex> lock(m_mutex);
if (_call == nullptr) {
ETHREAD_ERROR("Can not add an action with no function to call...");
return ethread::Future();
@ -55,7 +55,7 @@ void ethread::Pool::releaseId(uint64_t _id) {
if (_id == 0) {
return;
}
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
auto it = m_listIdPool.begin();
while (it != m_listIdPool.end()) {
if (*it == _id) {
@ -68,7 +68,7 @@ void ethread::Pool::releaseId(uint64_t _id) {
// get an action to execute ...
ememory::SharedPtr<ethread::PoolAction> ethread::Pool::getAction() {
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
auto it = m_listActions.begin();
while (it != m_listActions.end()) {
if (*it == nullptr) {
@ -101,7 +101,7 @@ ememory::SharedPtr<ethread::PoolAction> ethread::Pool::getAction() {
void ethread::Pool::stop() {
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
auto it = m_listThread.begin();
while (it != m_listThread.end()) {
if (*it == nullptr) {
@ -114,7 +114,7 @@ void ethread::Pool::stop() {
}
void ethread::Pool::join() {
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
ETHREAD_DEBUG("start join all the threads in pool " << m_listThread.size());
for (size_t iii=0; iii<m_listThread.size(); ++iii) {
ETHREAD_DEBUG(" join " << iii);

View File

@ -5,9 +5,9 @@
*/
#pragma once
#include <mutex>
#include <ethread/Mutex.hpp>
#include <etk/Vector.hpp>
#include <thread>
#include <ethread/Thread.hpp>
#include <ethread/Future.hpp>
#include <ethread/PoolAction.hpp>
@ -18,7 +18,7 @@ namespace ethread {
*/
class Pool {
private:
std::mutex m_mutex; //!< global add and release some thread
ethread::Mutex m_mutex; //!< global add and release some thread
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
@ -45,7 +45,7 @@ namespace ethread {
* @return A future on the action done
*/
// Execte in a group != of 0 request ordering the action in a single thread (same as a trand ...)
ethread::Future async(std::function<void()> _func, uint64_t _executionInGroupId=0); //!< execute an action in the thread pool...
ethread::Future async(etk::Function<void()> _func, uint64_t _executionInGroupId=0); //!< execute an action in the thread pool...
// internal:
/**
* @brief Gan an Action to process

View File

@ -7,7 +7,7 @@
#include <ethread/PoolAction.hpp>
#include "debug.hpp"
ethread::PoolAction::PoolAction(uint64_t _currentPoolId, ememory::SharedPtr<ethread::Promise> _promise, std::function<void()> _call) :
ethread::PoolAction::PoolAction(uint64_t _currentPoolId, ememory::SharedPtr<ethread::Promise> _promise, etk::Function<void()> _call) :
m_currentPoolId(_currentPoolId),
m_promise(_promise),
m_call(etk::move(_call)) {

View File

@ -5,9 +5,9 @@
*/
#pragma once
#include <mutex>
#include <ethread/Mutex.hpp>
#include <etk/Vector.hpp>
#include <thread>
#include <ethread/Thread.hpp>
#include <ethread/Future.hpp>
#include <ememory/memory.hpp>
@ -19,7 +19,7 @@ namespace ethread {
private:
uint64_t m_currentPoolId; //!< execution group Id requested
ememory::SharedPtr<ethread::Promise> m_promise; //!< Return promise of the action
std::function<void()> m_call; //!< Action to do ...
etk::Function<void()> m_call; //!< Action to do ...
public:
/**
* @brief Contuctor of a simple action
@ -27,7 +27,7 @@ namespace ethread {
* @param[in] _promise Promise to call when action is done
* @param[in] _call Action to do (callable object)
*/
PoolAction(uint64_t _currentPoolId, ememory::SharedPtr<ethread::Promise> _promise, std::function<void()> _call);
PoolAction(uint64_t _currentPoolId, ememory::SharedPtr<ethread::Promise> _promise, etk::Function<void()> _call);
/**
* @brief Get the Pool id of the Action
* @return The pool id of this action (0 for no request)

View File

@ -4,9 +4,9 @@
* @license MPL v2.0 (see license file)
*/
#include <mutex>
#include <ethread/Mutex.hpp>
#include <etk/Vector.hpp>
#include <thread>
#include <ethread/Thread.hpp>
#include <ethread/Future.hpp>
#include <ethread/PoolExecutor.hpp>
#include <ethread/tools.hpp>
@ -28,7 +28,7 @@ void ethread::PoolExecutor::threadCallback() {
// get an action:
m_action = m_pool.getAction();
if (m_action == nullptr) {
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
// If no action availlable and not requested to check, just sleep ...
if (m_needProcess == false) {
m_isWaiting = true;
@ -55,10 +55,10 @@ void ethread::PoolExecutor::start() {
ETHREAD_DEBUG("START: thread in Pool [START]");
m_running = true;
{
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
m_condition.notify_all();
}
m_thread = ememory::makeShared<std::thread>([&](void *){ this->threadCallback();}, nullptr);
m_thread = ememory::makeShared<ethread::Thread>([&](void *){ this->threadCallback();}, nullptr);
if (m_thread == nullptr) {
m_running = false;
ETHREAD_ERROR("START: thread in Pool [STOP] can not intanciate THREAD!");
@ -71,7 +71,7 @@ void ethread::PoolExecutor::start() {
void ethread::PoolExecutor::stop() {
ETHREAD_DEBUG("STOP: thread in Pool [START]");
{
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
m_condition.notify_all();
}
m_running = false;
@ -81,7 +81,7 @@ void ethread::PoolExecutor::stop() {
void ethread::PoolExecutor::join() {
ETHREAD_DEBUG("JOIN: thread in Pool [START]");
{
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
m_condition.notify_all();
}
if (m_thread != nullptr) {
@ -93,7 +93,7 @@ void ethread::PoolExecutor::join() {
}
bool ethread::PoolExecutor::touch() {
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
bool ret = false;
if ( m_needProcess == false
&& m_isWaiting == true) {

View File

@ -5,13 +5,13 @@
*/
#pragma once
#include <mutex>
#include <ethread/Mutex.hpp>
#include <etk/Vector.hpp>
#include <thread>
#include <ethread/Thread.hpp>
#include <ethread/Future.hpp>
#include <ethread/PoolAction.hpp>
#include <ethread/Pool.hpp>
#include <mutex>
#include <ethread/Mutex.hpp>
#include <condition_variable>
namespace ethread {
@ -20,13 +20,13 @@ namespace ethread {
*/
class PoolExecutor {
private: //section to permit to optimize CPU:
std::mutex m_mutex; //!< protection of the internal data.
ethread::Mutex m_mutex; //!< protection of the internal data.
std::condition_variable m_condition; //!< Message system to send event on an other thread.
bool m_needProcess; //!< Need to do action (no need to wait condition).
bool m_isWaiting; //!< The executor is waiting to some action to do.
private:
ethread::Pool& m_pool; //!< Local reference on the Thread pool that store action to do.
ememory::SharedPtr<std::thread> m_thread; //!< Local thread to process action.
ememory::SharedPtr<ethread::Thread> m_thread; //!< Local thread to process action.
bool m_running; //!< Thread is running (not stop).
ememory::SharedPtr<ethread::PoolAction> m_action; //!< Curent action that is processing.
public:
@ -37,7 +37,7 @@ namespace ethread {
PoolExecutor(ethread::Pool& _pool);
protected:
/**
* @brief Internal thread callback (for std::thread).
* @brief Internal thread callback (for ethread::Thread).
*/
void threadCallback();
public:

View File

@ -19,9 +19,9 @@ bool ethread::Promise::isFinished() {
}
void ethread::Promise::finish() {
std::function<void()> callback;
etk::Function<void()> callback;
{
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
if (m_isFinished == true) {
ETHREAD_ERROR("Request 2 time finishing a Promise ...");
return;
@ -41,7 +41,7 @@ bool ethread::Promise::wait(echrono::Duration _delay) {
echrono::Steady time = echrono::Steady::now();
while (_delay >= 0) {
{
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock<ethread::Mutex> lock(m_mutex);
if (m_isFinished == true) {
return true;
}
@ -57,8 +57,8 @@ bool ethread::Promise::wait(echrono::Duration _delay) {
return false;
}
void ethread::Promise::andThen(std::function<void()> _action) {
std::unique_lock<std::mutex> lock(m_mutex);
void ethread::Promise::andThen(etk::Function<void()> _action) {
std::unique_lock<ethread::Mutex> lock(m_mutex);
m_callback = etk::move(_action);
if (m_isFinished == true) {
m_callback();

View File

@ -5,8 +5,8 @@
*/
#pragma once
#include <mutex>
#include <thread>
#include <ethread/Mutex.hpp>
#include <ethread/Thread.hpp>
#include <functional>
#include <echrono/Duration.hpp>
@ -16,8 +16,8 @@ namespace ethread {
*/
class Promise {
private:
std::mutex m_mutex; //!< Simple lock of the interface
std::function<void()> m_callback; //!< callback to call when processing is ended
ethread::Mutex m_mutex; //!< Simple lock of the interface
etk::Function<void()> m_callback; //!< callback to call when processing is ended
bool m_isFinished; //!< The process of the action has been done
public:
/**
@ -43,6 +43,6 @@ namespace ethread {
* @brief Action to do when the action is finished
* @param[in] _action New action to do.
*/
void andThen(std::function<void()> _action);
void andThen(etk::Function<void()> _action);
};
}

View File

@ -3,9 +3,9 @@
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.h>
#include <etk/os/Semaphore.h>
#include <etk/debug.h>
#include <etk/types.hpp>
#include <etk/os/Semaphore.hpp>
#include <etk/debug.hpp>
etk::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax) {
// create interface mutex :

View File

@ -5,7 +5,7 @@
*/
#pragma once
#include <etk/types.h>
#include <etk/types.hpp>
#ifdef __TARGET_OS__Windows
#include <windows.h>
@ -60,6 +60,4 @@ namespace ethread {
*/
bool wait(uint64_t _timeOutInUs);
};
};
#endif
}

View File

@ -3,9 +3,9 @@
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.h>
#include <ethread/Semaphore.h>
#include <ethread/debug.h>
#include <etk/types.hpp>
#include <ethread/Semaphore.hpp>
//#include <ethread/debug.hpp>
#include <sys/time.h>
ethread::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax) {

View File

@ -4,9 +4,9 @@
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.h>
#include <etk/Function.h>
#include <etk/String.h>
#include <etk/types.hpp>
#include <etk/Function.hpp>
#include <etk/String.hpp>
#ifdef __TARGET_OS__Windows
#error TODO ...
@ -29,14 +29,13 @@ namespace ethread {
etk::String m_name; //!< Name of the thread (do not get it on the system ==> more portable)
etk::Function<void()> m_function; //!< Function to call every cycle of the thead running
public:
Thread(etk::Function<void()>&& _call, const std::string& _name);
Thread(etk::Function<void()>&& _call, const etk::String& _name);
~Thread();
void join();
bool detach();
void setName(const std::string& _name);
const std::string& setName() const;
void setName(const etk::String& _name);
const etk::String& setName() const;
uint32_t getIdentifier() const;
};
}
#endif

View File

@ -6,19 +6,22 @@
#include <ethread/tools.hpp>
#include <etk/Pair.hpp>
#include <mutex>
//#include <ethread/Mutex.hpp>
// TODO: set mutex back ...
#include <etk/Map.hpp>
#include <unistd.h>
static std::mutex g_lock;
//static ethread::Mutex g_lock;
static etk::Map<uint32_t, etk::String>& getThreadList() {
static etk::Map<uint32_t, etk::String> g_val;
return g_val;
}
static uint32_t getThreadHumanId(std::thread::id _id) {
/*
static uint32_t getThreadHumanId(ethread::Thread::id _id) {
return 0;
uint32_t out = 0;
uint64_t iddd = std::hash<std::thread::id>()(_id);
g_lock.lock();
uint64_t iddd = std::hash<ethread::Thread::id>()(_id);
// TODO: g_lock.lock();
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()) {
@ -30,30 +33,30 @@ static uint32_t getThreadHumanId(std::thread::id _id) {
} else {
out = it.getValue();
}
g_lock.unlock();
// TODO: g_lock.unlock();
return out;
}
static etk::String getThreadName(std::thread::id _id) {
static etk::String getThreadName(ethread::Thread::id _id) {
etk::Map<uint32_t,etk::String>& list = getThreadList();
uint32_t threadID = getThreadHumanId(_id);
etk::String out;
g_lock.lock();
// TODO: g_lock.lock();
auto it = list.find(threadID);
if (it != list.end()) {
out = it.getValue();
}
g_lock.unlock();
// TODO: g_lock.unlock();
return out;
return "TODO";
}
static void setThreadName(std::thread* _thread, const etk::String& _name) {
static void setThreadName(ethread::Thread* _thread, const etk::String& _name) {
etk::Map<uint32_t,etk::String>& list = getThreadList();
uint32_t threadID = ethread::getId();
g_lock.lock();
// TODO: g_lock.lock();
list.set(threadID, _name);
g_lock.unlock();
vg_lock.unlock();
// try now to set the thread name with Pthread
#if defined(__TARGET_OS__Linux) \
&& !defined(__TARGET_OS__Web)
@ -74,34 +77,41 @@ static void setThreadName(std::thread* _thread, const etk::String& _name) {
//TODO: TK_INFO("Can not set the thread name in this OS (local set)");
#endif
}
*/
uint32_t ethread::getId() {
/*
return getThreadHumanId(std::this_thread::get_id());
*/
return 0;
}
uint32_t ethread::getId(std::thread& _thread) {
return getThreadHumanId(_thread.get_id());
uint32_t ethread::getId(ethread::Thread& _thread) {
//return getThreadHumanId(_thread.get_id());
return 0;
}
void ethread::setName(const etk::String& _name) {
setThreadName(nullptr, _name);
//setThreadName(nullptr, _name);
}
void ethread::setName(std::thread& _thread, const etk::String& _name) {
setThreadName(&_thread, _name);
void ethread::setName(ethread::Thread& _thread, const etk::String& _name) {
//setThreadName(&_thread, _name);
}
etk::String ethread::getName() {
return getThreadName(std::this_thread::get_id());
//return getThreadName(std::this_thread::get_id());
return "";
}
etk::String ethread::getName(std::thread& _thread) {
return getThreadName(_thread.get_id());
etk::String ethread::getName(ethread::Thread& _thread) {
//return getThreadName(_thread.get_id());
return "";
}
#if defined(__TARGET_OS__Linux) \
&& !defined(__TARGET_OS__Web)
static void setThreadPriority(pthread_t _threadID, int32_t _priority) {
#if 0
int retcode;
int policy;
struct sched_param param;
@ -125,8 +135,10 @@ etk::String ethread::getName(std::thread& _thread) {
"???") );
*/
}
#endif
}
static int32_t getThreadPriority(pthread_t _threadID) {
/*
int retcode;
int policy;
struct sched_param param;
@ -139,27 +151,35 @@ etk::String ethread::getName(std::thread& _thread) {
return -param.sched_priority;
}
return param.sched_priority;
*/
return 0;
}
#endif
void ethread::setPriority(int32_t _priority) {
/*
#if defined(__TARGET_OS__Linux) \
&& !defined(__TARGET_OS__Web)
pthread_t threadID = pthread_self();
setThreadPriority(threadID, _priority);
#endif
*/
}
void ethread::setPriority(std::thread& _thread, int32_t _priority) {
void ethread::setPriority(ethread::Thread& _thread, int32_t _priority) {
/*
#if defined(__TARGET_OS__Linux) \
&& !defined(__TARGET_OS__Web)
pthread_t threadID = (pthread_t) _thread.native_handle();
setThreadPriority(threadID, _priority);
#endif
*/
}
int32_t ethread::getPriority() {
/*
#if defined(__TARGET_OS__Linux) \
&& !defined(__TARGET_OS__Web)
pthread_t threadID = pthread_self();
@ -167,9 +187,12 @@ int32_t ethread::getPriority() {
#else
return 20;
#endif
*/
return 20;
}
int32_t ethread::getPriority(std::thread& _thread) {
int32_t ethread::getPriority(ethread::Thread& _thread) {
/*
#if defined(__TARGET_OS__Linux) \
&& !defined(__TARGET_OS__Web)
pthread_t threadID = static_cast<pthread_t>(_thread.native_handle());
@ -177,14 +200,17 @@ int32_t ethread::getPriority(std::thread& _thread) {
#else
return 20;
#endif
*/
return 20;
}
static std::mutex g_localMutex;
//static ethread::Mutex g_localMutex;
static etk::Map<uint32_t, etk::Map<etk::String, uint64_t>> g_listMetaData;
void ethread::metadataSet(const etk::String& _key, uint64_t _value) {
/*
uint32_t currentThreadId = ethread::getId();
std::unique_lock<std::mutex> lock(g_localMutex);
// TODO: std::unique_lock<ethread::Mutex> lock(g_localMutex);
auto it = g_listMetaData.find(currentThreadId);
if (it != g_listMetaData.end()) {
it.getValue().set(_key, _value);
@ -193,11 +219,13 @@ void ethread::metadataSet(const etk::String& _key, uint64_t _value) {
tmp.set(_key, _value);
g_listMetaData.set(currentThreadId, tmp);
}
*/
}
void ethread::metadataRemove(const etk::String& _key) {
/*
uint32_t currentThreadId = ethread::getId();
std::unique_lock<std::mutex> lock(g_localMutex);
// TODO: std::unique_lock<ethread::Mutex> lock(g_localMutex);
etk::Map<uint32_t, etk::Map<etk::String, uint64_t>>::Iterator it = g_listMetaData.find(currentThreadId);
if (it != g_listMetaData.end()) {
auto it2 = it.getValue().find(_key);
@ -205,11 +233,14 @@ void ethread::metadataRemove(const etk::String& _key) {
it.getValue().erase(it2);
}
}
*/
}
uint64_t ethread::metadataGetU64(const etk::String& _key) {
/*
uint32_t currentThreadId = ethread::getId();
std::unique_lock<std::mutex> lock(g_localMutex);
// TODO: std::unique_lock<ethread::Mutex> lock(g_localMutex);
auto it = g_listMetaData.find(currentThreadId);
if (it != g_listMetaData.end()) {
auto it2 = it.getValue().find(_key);
@ -217,5 +248,12 @@ uint64_t ethread::metadataGetU64(const etk::String& _key) {
return it2.getValue();
}
}
*/
return 0;
}
}
void ethread::sleepMilliSeconds(uint32_t _timeInMilliSeconds) {
usleep(_timeInMilliSeconds*1000);
}

View File

@ -5,7 +5,7 @@
*/
#pragma once
#include <thread>
#include <ethread/Thread.hpp>
#include <etk/String.hpp>
/**
@ -13,16 +13,16 @@
*/
namespace ethread {
/**
* @brief get human readable thread ID. (not the std::thread::get_id())
* @brief get human readable thread ID. (not the ethread::Thread::getId())
* @return the ID of the thread.
*/
uint32_t getId();
/**
* @brief get human readable thread ID. (not the std::thread::get_id())
* @brief get human readable thread ID. (not the ethread::Thread::getId())
* @param[in] _thread Thread handle
* @return the ID of the thread.
*/
uint32_t getId(std::thread& _thread);
uint32_t getId(ethread::Thread& _thread);
/**
* @brief Set the Current thread name
* @param[in] _name New name of the thread
@ -33,7 +33,7 @@ namespace ethread {
* @param[in] _thread Thread handle
* @param[in] _name New name of the thread
*/
void setName(std::thread& _thread, const etk::String& _name);
void setName(ethread::Thread& _thread, const etk::String& _name);
/**
* @brief Set the Current thread name
* @return The current name of the thread
@ -44,7 +44,7 @@ namespace ethread {
* @param[in] _thread Thread handle
* @return The external thread name of the thread
*/
etk::String getName(std::thread& _thread);
etk::String getName(ethread::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
@ -57,7 +57,7 @@ namespace ethread {
* @param[in] _priority New priority of the thread
* @note If your process have not the right to change thread name, it does not work
*/
void setPriority(std::thread& _thread, int32_t _priority);
void setPriority(ethread::Thread& _thread, int32_t _priority);
/**
* @brief get the Current thread priority [-20..0] for RT and ]0..50] for normal priority
* @return current priority of the thread
@ -68,7 +68,7 @@ namespace ethread {
* @param[in] _thread Thread handle
* @return current priority of the thread
*/
int32_t getPriority(std::thread& _thread);
int32_t getPriority(ethread::Thread& _thread);
/**
* @brief Set an information with a key on the current thread
* @param[in] _key key to store the value
@ -86,4 +86,6 @@ namespace ethread {
* @return the uint 64 value to stored
*/
uint64_t metadataGetU64(const etk::String& _key);
void sleepMilliSeconds(uint32_t _timeInMilliSeconds);
}

View File

@ -33,13 +33,28 @@ def configure(target, my_module):
my_module.add_header_file([
'ethread/tools.hpp',
'ethread/Thread.hpp',
'ethread/Mutex.hpp',
'ethread/Semaphore.hpp',
])
if "Windows" in target.get_type():
my_module.add_src_file([
'ethread/Mutex.Windows.cpp',
'ethread/Thread.Windows.cpp',
])
else:
my_module.add_src_file([
'ethread/Mutex.pthread.cpp',
'ethread/Thread.pthread.cpp',
])
my_module.add_depend([
'pthread',
])
# build in C++ mode
my_module.compile_version("c++", 2011)
# add dependency of the generic C++ library:
my_module.add_depend([
'cxx',
'etk-base',
])
#pthread is not availlable on Windows

View File

@ -42,22 +42,16 @@ def configure(target, my_module):
'ethread/Pool.hpp',
'ethread/PoolAction.hpp',
'ethread/PoolExecutor.hpp',
'ethread/Mutex.hpp',
'ethread/Semaphore.hpp',
'ethread/Thread.hpp',
])
if "Windows" in target.get_type():
my_module.add_src_file([
'ethread/Mutex.Windows.cpp',
'ethread/Semaphore.Windows.cpp',
'ethread/Thread.Windows.cpp',
])
else:
my_module.add_src_file([
'ethread/Mutex.pthread.cpp',
'ethread/Semaphore.pthread.cpp',
'ethread/Thread.pthread.cpp',
])
my_module.add_depend([
'pthread',
])