[DEBUG] correct android multithreading

This commit is contained in:
Edouard DUPIN 2015-09-28 23:23:56 +02:00
parent 9d4001fe03
commit f580ec38e3
2 changed files with 44 additions and 25 deletions

View File

@ -15,13 +15,18 @@
#include <audio/ess/decOgg.h> #include <audio/ess/decOgg.h>
#include <unistd.h> #include <unistd.h>
void audio::ess::LoadedFile::threadCallback() { #if defined(__TARGET_OS__Android)
//etk::thread::setName("audio-ess decoder"); void* audio::ess::LoadedFile::threadCallback(void* _userData) {
//decode(); audio::ess::LoadedFile* threadHandle = static_cast<audio::ess::LoadedFile*>(_userData);
} if (threadHandle != nullptr) {
static void threadCallback222() { threadHandle->threadCall();
//etk::thread::setName("audio-ess decoder"); }
//decode(); return nullptr;
}
#endif
void audio::ess::LoadedFile::threadCall() {
decode();
} }
void audio::ess::LoadedFile::decode() { void audio::ess::LoadedFile::decode() {
@ -32,11 +37,13 @@ void audio::ess::LoadedFile::decode() {
} }
audio::ess::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanRequested) : audio::ess::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanRequested) :
m_thread(nullptr), #if !defined(__TARGET_OS__Android)
m_thread(nullptr),
#endif
m_file(_fileName), m_file(_fileName),
m_nbSamples(0), m_nbSamples(0),
m_nbChanRequested(_nbChanRequested), m_nbChanRequested(_nbChanRequested),
m_requestedTime(1){ m_requestedTime(1) {
std::string tmpName = etk::tolower(m_file); std::string tmpName = etk::tolower(m_file);
// select the corect Loader : // select the corect Loader :
if (etk::end_with(tmpName, ".wav") == true) { if (etk::end_with(tmpName, ".wav") == true) {
@ -45,18 +52,18 @@ audio::ess::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanR
} else if (etk::end_with(tmpName, ".ogg") == true) { } else if (etk::end_with(tmpName, ".ogg") == true) {
#if 1 #if 1
EWOLSA_INFO("create thread"); EWOLSA_INFO("create thread");
#if defined(__TARGET_OS__Android)
//m_thread = std::make_shared<std::thread>(&audio::ess::LoadedFile::threadCallback, this); pthread_create(&m_thread, nullptr, &audio::ess::LoadedFile::threadCallback, this);
//m_thread = std::make_shared<std::thread>(&threadCallback222); #else
static std::thread plop(&threadCallback222); m_thread = std11::make_shared<std11::thread>(&audio::ess::LoadedFile::threadCall, this);
plop.detach(); if (m_thread == nullptr) {
EWOLSA_INFO("done 1"); GALE_ERROR("Can not create thread ...");
std::this_thread::sleep_for(std::chrono::milliseconds(10000)); return;
EWOLSA_INFO("done 2"); }
#endif
std::this_thread::sleep_for(std::chrono::milliseconds(1));
#else #else
EWOLSA_DEBUG("done 1");
decode(); decode();
EWOLSA_DEBUG("done 2");
#endif #endif
} else { } else {
EWOLSA_ERROR("Extention not managed '" << m_file << "' Sopported extention : .wav / .ogg"); EWOLSA_ERROR("Extention not managed '" << m_file << "' Sopported extention : .wav / .ogg");
@ -65,10 +72,15 @@ audio::ess::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanR
} }
audio::ess::LoadedFile::~LoadedFile() { audio::ess::LoadedFile::~LoadedFile() {
if (m_thread != nullptr) { #if defined(__TARGET_OS__Android)
//m_thread->join(); void* ret = nullptr;
} int val = pthread_join(m_thread, &ret);
//m_thread.reset(); #else
if (m_thread != nullptr) {
m_thread->join();
}
m_thread.reset();
#endif
} }

View File

@ -23,7 +23,11 @@ namespace audio {
return m_uid; return m_uid;
} }
private: private:
std::shared_ptr<std::thread> m_thread; #if defined(__TARGET_OS__Android)
pthread_t m_thread;
#else
std11::shared_ptr<std11::thread> m_thread;
#endif
public: public:
LoadedFile(const std::string& _fileName, int8_t _nbChanRequested=1); LoadedFile(const std::string& _fileName, int8_t _nbChanRequested=1);
~LoadedFile(); ~LoadedFile();
@ -38,7 +42,10 @@ namespace audio {
}; };
void decode(); void decode();
private: private:
void threadCallback(); #if defined(__TARGET_OS__Android)
static void* threadCallback(void* _userData);
#endif
void threadCall();
}; };
} }
} }