[DEV] remove STL

This commit is contained in:
Edouard DUPIN 2017-09-07 23:38:26 +02:00
parent 83eecacc0b
commit 56b4ebf9ef
8 changed files with 67 additions and 67 deletions

View File

@ -36,29 +36,29 @@ gale::Thread::~Thread() {
void gale::Thread::start() {
if (m_state == state::stop) {
GALE_DEBUG("Allocate std::thread [START]");
GALE_DEBUG("Allocate ethread::Thread [START]");
m_state = state::starting;
m_context = &gale::getContext();
#if defined(__TARGET_OS__Android)
pthread_create(&m_thread, nullptr, &gale::Thread::threadCallback, this);
#else
m_thread = ememory::makeShared<std::thread>(&gale::Thread::threadCall, this);
m_thread = ememory::makeShared<ethread::Thread>(&gale::Thread::threadCall, this);
if (m_thread == nullptr) {
GALE_ERROR("Can not create thread ...");
return;
}
#endif
//m_thread->detach();
GALE_DEBUG("Allocate std::thread [Set priority]");
GALE_DEBUG("Allocate ethread::Thread [Set priority]");
// set priority
GALE_DEBUG("Allocate std::thread [Register context]");
GALE_DEBUG("Allocate ethread::Thread [Register context]");
// set association with the gale context ...
//gale::contextRegisterThread(m_thread);
GALE_DEBUG("Allocate std::thread [set State]");
GALE_DEBUG("Allocate ethread::Thread [set State]");
m_state = state::running;
GALE_DEBUG("Allocate std::thread [STOP]");
GALE_DEBUG("Allocate ethread::Thread [STOP]");
}
}
@ -74,7 +74,7 @@ void gale::Thread::stop() {
GALE_INFO("wait Thread stopping");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
GALE_DEBUG("stop std::thread [START]");
GALE_DEBUG("stop ethread::Thread [START]");
#if defined(__TARGET_OS__Android)
void* ret = nullptr;
int val = pthread_join(m_thread, &ret);
@ -82,15 +82,15 @@ void gale::Thread::stop() {
m_thread->join();
#endif
//gale::contextUnRegisterThread(m_thread);
GALE_DEBUG("stop std::thread [delete]");
GALE_DEBUG("stop ethread::Thread [delete]");
#if defined(__TARGET_OS__Android)
#else
m_thread.reset();
#endif
GALE_DEBUG("stop std::thread [set state]");
GALE_DEBUG("stop ethread::Thread [set state]");
m_state = state::stop;
GALE_INFO("stop std::thread [STOP]");
GALE_INFO("stop ethread::Thread [STOP]");
}
void gale::Thread::threadCall() {
@ -102,7 +102,7 @@ void gale::Thread::threadCall() {
gale::setContext(m_context);
while (m_state != state::stopping) {
if (m_state == state::starting) {
GALE_DEBUG("run std::thread [NOTHING to do]");
GALE_DEBUG("run ethread::Thread [NOTHING to do]");
std::this_thread::sleep_for(std::chrono::milliseconds(1));
continue;
}
@ -113,7 +113,7 @@ void gale::Thread::threadCall() {
}
}
if (onThreadCall() == true) {
GALE_DEBUG("run std::thread [AUTO STOP]");
GALE_DEBUG("run ethread::Thread [AUTO STOP]");
m_state = state::stopping;
return;
}

View File

@ -12,12 +12,12 @@
#if defined(__TARGET_OS__Android)
#include <pthread.h>
#else
#include <thread>
#include <ethread/Thread.hpp>
#endif
namespace gale {
/**
* @brief We have our own thread in gale to manage gale context folowing and manage android rong management of std::thread when calling java.
* @brief We have our own thread in gale to manage gale context folowing and manage android rong management of ethread::Thread when calling java.
*/
class Thread : public ememory::EnableSharedFromThis<Thread> {
public:
@ -42,7 +42,7 @@ namespace gale {
#if defined(__TARGET_OS__Android)
pthread_t m_thread; //!< Current handle on the thread
#else
ememory::SharedPtr<std::thread> m_thread; //!< Current handle on the thread
ememory::SharedPtr<ethread::Thread> m_thread; //!< Current handle on the thread
#endif
gale::Context* m_context; //!< Copy of the gale context (permit to get current gale interface)
public:

View File

@ -9,7 +9,7 @@
#include <time.h>
#include <cstdint>
#include <pthread.h>
#include <mutex>
#include <ethread/Mutex.hpp>
#include <gale/debug.hpp>
#include <gale/context/Context.hpp>
#include <gale/Dimension.hpp>
@ -19,7 +19,7 @@
// jni doc : /usr/lib/jvm/java-1.6.0-openjdk/include
std::mutex g_interfaceMutex;
ethread::Mutex g_interfaceMutex;
class AndroidContext : public gale::Context {
@ -502,7 +502,7 @@ extern "C" {
jint _mode,
jstring _myString,
jstring _applicationName) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
|| nullptr == s_listInstance[_id] ) {
@ -535,7 +535,7 @@ extern "C" {
jclass _classBase,
jobject _objCallback,
int _typeApplication) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_DEBUG("*******************************************");
GALE_DEBUG("** Creating GALE context **");
GALE_DEBUG("*******************************************");
@ -565,7 +565,7 @@ extern "C" {
}
void Java_org_gale_Gale_EWsetJavaVirtualMachineStop(JNIEnv* _env, jclass _cls, jint _id) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_DEBUG("*******************************************");
GALE_DEBUG("** remove JVM Pointer **");
GALE_DEBUG("*******************************************");
@ -583,7 +583,7 @@ extern "C" {
s_listInstance[_id]=nullptr;
}
void Java_org_gale_Gale_EWtouchEvent(JNIEnv* _env, jobject _thiz, jint _id) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_DEBUG(" == > Touch Event");
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
@ -596,7 +596,7 @@ extern "C" {
}
void Java_org_gale_Gale_EWonCreate(JNIEnv* _env, jobject _thiz, jint _id) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_DEBUG("*******************************************");
GALE_DEBUG("** Activity on Create **");
GALE_DEBUG("*******************************************");
@ -612,7 +612,7 @@ extern "C" {
}
void Java_org_gale_Gale_EWonStart(JNIEnv* _env, jobject _thiz, jint _id) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_DEBUG("*******************************************");
GALE_DEBUG("** Activity on Start **");
GALE_DEBUG("*******************************************");
@ -627,7 +627,7 @@ extern "C" {
//SendSystemMessage(" testmessages ... ");
}
void Java_org_gale_Gale_EWonReStart(JNIEnv* _env, jobject _thiz, jint _id) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_DEBUG("*******************************************");
GALE_DEBUG("** Activity on Re-Start **");
GALE_DEBUG("*******************************************");
@ -641,7 +641,7 @@ extern "C" {
s_listInstance[_id]->ANDROID_reStart();
}
void Java_org_gale_Gale_EWonResume(JNIEnv* _env, jobject _thiz, jint _id) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_DEBUG("*******************************************");
GALE_DEBUG("** Activity on resume **");
GALE_DEBUG("*******************************************");
@ -655,7 +655,7 @@ extern "C" {
s_listInstance[_id]->OS_Resume();
}
void Java_org_gale_Gale_EWonPause(JNIEnv* _env, jobject _thiz, jint _id) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_DEBUG("*******************************************");
GALE_DEBUG("** Activity on pause **");
GALE_DEBUG("*******************************************");
@ -671,7 +671,7 @@ extern "C" {
s_listInstance[_id]->OS_Suspend();
}
void Java_org_gale_Gale_EWonStop(JNIEnv* _env, jobject _thiz, jint _id) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_DEBUG("*******************************************");
GALE_DEBUG("** Activity on Stop **");
GALE_DEBUG("*******************************************");
@ -685,7 +685,7 @@ extern "C" {
s_listInstance[_id]->OS_Stop();
}
void Java_org_gale_Gale_EWonDestroy(JNIEnv* _env, jobject _thiz, jint _id) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_DEBUG("*******************************************");
GALE_DEBUG("** Activity on Destroy **");
GALE_DEBUG("*******************************************");
@ -711,7 +711,7 @@ extern "C" {
jint _pointerID,
jfloat _x,
jfloat _y) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
|| nullptr == s_listInstance[_id] ) {
@ -732,7 +732,7 @@ extern "C" {
jboolean _isDown,
jfloat _x,
jfloat _y) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
if( _id >= (int32_t)s_listInstance.size()
|| _id < 0
|| s_listInstance[_id] == nullptr ) {
@ -752,7 +752,7 @@ extern "C" {
jint _pointerID,
jfloat _x,
jfloat _y) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
|| nullptr == s_listInstance[_id] ) {
@ -773,7 +773,7 @@ extern "C" {
jboolean _isDown,
jfloat _x,
jfloat _y) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
|| nullptr == s_listInstance[_id] ) {
@ -791,7 +791,7 @@ extern "C" {
jobject _thiz,
jint _id,
jint _pointerID) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
|| nullptr == s_listInstance[_id] ) {
@ -807,7 +807,7 @@ extern "C" {
jint _id,
jint _type,
jboolean _isdown) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
|| nullptr == s_listInstance[_id] ) {
@ -824,7 +824,7 @@ extern "C" {
jint _id,
jint _uniChar,
jboolean _isdown) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
|| nullptr == s_listInstance[_id] ) {
@ -841,7 +841,7 @@ extern "C" {
jint _id,
jfloat _ratioX,
jfloat _ratioY) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
|| nullptr == s_listInstance[_id] ) {
@ -859,7 +859,7 @@ extern "C" {
jint _id,
jint _keyVal,
jboolean _isdown) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
|| nullptr == s_listInstance[_id] ) {
@ -903,7 +903,7 @@ extern "C" {
void Java_org_gale_Gale_EWrenderInit(JNIEnv* _env,
jobject _thiz,
jint _id) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_VERBOSE("Java_org_gale_Gale_EWrenderInit [BEGIN]");
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
@ -920,7 +920,7 @@ extern "C" {
jint _id,
jint _w,
jint _h) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_VERBOSE("Java_org_gale_Gale_EWrenderResize [BEGIN]");
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
@ -937,7 +937,7 @@ extern "C" {
void Java_org_gale_Gale_EWrenderDraw(JNIEnv* _env,
jobject _thiz,
jint _id) {
std::unique_lock<std::mutex> lock(g_interfaceMutex);
std::unique_lock<ethread::Mutex> lock(g_interfaceMutex);
GALE_VERBOSE("Java_org_gale_Gale_EWrenderDraw [BEGIN]");
if( _id >= (int32_t)s_listInstance.size()
|| _id<0

View File

@ -12,7 +12,7 @@
#include <etk/tool.hpp>
#include <etk/os/FSNode.hpp>
#include <ethread/tools.hpp>
#include <mutex>
#include <ethread/Mutex.hpp>
#include <gale/gale.hpp>
#include <gale/Dimension.hpp>
@ -30,24 +30,24 @@
* @note due ti the fact that the system can be called for multiple instance, for naw we just limit the acces to one process at a time.
* @return the main inteface Mutex
*/
static std::mutex& mutexInterface() {
static std::mutex s_interfaceMutex;
static ethread::Mutex& mutexInterface() {
static ethread::Mutex s_interfaceMutex;
return s_interfaceMutex;
}
static std::mutex g_lockContextMap;
static etk::Map<std::thread::id, gale::Context*>& getContextList() {
static etk::Map<std::thread::id, gale::Context*> g_val;
static ethread::Mutex g_lockContextMap;
static etk::Map<ethread::Thread::id, gale::Context*>& getContextList() {
static etk::Map<ethread::Thread::id, gale::Context*> g_val;
return g_val;
}
static gale::Context* lastContextSet = nullptr;
gale::Context& gale::getContext() {
etk::Map<std::thread::id, gale::Context*>& list = getContextList();
etk::Map<ethread::Thread::id, gale::Context*>& list = getContextList();
g_lockContextMap.lock();
etk::Map<std::thread::id, gale::Context*>::Iterator it = list.find(std::this_thread::get_id());
etk::Map<ethread::Thread::id, gale::Context*>::Iterator it = list.find(std::this_thread::get_id());
gale::Context* out = nullptr;
if (it != list.end()) {
out = it->second;
@ -85,7 +85,7 @@ gale::Context& gale::getContext() {
}
void gale::setContext(gale::Context* _context) {
etk::Map<std::thread::id, gale::Context*>& list = getContextList();
etk::Map<ethread::Thread::id, gale::Context*>& list = getContextList();
//GALE_ERROR("Set context : " << std::this_thread::get_id() << " context pointer : " << uint64_t(_context));
g_lockContextMap.lock();
if (_context != nullptr) {
@ -95,25 +95,25 @@ void gale::setContext(gale::Context* _context) {
g_lockContextMap.unlock();
}
void gale::contextRegisterThread(std::thread* _thread) {
void gale::contextRegisterThread(ethread::Thread* _thread) {
if (_thread == nullptr) {
return;
}
gale::Context* context = &gale::getContext();
etk::Map<std::thread::id, gale::Context*>& list = getContextList();
etk::Map<ethread::Thread::id, gale::Context*>& list = getContextList();
//GALE_ERROR("REGISTER Thread : " << _thread->get_id() << " context pointer : " << uint64_t(context));
g_lockContextMap.lock();
list.set(_thread->get_id(), context);
g_lockContextMap.unlock();
}
void gale::contextUnRegisterThread(std::thread* _thread) {
void gale::contextUnRegisterThread(ethread::Thread* _thread) {
if (_thread == nullptr) {
return;
}
etk::Map<std::thread::id, gale::Context*>& list = getContextList();
etk::Map<ethread::Thread::id, gale::Context*>& list = getContextList();
g_lockContextMap.lock();
etk::Map<std::thread::id, gale::Context*>::Iterator it = list.find(_thread->get_id());
etk::Map<ethread::Thread::id, gale::Context*>::Iterator it = list.find(_thread->get_id());
if (it != list.end()) {
list.erase(it);
}
@ -149,7 +149,7 @@ void gale::Context::processEvents() {
//GALE_DEBUG(" ******** Event");
while (m_msgSystem.count()>0) {
nbEvent++;
std::function<void(gale::Context& _context)> func;
etk::Function<void(gale::Context& _context)> func;
{
std::unique_lock<std::recursive_mutex> lock(m_mutex);
m_msgSystem.wait(func);
@ -375,7 +375,7 @@ void gale::Context::start2ndThreadProcessing() {
unLockContext();
}
void gale::Context::postAction(std::function<void(gale::Context& _context)> _action) {
void gale::Context::postAction(etk::Function<void(gale::Context& _context)> _action) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
m_msgSystem.post(_action);
}

View File

@ -75,7 +75,7 @@ namespace gale {
etk::FSNode m_simulationFile;
private:
echrono::Steady m_previousDisplayTime; // this is to limit framerate ... in case...
etk::Fifo<std::function<void(gale::Context& _context)> > m_msgSystem;
etk::Fifo<etk::Function<void(gale::Context& _context)> > m_msgSystem;
bool m_displayFps;
gale::context::Fps m_FpsSystemEvent;
gale::context::Fps m_FpsSystemContext;
@ -86,7 +86,7 @@ namespace gale {
*/
void processEvents();
public:
void postAction(std::function<void(gale::Context& _context)> _action);
void postAction(etk::Function<void(gale::Context& _context)> _action);
public:
virtual void setArchiveDir(int _mode, const char* _str, const char* _applName=nullptr);
@ -311,11 +311,11 @@ namespace gale {
* @brief When a new thread is created, it is needed to register it in the gale context interface to permit to get the context associated on it ...
* @param[in] _thread generic C++11 thread handle
*/
void contextRegisterThread(std::thread* _thread);
void contextRegisterThread(ethread::Thread* _thread);
/**
* @brief Remove an associated thread
* @param[in] _thread generic C++11 thread handle
*/
void contextUnRegisterThread(std::thread* _thread);
void contextUnRegisterThread(ethread::Thread* _thread);
}

View File

@ -23,7 +23,7 @@ namespace MacOs {
void setKeyboardMove(gale::key::Special& _keyboardMode, enum gale::key::keyboard _move, bool _isDown, bool _isAReapeateKey);
void stopRequested();
/*
void setRedrawCallback(const std::function<void()>& _func);
void setRedrawCallback(const etk::Function<void()>& _func);
*/
}

View File

@ -8,7 +8,7 @@
#include <gale/debug.hpp>
#include <gale/renderer/openGL/openGL.hpp>
#include <etk/stdTools.hpp>
#include <mutex>
#include <ethread/Mutex.hpp>
//#define DIRECT_MODE
#include <gale/renderer/openGL/openGL-include.hpp>
#include <ethread/tools.hpp>
@ -55,8 +55,8 @@ static void checkGlError(const char* _op, int32_t _localLine) {
* @note due ti the fact that the system can be called for multiple instance, for naw we just limit the acces to one process at a time.
* @return the main inteface Mutex
*/
static std::mutex& mutexOpenGl() {
static std::mutex s_drawMutex;
static ethread::Mutex& mutexOpenGl() {
static ethread::Mutex s_drawMutex;
return s_drawMutex;
}
@ -84,8 +84,8 @@ void gale::openGL::unLock() {
mutexOpenGl().unlock();
}
static etk::Vector<std::thread::id>& getContextList() {
static etk::Vector<std::thread::id> g_val;
static etk::Vector<ethread::Thread::id>& getContextList() {
static etk::Vector<ethread::Thread::id> g_val;
return g_val;
}

View File

@ -5,7 +5,7 @@
*/
#pragma once
#include <mutex>
#include <ethread/Mutex.hpp>
#include <ememory/memory.hpp>
#include <etk/types.hpp>
#include <gale/debug.hpp>