Browse Source

Make thread termination more elegant.

tags/1.9.8
Devin Anderson 14 years ago
parent
commit
8e4ee25c7f
2 changed files with 39 additions and 16 deletions
  1. +36
    -16
      windows/winmme/JackWinMMEOutputPort.cpp
  2. +3
    -0
      windows/winmme/JackWinMMEOutputPort.h

+ 36
- 16
windows/winmme/JackWinMMEOutputPort.cpp View File

@@ -247,10 +247,7 @@ JackWinMMEOutputPort::HandleMessage(UINT message, DWORD_PTR param1,
jack_info("JackWinMMEOutputPort::HandleMessage - MIDI device closed."); jack_info("JackWinMMEOutputPort::HandleMessage - MIDI device closed.");
break; break;
case MOM_DONE: case MOM_DONE:
if (! ReleaseSemaphore(sysex_semaphore, 1, NULL)) {
WriteOSError("JackWinMMEOutputPort::HandleMessage",
"ReleaseSemaphore");
}
Signal(sysex_semaphore);
break; break;
case MOM_OPEN: case MOM_OPEN:
jack_info("JackWinMMEOutputPort::HandleMessage - MIDI device opened."); jack_info("JackWinMMEOutputPort::HandleMessage - MIDI device opened.");
@@ -294,14 +291,21 @@ JackWinMMEOutputPort::ProcessJack(JackMidiBuffer *port_buffer,
event->size); event->size);
break; break;
default: default:
if (! ReleaseSemaphore(thread_queue_semaphore, 1, NULL)) {
WriteOSError("JackWinMMEOutputPort::ProcessJack",
"ReleaseSemaphore");
}
Signal(thread_queue_semaphore);
} }
} }
} }


bool
JackWinMMEOutputPort::Signal(Handle semaphore)
{
bool result = (bool) ReleaseSemaphore(semaphore, 1, NULL);
if (! result) {
WriteOSError("JackWinMMEOutputPort::Signal", "ReleaseSemaphore");
}
return result;
}

bool bool
JackWinMMEOutputPort::Start() JackWinMMEOutputPort::Start()
{ {
@@ -319,15 +323,31 @@ JackWinMMEOutputPort::Start()
bool bool
JackWinMMEOutputPort::Stop() JackWinMMEOutputPort::Stop()
{ {
bool result = thread->GetStatus() == JackThread::kIdle;
if (! result) {
result = ! thread->Kill();
if (! result) {
jack_error("JackWinMMEOutputPort::Stop - failed to stop MIDI "
"processing thread.");
}

jack_info("JackWinMMEOutputPort::Stop - stopping MIDI output port "
"processing thread.");

int result;
const char *verb;
switch (thread->GetStatus()) {
case JackThread::kIniting:
case JackThread::kStarting:
result = thread->Kill();
verb = "kill";
break;
case JackThread::kRunning:
Signal(thread_queue_semaphore);
result = thread->Stop();
verb = "stop";
break;
default:
return true;
} }
return result;
if (result) {
jack_error("JackWinMMEOutputPort::Stop - could not %s MIDI processing "
"thread.", verb);
}
return ! result;
} }


bool bool


+ 3
- 0
windows/winmme/JackWinMMEOutputPort.h View File

@@ -46,6 +46,9 @@ namespace Jack {
void void
HandleMessage(UINT message, DWORD_PTR param1, DWORD_PTR param2); HandleMessage(UINT message, DWORD_PTR param1, DWORD_PTR param2);


bool
Signal(Handle semaphore);

bool bool
Wait(Handle semaphore); Wait(Handle semaphore);




Loading…
Cancel
Save