Skip to content

Commit

Permalink
* Do a better job of terminating on terminate(); avoid zombies; increase
Browse files Browse the repository at this point in the history
  timeout on startup
  • Loading branch information
cannam committed Oct 25, 2004
1 parent 07c981a commit 40dd370
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
15 changes: 12 additions & 3 deletions dssi-vst-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ RemoteVSTServer::reset()
void
RemoteVSTServer::terminate()
{
cerr << "RemoteVSTServer::terminate: setting exiting flag" << endl;
exiting = true;
}

Expand Down Expand Up @@ -701,6 +702,7 @@ AudioThreadMain(LPVOID parameter)
}

if (exiting) {
cerr << "Remote VST plugin audio thread: returning" << endl;
param.sched_priority = 0;
(void)sched_setscheduler(0, SCHED_OTHER, &param);
return 0;
Expand Down Expand Up @@ -977,9 +979,16 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdline, int cmdshow)

MSG msg;
exiting = false;
while (GetMessage(&msg, 0, 0, 0)) {
DispatchMessage(&msg);
if (exiting) break;
while (!exiting) {
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
DispatchMessage(&msg);
} else {
if (tryGui) {
usleep(10000);
} else {
sleep(1);
}
}
}

if (debugLevel > 0) {
Expand Down
2 changes: 0 additions & 2 deletions dssi-vst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ DSSIVSTPluginInstance::runSynth(unsigned long sampleCount,

if (index >= MIDI_BUFFER_SIZE - 4) break;

std::cout << "DSSIVSTPluginInstance::runSynth: event at offset " << ev->time.tick << std::endl;

m_frameOffsetsBuffer[i] = ev->time.tick;

long count = snd_midi_event_decode(m_alsaDecoder,
Expand Down
3 changes: 2 additions & 1 deletion remotepluginclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ RemotePluginClient::syncStartup()
// for this and the process fd anyway.

bool connected = false;
int timeout = 15;

for (int attempt = 0; attempt < 6; ++attempt) {
for (int attempt = 0; attempt < timeout; ++attempt) {

if ((m_controlRequestFd =
open(m_controlRequestFileName, O_WRONLY | O_NONBLOCK)) >= 0) {
Expand Down
16 changes: 14 additions & 2 deletions remotevstclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <iostream>
#include <dirent.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#include "rdwrops.h"
#include "paths.h"
Expand Down Expand Up @@ -89,6 +91,10 @@ RemoteVSTClient::RemoteVSTClient(std::string dllName, bool showGUI) :

RemoteVSTClient::~RemoteVSTClient()
{
for (int i = 0; i < 3; ++i) {
if (waitpid(-1, NULL, WNOHANG)) break;
sleep(1);
}
}

void
Expand Down Expand Up @@ -216,8 +222,9 @@ RemoteVSTClient::queryPlugins(std::vector<PluginRecord> &plugins)
pfd.fd = fd;
pfd.events = POLLIN;
int sec;
int timeout = 15;

for (sec = 0; sec < 6; ++sec) {
for (sec = 0; sec < timeout; ++sec) {

int rv = poll(&pfd, 1, 1000);

Expand All @@ -236,7 +243,7 @@ RemoteVSTClient::queryPlugins(std::vector<PluginRecord> &plugins)
}
}

if (sec >= 6) {
if (sec >= timeout) {
close(fd);
unlink(fifoFile);
throw ((std::string)"Plugin scanner timed out on startup.");
Expand Down Expand Up @@ -308,5 +315,10 @@ RemoteVSTClient::queryPlugins(std::vector<PluginRecord> &plugins)

close(fd);
unlink(fifoFile);

for (int i = 0; i < 3; ++i) {
if (waitpid(-1, NULL, WNOHANG)) break;
sleep(1);
}
}

0 comments on commit 40dd370

Please sign in to comment.