#include <condition_variable>
#include <string>
#include <atomic>
+#include <Eina.h>
#include "WorkingDir.h"
namespace Msg
static void *safeCallOnFileReady(void *data);
static void *safeCallOnFileFails(void *data);
+ static void *on_routine_cb(void *data, Eina_Thread t);
void onRoutine();
+
private:
IAttachmentHandlerListener *m_pListener;
WorkingDirRef m_WorkingDir;
std::string m_CurrentFile;
- std::thread m_Thread;
+ Eina_Thread m_Thread;
+ bool m_ThreadCreated;
long long m_CurrentFreeSpace;
mutable std::mutex m_Mutex;
std::condition_variable m_Condition;
AttachmentHandler::AttachmentHandler(WorkingDirRef workingDir)
: m_pListener(nullptr)
, m_WorkingDir(workingDir)
+ , m_Thread()
+ , m_ThreadCreated(false)
, m_NeedTerminate(false)
{
+
}
AttachmentHandler::~AttachmentHandler()
{
m_NeedTerminate = true;
m_Condition.notify_one();
- if (m_Thread.joinable())
- m_Thread.join();
+
+ if (m_ThreadCreated)
+ eina_thread_join(m_Thread);
+ m_ThreadCreated = false;
}
void AttachmentHandler::processFile(const std::string &file)
{
- if (!m_Thread.joinable())
- m_Thread = std::thread(&AttachmentHandler::onRoutine, this);
+ if (!m_ThreadCreated)
+ {
+ if (eina_thread_create(&m_Thread, EINA_THREAD_NORMAL, 0, on_routine_cb, this))
+ {
+ m_ThreadCreated = true;
+ } else {
+ if(m_pListener)
+ m_pListener->onFileFails();
+ }
+ }
+
+ // TODO: revert this code (eina_thread), when C++11 will work on Emulator, JIRA: SDKRM-1187
+ /*if (!m_Thread.joinable())
+ m_Thread = std::thread(&AttachmentHandler::onRoutine, this);*/
std::unique_lock<std::mutex> _lock(m_Mutex);
m_Task.push(file);
return nullptr;
}
+void *AttachmentHandler::on_routine_cb(void *data, Eina_Thread t)
+{
+ ((AttachmentHandler*)data)->onRoutine();
+ return nullptr;
+}
+
void AttachmentHandler::onRoutine()
{
while (!m_NeedTerminate)