|
|
@@ -68,55 +68,98 @@ JackWinThread::~JackWinThread() |
|
|
CloseHandle(fEvent); |
|
|
CloseHandle(fEvent); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int JackWinThread::Start() |
|
|
|
|
|
{ |
|
|
|
|
|
fRunning = true; |
|
|
|
|
|
StartSync(): |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int JackWinThread::StartSync() |
|
|
|
|
|
{ |
|
|
|
|
|
DWORD id; |
|
|
|
|
|
|
|
|
|
|
|
if (fRealTime) { |
|
|
|
|
|
|
|
|
|
|
|
JackLog("Create RT thread\n"); |
|
|
|
|
|
fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id); |
|
|
|
|
|
|
|
|
|
|
|
if (fThread == NULL) { |
|
|
|
|
|
jack_error("Cannot create thread error = %d", GetLastError()); |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (WaitForSingleObject(fEvent, 3000) != WAIT_OBJECT_0) { // wait 3 sec |
|
|
|
|
|
jack_error("Thread has not started"); |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!SetThreadPriority(fThread, THREAD_PRIORITY_TIME_CRITICAL)) { |
|
|
|
|
|
jack_error("Cannot set priority class = %d", GetLastError()); |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
JackLog("Create non RT thread\n"); |
|
|
|
|
|
fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id); |
|
|
|
|
|
|
|
|
|
|
|
if (fThread == NULL) { |
|
|
|
|
|
jack_error("Cannot create thread error = %d", GetLastError()); |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (WaitForSingleObject(fEvent, 3000) != WAIT_OBJECT_0) { // wait 3 sec |
|
|
|
|
|
jack_error("Thread has not started"); |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
int JackWinThread::Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
DWORD id;
|
|
|
|
|
|
|
|
|
|
|
|
fEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
|
|
|
|
if (fEvent == NULL) {
|
|
|
|
|
|
jack_error("Cannot create event error = %d", GetLastError());
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fRunning = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (fRealTime) {
|
|
|
|
|
|
|
|
|
|
|
|
JackLog("Create RT thread\n");
|
|
|
|
|
|
fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id);
|
|
|
|
|
|
|
|
|
|
|
|
if (fThread == NULL) {
|
|
|
|
|
|
jack_error("Cannot create thread error = %d", GetLastError());
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!SetThreadPriority(fThread, THREAD_PRIORITY_TIME_CRITICAL)) {
|
|
|
|
|
|
jack_error("Cannot set priority class = %d", GetLastError());
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
JackLog("Create non RT thread\n");
|
|
|
|
|
|
fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id);
|
|
|
|
|
|
|
|
|
|
|
|
if (fThread == NULL) {
|
|
|
|
|
|
jack_error("Cannot create thread error = %d", GetLastError());
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int JackWinThread::StartSync()
|
|
|
|
|
|
{
|
|
|
|
|
|
DWORD id;
|
|
|
|
|
|
|
|
|
|
|
|
fEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
|
|
|
|
if (fEvent == NULL) {
|
|
|
|
|
|
jack_error("Cannot create event error = %d", GetLastError());
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (fRealTime) {
|
|
|
|
|
|
|
|
|
|
|
|
JackLog("Create RT thread\n");
|
|
|
|
|
|
fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id);
|
|
|
|
|
|
|
|
|
|
|
|
if (fThread == NULL) {
|
|
|
|
|
|
jack_error("Cannot create thread error = %d", GetLastError());
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (WaitForSingleObject(fEvent, 3000) != WAIT_OBJECT_0) { // wait 3 sec
|
|
|
|
|
|
jack_error("Thread has not started");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!SetThreadPriority(fThread, THREAD_PRIORITY_TIME_CRITICAL)) {
|
|
|
|
|
|
jack_error("Cannot set priority class = %d", GetLastError());
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
JackLog("Create non RT thread\n");
|
|
|
|
|
|
fThread = CreateThread(NULL, 0, ThreadHandler, (void*)this, 0, &id);
|
|
|
|
|
|
|
|
|
|
|
|
if (fThread == NULL) {
|
|
|
|
|
|
jack_error("Cannot create thread error = %d", GetLastError());
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (WaitForSingleObject(fEvent, 3000) != WAIT_OBJECT_0) { // wait 3 sec
|
|
|
|
|
|
jack_error("Thread has not started");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// voir http://www.microsoft.com/belux/msdn/nl/community/columns/ldoc/multithread1.mspx |
|
|
// voir http://www.microsoft.com/belux/msdn/nl/community/columns/ldoc/multithread1.mspx |
|
|
|