[DEV/DEBUG] No stl start to work (add manual type declaration (NO RTTI))
This commit is contained in:
parent
5be0e06356
commit
9d6f76219f
@ -7,6 +7,9 @@
|
||||
#include "debug.hpp"
|
||||
#include <ethread/Future.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ethread::Future);
|
||||
|
||||
ethread::Future::Future(ememory::SharedPtr<ethread::Promise> _promise):
|
||||
m_promise(_promise) {
|
||||
|
||||
|
@ -7,6 +7,10 @@
|
||||
|
||||
#include <ethread/Mutex.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ethread::Mutex);
|
||||
ETK_DECLARE_TYPE(ethread::UniqueLock);
|
||||
|
||||
ethread::Mutex::Mutex() {
|
||||
InitializeCriticalSection(&m_mutex);
|
||||
}
|
||||
|
@ -6,6 +6,13 @@
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <ethread/tools.hpp>
|
||||
extern "C" {
|
||||
#include <errno.h>
|
||||
}
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ethread::Mutex);
|
||||
ETK_DECLARE_TYPE(ethread::UniqueLock);
|
||||
//#include <ethread/debug.hpp>
|
||||
|
||||
ethread::Mutex::Mutex() {
|
||||
@ -28,7 +35,40 @@ void ethread::Mutex::lock() {
|
||||
|
||||
|
||||
bool ethread::Mutex::tryLock() {
|
||||
return pthread_mutex_trylock(&m_mutex) != 0;
|
||||
int ret = pthread_mutex_trylock(&m_mutex);
|
||||
if (ret == 0) {
|
||||
return true;
|
||||
}
|
||||
if (ret == EINVAL) {
|
||||
printf("trylock error: EINVAL\n");
|
||||
// The mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread's
|
||||
// priority is higher than the mutex's current priority ceiling.
|
||||
// The pthread_mutex_trylock() function shall fail if:
|
||||
}
|
||||
if (ret == EBUSY) {
|
||||
printf("trylock error: EBUSY\n");
|
||||
// The mutex could not be acquired because it was already locked.
|
||||
// The pthread_mutex_lock(), pthread_mutex_trylock(), and pthread_mutex_unlock() functions may fail if:
|
||||
}
|
||||
if (ret == EINVAL) {
|
||||
printf("trylock error: EINVAL\n");
|
||||
// The value specified by mutex does not refer to an initialized mutex object.
|
||||
}
|
||||
if (ret == EAGAIN) {
|
||||
printf("trylock error: EAGAIN\n");
|
||||
// The mutex could not be acquired because the maximum number of recursive locks for mutex has been exceeded.
|
||||
// The pthread_mutex_lock() function may fail if:
|
||||
}
|
||||
if (ret == EDEADLK) {
|
||||
printf("trylock error: EDEADLK\n");
|
||||
// The current thread already owns the mutex.
|
||||
// The pthread_mutex_unlock() function may fail if:
|
||||
}
|
||||
if (ret == EPERM) {
|
||||
printf("trylock error: EPERM\n");
|
||||
//The current thread does not own the mutex.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <ethread/Pool.hpp>
|
||||
#include <ethread/PoolExecutor.hpp>
|
||||
#include "debug.hpp"
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ethread::Pool);
|
||||
|
||||
ethread::Pool::Pool(uint16_t _numberOfThread):
|
||||
m_lastTrandId(1) {
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include <ethread/PoolAction.hpp>
|
||||
#include "debug.hpp"
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ethread::PoolAction);
|
||||
|
||||
ethread::PoolAction::PoolAction(uint64_t _currentPoolId, ememory::SharedPtr<ethread::Promise> _promise, etk::Function<void()> _call) :
|
||||
m_currentPoolId(_currentPoolId),
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include <ethread/PoolExecutor.hpp>
|
||||
#include <ethread/tools.hpp>
|
||||
#include "debug.hpp"
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ethread::PoolExecutor);
|
||||
|
||||
ethread::PoolExecutor::PoolExecutor(ethread::Pool& _pool):
|
||||
m_needProcess(false),
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <ethread/Future.hpp>
|
||||
#include <ethread/Promise.hpp>
|
||||
#include <echrono/Steady.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ethread::Promise);
|
||||
|
||||
ethread::Promise::Promise():
|
||||
m_isFinished(false) {
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/Semaphore.hpp>
|
||||
#include <etk/debug.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ethread::Semaphore);
|
||||
|
||||
etk::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax) {
|
||||
// create interface mutex :
|
||||
|
@ -7,17 +7,19 @@
|
||||
#include <ethread/Semaphore.hpp>
|
||||
//#include <ethread/debug.hpp>
|
||||
#include <sys/time.h>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ethread::Semaphore);
|
||||
|
||||
ethread::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax) {
|
||||
// create interface mutex :
|
||||
int ret = pthread_mutex_init(&m_mutex, nullptr);
|
||||
TK_ASSERT(ret == 0, "Error creating Mutex ...");
|
||||
//TK_ASSERT(ret == 0, "Error creating Mutex ...");
|
||||
// create contition :
|
||||
ret = pthread_cond_init(&m_condition, nullptr);
|
||||
TK_ASSERT(ret == 0, "Error creating Condition ...");
|
||||
//TK_ASSERT(ret == 0, "Error creating Condition ...");
|
||||
if (ret != 0) {
|
||||
ret = pthread_mutex_destroy(&m_mutex);
|
||||
TK_ASSERT(ret == 0, "Error destroying Mutex ...");
|
||||
//TK_ASSERT(ret == 0, "Error destroying Mutex ...");
|
||||
}
|
||||
m_maximum = _nbMessageMax;
|
||||
m_data = _nbBasicElement;
|
||||
@ -27,10 +29,10 @@ ethread::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax)
|
||||
ethread::Semaphore::~Semaphore() {
|
||||
// Remove condition
|
||||
int ret = pthread_cond_destroy(&m_condition);
|
||||
TK_ASSERT(ret == 0, "Error destroying Condition ...");
|
||||
//TK_ASSERT(ret == 0, "Error destroying Condition ...");
|
||||
// Remove Mutex
|
||||
ret = pthread_mutex_destroy(&m_mutex);
|
||||
TK_ASSERT(ret == 0, "Error destroying Mutex ...");
|
||||
//TK_ASSERT(ret == 0, "Error destroying Mutex ...");
|
||||
}
|
||||
|
||||
uint32_t ethread::Semaphore::getCount() {
|
||||
|
@ -38,8 +38,15 @@ namespace ethread {
|
||||
bool detach();
|
||||
void threadCall();
|
||||
void setName(const etk::String& _name);
|
||||
const etk::String& setName() const;
|
||||
const etk::String& getName() const;
|
||||
uint64_t getId() const;
|
||||
#ifdef __TARGET_OS__Windows
|
||||
|
||||
#else
|
||||
pthread_t getNativeHandle() {
|
||||
return m_thread;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,16 @@
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#include <ethread/Thread.hpp>
|
||||
#include <ethread/tools.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ethread::Thread);
|
||||
|
||||
namespace ethread {
|
||||
uint32_t getThreadHumanId(uint64_t _id);
|
||||
etk::String getThreadName(uint64_t _id);
|
||||
void setThreadName(ethread::Thread* _thread, const etk::String& _name);
|
||||
}
|
||||
|
||||
void* ethread::Thread::threadCallback(void* _userData) {
|
||||
ethread::Thread* threadHandle = static_cast<ethread::Thread*>(_userData);
|
||||
@ -20,13 +29,10 @@ ethread::Thread::Thread(etk::Function<void()>&& _call, const etk::String& _name)
|
||||
m_uid(-1),
|
||||
m_name(_name),
|
||||
m_function(etk::move(_call)) {
|
||||
uint32_t iii = ethread::getId();
|
||||
pthread_create(&m_thread, nullptr, ðread::Thread::threadCallback, this);
|
||||
/*
|
||||
pthread_id_np_t tid;
|
||||
pthread_getunique_np(&m_thread, &tid);
|
||||
m_uid = uint64_t(tid);
|
||||
*/
|
||||
m_uid = *(uint64_t*)(m_thread);
|
||||
m_uid = ethread::getThreadHumanId(uint64_t(m_thread));
|
||||
printf("New thread: %d from %d", m_uid, iii);
|
||||
}
|
||||
|
||||
ethread::Thread::~Thread() {
|
||||
@ -40,13 +46,15 @@ void ethread::Thread::join() {
|
||||
|
||||
bool ethread::Thread::detach() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ethread::Thread::setName(const etk::String& _name) {
|
||||
m_name = _name;
|
||||
ethread::setThreadName(this, m_name);
|
||||
}
|
||||
|
||||
const etk::String& ethread::Thread::setName() const {
|
||||
const etk::String& ethread::Thread::getName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <ethread/tools.hpp>
|
||||
#include <etk/Pair.hpp>
|
||||
//#include <ethread/Mutex.hpp>
|
||||
#include <ethread/Mutex.hpp>
|
||||
// TODO: set mutex back ...
|
||||
#include <etk/Map.hpp>
|
||||
extern "C" {
|
||||
@ -19,104 +19,101 @@ extern "C" {
|
||||
#include <pthread.h>
|
||||
}
|
||||
#endif
|
||||
//static ethread::Mutex g_lock;
|
||||
static etk::Map<uint32_t, etk::String>& getThreadList() {
|
||||
static etk::Map<uint32_t, etk::String> g_val;
|
||||
static ethread::Mutex g_lock;
|
||||
static etk::Map<uint64_t, etk::String>& getThreadList() {
|
||||
static etk::Map<uint64_t, etk::String> g_val;
|
||||
return g_val;
|
||||
}
|
||||
/*
|
||||
static uint32_t getThreadHumanId(ethread::Thread::id _id) {
|
||||
return 0;
|
||||
uint32_t out = 0;
|
||||
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()) {
|
||||
// attribute new ID :
|
||||
static uint32_t tmpId = 0;
|
||||
g_list.set(iddd,tmpId);
|
||||
out = tmpId;
|
||||
tmpId++;
|
||||
} else {
|
||||
out = it.getValue();
|
||||
}
|
||||
// TODO: g_lock.unlock();
|
||||
return out;
|
||||
}
|
||||
|
||||
static etk::String getThreadName(ethread::Thread::id _id) {
|
||||
etk::Map<uint32_t,etk::String>& list = getThreadList();
|
||||
uint32_t threadID = getThreadHumanId(_id);
|
||||
etk::String out;
|
||||
// TODO: g_lock.lock();
|
||||
auto it = list.find(threadID);
|
||||
if (it != list.end()) {
|
||||
out = it.getValue();
|
||||
}
|
||||
// TODO: g_lock.unlock();
|
||||
return out;
|
||||
return "TODO";
|
||||
}
|
||||
|
||||
static void setThreadName(ethread::Thread* _thread, const etk::String& _name) {
|
||||
etk::Map<uint32_t,etk::String>& list = getThreadList();
|
||||
uint32_t threadID = ethread::getId();
|
||||
// TODO: g_lock.lock();
|
||||
list.set(threadID, _name);
|
||||
vg_lock.unlock();
|
||||
// try now to set the thread name with Pthread
|
||||
#if defined(__TARGET_OS__Linux) \
|
||||
&& !defined(__TARGET_OS__Web)
|
||||
pthread_t pthreadID;
|
||||
if (_thread == nullptr) {
|
||||
pthreadID = pthread_self();
|
||||
namespace ethread {
|
||||
// Note: Declared in Thread.cpp
|
||||
uint32_t getThreadHumanId(uint64_t _id) {
|
||||
uint32_t out = 0;
|
||||
g_lock.lock();
|
||||
static etk::Map<uint64_t, uint32_t> g_list;
|
||||
auto it = g_list.find(_id);
|
||||
if (it == g_list.end()) {
|
||||
// attribute new ID :
|
||||
static uint32_t tmpId = 0;
|
||||
g_list.set(_id, tmpId);
|
||||
out = tmpId;
|
||||
tmpId++;
|
||||
} else {
|
||||
pthreadID = (pthread_t) _thread->native_handle();
|
||||
out = it.getValue();
|
||||
}
|
||||
etk::String name = _name;
|
||||
if (name.size() > 15) {
|
||||
name.resize(15);
|
||||
g_lock.unLock();
|
||||
return out;
|
||||
}
|
||||
|
||||
etk::String getThreadName(uint64_t _id) {
|
||||
etk::Map<uint64_t,etk::String>& list = getThreadList();
|
||||
uint32_t threadID = getThreadHumanId(_id);
|
||||
etk::String out;
|
||||
// TODO: g_lock.lock();
|
||||
auto it = list.find(threadID);
|
||||
if (it != list.end()) {
|
||||
out = it.getValue();
|
||||
}
|
||||
if (pthread_setname_np(pthreadID, name.c_str()) < 0) {
|
||||
//TODO: TK_ERROR("Error when setting the Name in the OS thread naming");
|
||||
}
|
||||
#else
|
||||
//TODO: TK_INFO("Can not set the thread name in this OS (local set)");
|
||||
#endif
|
||||
// TODO: g_lock.unlock();
|
||||
return out;
|
||||
}
|
||||
|
||||
void setThreadName(ethread::Thread* _thread, const etk::String& _name) {
|
||||
etk::Map<uint64_t,etk::String>& list = getThreadList();
|
||||
uint32_t threadID = ethread::getId();
|
||||
// TODO: g_lock.lock();
|
||||
list.set(threadID, _name);
|
||||
// TODO: g_lock.unlock();
|
||||
// try now to set the thread name with Pthread
|
||||
#if ( defined(__TARGET_OS__Linux) \
|
||||
|| defined(__TARGET_OS__Android) \
|
||||
) \
|
||||
&& !defined(__TARGET_OS__Web)
|
||||
pthread_t pthreadID;
|
||||
if (_thread == nullptr) {
|
||||
pthreadID = pthread_self();
|
||||
} else {
|
||||
pthreadID = _thread->getNativeHandle();
|
||||
}
|
||||
etk::String name = _name;
|
||||
if (name.size() > 15) {
|
||||
name.resize(15);
|
||||
}
|
||||
if (pthread_setname_np(pthreadID, name.c_str()) < 0) {
|
||||
//TODO: TK_ERROR("Error when setting the Name in the OS thread naming");
|
||||
}
|
||||
#else
|
||||
//TODO: TK_INFO("Can not set the thread name in this OS (local set)");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
uint32_t ethread::getId() {
|
||||
pthread_t self;
|
||||
self = pthread_self();
|
||||
/*
|
||||
pthread_id_np_t tid;
|
||||
pthread_getunique_np(&self, &tid);
|
||||
return uint64_t(tid);
|
||||
*/
|
||||
return *(uint64_t*)(self);
|
||||
return ethread::getThreadHumanId(uint64_t(self));
|
||||
}
|
||||
|
||||
uint32_t ethread::getId(ethread::Thread& _thread) {
|
||||
return _thread.getId();
|
||||
return ethread::getThreadHumanId(_thread.getId());
|
||||
}
|
||||
|
||||
void ethread::setName(const etk::String& _name) {
|
||||
//setThreadName(nullptr, _name);
|
||||
setThreadName(nullptr, _name);
|
||||
}
|
||||
|
||||
void ethread::setName(ethread::Thread& _thread, const etk::String& _name) {
|
||||
//setThreadName(&_thread, _name);
|
||||
_thread.setName(_name);
|
||||
}
|
||||
|
||||
etk::String ethread::getName() {
|
||||
//return getThreadName(std::this_thread::get_id());
|
||||
return "";
|
||||
pthread_t self;
|
||||
self = pthread_self();
|
||||
return getThreadName(uint64_t(self));
|
||||
}
|
||||
|
||||
etk::String ethread::getName(ethread::Thread& _thread) {
|
||||
//return getThreadName(_thread.get_id());
|
||||
return "";
|
||||
return _thread.getName();
|
||||
}
|
||||
|
||||
#if defined(__TARGET_OS__Linux) \
|
||||
|
@ -44,12 +44,14 @@ def configure(target, my_module):
|
||||
'ethread/Mutex.Windows.cpp',
|
||||
'ethread/MutexRecursive.Windows.cpp',
|
||||
'ethread/Thread.Windows.cpp',
|
||||
'ethread/Semaphore.Windows.cpp',
|
||||
])
|
||||
else:
|
||||
my_module.add_src_file([
|
||||
'ethread/Mutex.pthread.cpp',
|
||||
'ethread/MutexRecursive.pthread.cpp',
|
||||
'ethread/Thread.pthread.cpp',
|
||||
'ethread/Semaphore.pthread.cpp',
|
||||
])
|
||||
my_module.add_depend([
|
||||
'pthread',
|
||||
|
@ -44,17 +44,6 @@ def configure(target, my_module):
|
||||
'ethread/PoolExecutor.hpp',
|
||||
])
|
||||
|
||||
if "Windows" in target.get_type():
|
||||
my_module.add_src_file([
|
||||
'ethread/Semaphore.Windows.cpp',
|
||||
])
|
||||
else:
|
||||
my_module.add_src_file([
|
||||
'ethread/Semaphore.pthread.cpp',
|
||||
])
|
||||
my_module.add_depend([
|
||||
'pthread',
|
||||
])
|
||||
# build in C++ mode
|
||||
my_module.compile_version("c++", 2011)
|
||||
# add dependency of the generic C++ library:
|
||||
|
Loading…
x
Reference in New Issue
Block a user