[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 <unistd.h>
void audio::ess::LoadedFile::threadCallback() {
//etk::thread::setName("audio-ess decoder");
//decode();
#if defined(__TARGET_OS__Android)
void* audio::ess::LoadedFile::threadCallback(void* _userData) {
audio::ess::LoadedFile* threadHandle = static_cast<audio::ess::LoadedFile*>(_userData);
if (threadHandle != nullptr) {
threadHandle->threadCall();
}
static void threadCallback222() {
//etk::thread::setName("audio-ess decoder");
//decode();
return nullptr;
}
#endif
void audio::ess::LoadedFile::threadCall() {
decode();
}
void audio::ess::LoadedFile::decode() {
@ -32,7 +37,9 @@ void audio::ess::LoadedFile::decode() {
}
audio::ess::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanRequested) :
#if !defined(__TARGET_OS__Android)
m_thread(nullptr),
#endif
m_file(_fileName),
m_nbSamples(0),
m_nbChanRequested(_nbChanRequested),
@ -45,18 +52,18 @@ audio::ess::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanR
} else if (etk::end_with(tmpName, ".ogg") == true) {
#if 1
EWOLSA_INFO("create thread");
//m_thread = std::make_shared<std::thread>(&audio::ess::LoadedFile::threadCallback, this);
//m_thread = std::make_shared<std::thread>(&threadCallback222);
static std::thread plop(&threadCallback222);
plop.detach();
EWOLSA_INFO("done 1");
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
EWOLSA_INFO("done 2");
#if defined(__TARGET_OS__Android)
pthread_create(&m_thread, nullptr, &audio::ess::LoadedFile::threadCallback, this);
#else
m_thread = std11::make_shared<std11::thread>(&audio::ess::LoadedFile::threadCall, this);
if (m_thread == nullptr) {
GALE_ERROR("Can not create thread ...");
return;
}
#endif
std::this_thread::sleep_for(std::chrono::milliseconds(1));
#else
EWOLSA_DEBUG("done 1");
decode();
EWOLSA_DEBUG("done 2");
#endif
} else {
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() {
#if defined(__TARGET_OS__Android)
void* ret = nullptr;
int val = pthread_join(m_thread, &ret);
#else
if (m_thread != nullptr) {
//m_thread->join();
m_thread->join();
}
//m_thread.reset();
m_thread.reset();
#endif
}

View File

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