#pragma comment(lib, "shell32.lib" )
#pragma comment(lib,"expat.lib")
#pragma comment(lib,"sqlite3.lib")
-#pragma comment(lib,"sqliteManager.lib")
#pragma comment(lib,"shareCookie.lib")
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"JSONParser.lib")
COpenJtalkCore::COpenJtalkCore():
manageFlag(false){
- this->synthesisThreadHandle = (HANDLE)_beginthreadex(NULL,0,COpenJtalkCore::SynthesisThreadFunction,this,0,NULL);
+ _beginthread(COpenJtalkCore::SynthesisThreadFunction,0,this);
this->synthesisEventObject = ::CreateEvent(NULL,false,false,NULL);
this->endEventObject = ::CreateEvent(NULL,true,false,NULL);
COpenJtalkCore::~COpenJtalkCore(){
if(this->manageFlag == true)this->Clear();
- ::SetEvent(this->endEventObject);
+
int errcount = 0;
- while(::WaitForSingleObject(this->synthesisThreadHandle,3000) == WAIT_TIMEOUT){
- errcount++;
- if(errcount > 3){
-
- _exit(-1);
- }
+ ::SetEvent(this->endEventObject);
- }
- ::CloseHandle(this->synthesisThreadHandle);
::CloseHandle(this->synthesisEventObject);
::CloseHandle(this->endEventObject);
this->synthesisQueueCS.Lock();
- if(this->synthesisQueue.size() > 3)this->synthesisQueue.pop();
+ if(this->synthesisQueue.size() > 3)this->synthesisQueue.pop_back();
- this->synthesisQueue.push(txt);
+ this->synthesisQueue.push_front(txt);
this->synthesisQueueCS.Unlock();
+ ::SetEvent(this->synthesisEventObject);
}
void COpenJtalkCore::Clear(){
this->manageFlag = false;
}
-unsigned WINAPI COpenJtalkCore::SynthesisThreadFunction(void *userData){
+void COpenJtalkCore::SynthesisThreadFunction(void *userData){
auto &self = *(COpenJtalkCore*)userData;
dwRslt = ::WaitForMultipleObjects(sizeof(eventList) / sizeof(eventList[0]),eventList,false,INFINITE);
if(dwRslt- WAIT_OBJECT_0 == 1)break;
+ else if(dwRslt- WAIT_OBJECT_0 == 0){
+ CString synthesisString;
+ SynthesisQueue synthesisQueueCopy;
+ self.synthesisQueueCS.Lock();
- CString synthesisString;
-
- self.synthesisQueueCS.Lock();
+ synthesisQueueCopy = self.synthesisQueue;
+ self.synthesisQueue.clear();
+
- synthesisString = self.synthesisQueue.back();
- self.synthesisQueue.pop();
+ self.synthesisQueueCS.Unlock();
- self.synthesisQueueCS.Unlock();
+ auto rbegin = synthesisQueueCopy.rbegin();
+ auto rend = synthesisQueueCopy.rend();
- self.Synthesis((const TChar_P)(const wchar_t*)synthesisString);
+ for(;rbegin != rend;++rbegin){
+ self.Synthesis((const TChar_P)(const wchar_t*)*rbegin);
+ }
+ }
} while(true);
- _endthreadex(0);
+ _endthread();
- return 0;
+ return ;
}
}
class COpenJtalkCore:public ISpeaker{
private:
+ typedef std::deque<CString> SynthesisQueue;
OpenJTalk openJtalk_internal; //\93à\95\94\83I\83u\83W\83F\83N\83g
bool manageFlag; //\8aÇ\97\9d\83t\83\89\83O
CComAutoCriticalSection synthesisQueueCS;
- std::queue<CString> synthesisQueue;
- HANDLE synthesisThreadHandle; //\93Ç\82Ý\8fã\82°\83X\83\8c\83b\83h\83n\83\93\83h\83\8b
+ SynthesisQueue synthesisQueue;
HANDLE synthesisEventObject;
HANDLE endEventObject;
protected:
///
///\94ñ\93¯\8aú\93Ç\82Ý\8fã\82°\97p\82Ì\83X\83\8c\83b\83h\8aÖ\90\94
///
- static unsigned WINAPI SynthesisThreadFunction(void *userData);
+ static void SynthesisThreadFunction(void *userData);
};