[DEV] update etk null

This commit is contained in:
Edouard DUPIN 2018-06-19 22:13:48 +02:00
parent 8ee819a6e1
commit 9902ff0e2d
11 changed files with 32 additions and 32 deletions

View File

@ -16,7 +16,7 @@ ethread::Future::Future(ememory::SharedPtr<ethread::Promise> _promise):
} }
bool ethread::Future::isFinished() { bool ethread::Future::isFinished() {
if (m_promise == nullptr) { if (m_promise == null) {
ETHREAD_ERROR("Promise does not exist..."); ETHREAD_ERROR("Promise does not exist...");
return true; return true;
} }
@ -24,7 +24,7 @@ bool ethread::Future::isFinished() {
} }
bool ethread::Future::wait(echrono::Duration _delay) { bool ethread::Future::wait(echrono::Duration _delay) {
if (m_promise == nullptr) { if (m_promise == null) {
ETHREAD_ERROR("Promise does not exist..."); ETHREAD_ERROR("Promise does not exist...");
return false; return false;
} }
@ -32,7 +32,7 @@ bool ethread::Future::wait(echrono::Duration _delay) {
} }
void ethread::Future::andThen(etk::Function<void()> _action) { void ethread::Future::andThen(etk::Function<void()> _action) {
if (m_promise == nullptr) { if (m_promise == null) {
ETHREAD_ERROR("Promise does not exist..."); ETHREAD_ERROR("Promise does not exist...");
return; return;
} }

View File

@ -22,7 +22,7 @@ namespace ethread {
* @brief Simple Future contructor * @brief Simple Future contructor
* @param[in] _promise Associated promise to wait * @param[in] _promise Associated promise to wait
*/ */
Future(ememory::SharedPtr<ethread::Promise> _promise=nullptr); Future(ememory::SharedPtr<ethread::Promise> _promise=null);
/** /**
* @brief Check if the action is finished * @brief Check if the action is finished
* @return true, the action is done, false otherwise * @return true, the action is done, false otherwise

View File

@ -17,7 +17,7 @@ ETK_DECLARE_TYPE(ethread::UniqueLock);
ethread::Mutex::Mutex() { ethread::Mutex::Mutex() {
// create interface mutex : // create interface mutex :
int ret = pthread_mutex_init(&m_mutex, nullptr); int ret = pthread_mutex_init(&m_mutex, null);
//ETHREAD_ASSERT(ret == 0, "Error creating Mutex ..."); //ETHREAD_ASSERT(ret == 0, "Error creating Mutex ...");
} }

View File

@ -15,7 +15,7 @@ ethread::Pool::Pool(uint16_t _numberOfThread):
ethread::UniqueLock lock(m_mutex); ethread::UniqueLock lock(m_mutex);
for (uint32_t iii=0; iii<_numberOfThread; ++iii) { for (uint32_t iii=0; iii<_numberOfThread; ++iii) {
ememory::SharedPtr<ethread::PoolExecutor> tmp = ememory::makeShared<ethread::PoolExecutor>(*this); ememory::SharedPtr<ethread::PoolExecutor> tmp = ememory::makeShared<ethread::PoolExecutor>(*this);
if (tmp != nullptr) { if (tmp != null) {
tmp->start(); tmp->start();
m_listThread.pushBack(tmp); m_listThread.pushBack(tmp);
} }
@ -34,7 +34,7 @@ uint32_t ethread::Pool::createGroupId() {
ethread::Future ethread::Pool::async(etk::Function<void()> _call, uint64_t _executionInGroupId) { ethread::Future ethread::Pool::async(etk::Function<void()> _call, uint64_t _executionInGroupId) {
ethread::UniqueLock lock(m_mutex); ethread::UniqueLock lock(m_mutex);
if (_call == nullptr) { if (_call == null) {
ETHREAD_ERROR("Can not add an action with no function to call..."); ETHREAD_ERROR("Can not add an action with no function to call...");
return ethread::Future(); return ethread::Future();
} }
@ -42,7 +42,7 @@ ethread::Future ethread::Pool::async(etk::Function<void()> _call, uint64_t _exec
ememory::SharedPtr<ethread::PoolAction> action = ememory::makeShared<ethread::PoolAction>(_executionInGroupId, promise, _call); ememory::SharedPtr<ethread::PoolAction> action = ememory::makeShared<ethread::PoolAction>(_executionInGroupId, promise, _call);
m_listActions.pushBack(action); m_listActions.pushBack(action);
for(auto &it : m_listThread) { for(auto &it : m_listThread) {
if (it == nullptr) { if (it == null) {
continue; continue;
} }
if (it->touch() == true) { if (it->touch() == true) {
@ -73,7 +73,7 @@ ememory::SharedPtr<ethread::PoolAction> ethread::Pool::getAction() {
ethread::UniqueLock lock(m_mutex); ethread::UniqueLock lock(m_mutex);
auto it = m_listActions.begin(); auto it = m_listActions.begin();
while (it != m_listActions.end()) { while (it != m_listActions.end()) {
if (*it == nullptr) { if (*it == null) {
it = m_listActions.erase(it); it = m_listActions.erase(it);
continue; continue;
} }
@ -98,7 +98,7 @@ ememory::SharedPtr<ethread::PoolAction> ethread::Pool::getAction() {
} }
++it; ++it;
} }
return nullptr; return null;
} }
@ -106,7 +106,7 @@ void ethread::Pool::stop() {
ethread::UniqueLock lock(m_mutex); ethread::UniqueLock lock(m_mutex);
auto it = m_listThread.begin(); auto it = m_listThread.begin();
while (it != m_listThread.end()) { while (it != m_listThread.end()) {
if (*it == nullptr) { if (*it == null) {
it = m_listThread.erase(it); it = m_listThread.erase(it);
continue; continue;
} }
@ -120,7 +120,7 @@ void ethread::Pool::join() {
ETHREAD_DEBUG("start join all the threads in pool " << m_listThread.size()); ETHREAD_DEBUG("start join all the threads in pool " << m_listThread.size());
for (size_t iii=0; iii<m_listThread.size(); ++iii) { for (size_t iii=0; iii<m_listThread.size(); ++iii) {
ETHREAD_DEBUG(" join " << iii); ETHREAD_DEBUG(" join " << iii);
if (m_listThread[iii] == nullptr) { if (m_listThread[iii] == null) {
continue; continue;
} }
m_listThread[iii]->join(); m_listThread[iii]->join();

View File

@ -21,13 +21,13 @@ uint64_t ethread::PoolAction::getPoolId() const {
} }
void ethread::PoolAction::call() { void ethread::PoolAction::call() {
if (m_call == nullptr) { if (m_call == null) {
return; return;
} }
if (m_call != nullptr) { if (m_call != null) {
m_call(); m_call();
} }
if (m_promise != nullptr) { if (m_promise != null) {
m_promise->finish(); m_promise->finish();
} }
} }

View File

@ -29,7 +29,7 @@ void ethread::PoolExecutor::threadCallback() {
while (m_running == true) { while (m_running == true) {
// get an action: // get an action:
m_action = m_pool.getAction(); m_action = m_pool.getAction();
if (m_action == nullptr) { if (m_action == null) {
// If no action availlable and not requested to check, just sleep ... // If no action availlable and not requested to check, just sleep ...
if (m_needProcess == false) { if (m_needProcess == false) {
m_isWaiting = true; m_isWaiting = true;
@ -57,7 +57,7 @@ void ethread::PoolExecutor::start() {
m_running = true; m_running = true;
m_semaphore.post(); m_semaphore.post();
m_thread = ememory::makeShared<ethread::Thread>([&](){ threadCallback();}); m_thread = ememory::makeShared<ethread::Thread>([&](){ threadCallback();});
if (m_thread == nullptr) { if (m_thread == null) {
m_running = false; m_running = false;
ETHREAD_ERROR("START: thread in Pool [STOP] can not intanciate THREAD!"); ETHREAD_ERROR("START: thread in Pool [STOP] can not intanciate THREAD!");
return; return;
@ -76,7 +76,7 @@ void ethread::PoolExecutor::stop() {
void ethread::PoolExecutor::join() { void ethread::PoolExecutor::join() {
ETHREAD_DEBUG("JOIN: thread in Pool [START]"); ETHREAD_DEBUG("JOIN: thread in Pool [START]");
m_semaphore.post(); m_semaphore.post();
if (m_thread != nullptr) { if (m_thread != null) {
ETHREAD_DEBUG("JOIN: waiting ..."); ETHREAD_DEBUG("JOIN: waiting ...");
m_thread->join(); m_thread->join();
m_thread.reset(); m_thread.reset();

View File

@ -30,12 +30,12 @@ void ethread::Promise::finish() {
return; return;
} }
m_isFinished = true; m_isFinished = true;
if (m_callback != nullptr) { if (m_callback != null) {
// call callbacks ... // call callbacks ...
callback = etk::move(m_callback); callback = etk::move(m_callback);
} }
} }
if (callback != nullptr) { if (callback != null) {
callback(); callback();
} }
} }

View File

@ -11,7 +11,7 @@ ETK_DECLARE_TYPE(ethread::Semaphore);
etk::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax) { etk::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax) {
// create interface mutex : // create interface mutex :
m_semaphore = CreateSemaphore(nullptr, _nbBasicElement, _nbMessageMax, nullptr); m_semaphore = CreateSemaphore(null, _nbBasicElement, _nbMessageMax, null);
TK_ASSERT(m_semaphore != 0, "Error creating SEMAPHORE ..."); TK_ASSERT(m_semaphore != 0, "Error creating SEMAPHORE ...");
} }
@ -27,7 +27,7 @@ uint32_t etk::Semaphore::getCount() {
} }
void etk::Semaphore::post() { void etk::Semaphore::post() {
ReleaseSemaphore(m_semaphore, 1, nullptr); ReleaseSemaphore(m_semaphore, 1, null);
} }

View File

@ -12,10 +12,10 @@ ETK_DECLARE_TYPE(ethread::Semaphore);
ethread::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax) { ethread::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax) {
// create interface mutex : // create interface mutex :
int ret = pthread_mutex_init(&m_mutex, nullptr); int ret = pthread_mutex_init(&m_mutex, null);
//TK_ASSERT(ret == 0, "Error creating Mutex ..."); //TK_ASSERT(ret == 0, "Error creating Mutex ...");
// create contition : // create contition :
ret = pthread_cond_init(&m_condition, nullptr); ret = pthread_cond_init(&m_condition, null);
//TK_ASSERT(ret == 0, "Error creating Condition ..."); //TK_ASSERT(ret == 0, "Error creating Condition ...");
if (ret != 0) { if (ret != 0) {
ret = pthread_mutex_destroy(&m_mutex); ret = pthread_mutex_destroy(&m_mutex);
@ -71,7 +71,7 @@ bool ethread::Semaphore::wait(uint64_t _timeOutInUs) {
if(m_data == 0) { if(m_data == 0) {
struct timeval tp; struct timeval tp;
struct timespec ts; struct timespec ts;
gettimeofday(&tp, nullptr); gettimeofday(&tp, null);
uint64_t totalTimeUS = tp.tv_sec * 1000000 + tp.tv_usec; uint64_t totalTimeUS = tp.tv_sec * 1000000 + tp.tv_usec;
totalTimeUS += _timeOutInUs; totalTimeUS += _timeOutInUs;
ts.tv_sec = totalTimeUS / 1000000; ts.tv_sec = totalTimeUS / 1000000;

View File

@ -17,10 +17,10 @@ namespace ethread {
void* ethread::Thread::threadCallback(void* _userData) { void* ethread::Thread::threadCallback(void* _userData) {
ethread::Thread* threadHandle = static_cast<ethread::Thread*>(_userData); ethread::Thread* threadHandle = static_cast<ethread::Thread*>(_userData);
if (threadHandle != nullptr) { if (threadHandle != null) {
threadHandle->threadCall(); threadHandle->threadCall();
} }
return nullptr; return null;
} }
@ -30,7 +30,7 @@ ethread::Thread::Thread(etk::Function<void()>&& _call, const etk::String& _name)
m_name(_name), m_name(_name),
m_function(etk::move(_call)) { m_function(etk::move(_call)) {
uint32_t iii = ethread::getId(); uint32_t iii = ethread::getId();
pthread_create(&m_thread, nullptr, &ethread::Thread::threadCallback, this); pthread_create(&m_thread, null, &ethread::Thread::threadCallback, this);
m_uid = ethread::getThreadHumanId(uint64_t(m_thread)); m_uid = ethread::getThreadHumanId(uint64_t(m_thread));
printf("New thread: %ld from %d\n", m_uid, iii); printf("New thread: %ld from %d\n", m_uid, iii);
} }
@ -40,7 +40,7 @@ ethread::Thread::~Thread() {
} }
void ethread::Thread::join() { void ethread::Thread::join() {
void* ret = nullptr; void* ret = null;
int val = pthread_join(m_thread, &ret); int val = pthread_join(m_thread, &ret);
} }
@ -59,7 +59,7 @@ const etk::String& ethread::Thread::getName() const {
} }
void ethread::Thread::threadCall() { void ethread::Thread::threadCall() {
if (m_function != nullptr) { if (m_function != null) {
m_function(); m_function();
} }
} }

View File

@ -69,7 +69,7 @@ namespace ethread {
) \ ) \
&& !defined(__TARGET_OS__Web) && !defined(__TARGET_OS__Web)
pthread_t pthreadID; pthread_t pthreadID;
if (_thread == nullptr) { if (_thread == null) {
pthreadID = pthread_self(); pthreadID = pthread_self();
} else { } else {
pthreadID = _thread->getNativeHandle(); pthreadID = _thread->getNativeHandle();
@ -99,7 +99,7 @@ uint32_t ethread::getId(ethread::Thread& _thread) {
} }
void ethread::setName(const etk::String& _name) { void ethread::setName(const etk::String& _name) {
setThreadName(nullptr, _name); setThreadName(null, _name);
} }
void ethread::setName(ethread::Thread& _thread, const etk::String& _name) { void ethread::setName(ethread::Thread& _thread, const etk::String& _name) {