headless: Use direct x-thread wakeup instead of sleep/spin
This commit is contained in:
parent
9cfcb0bd92
commit
bd8897686a
@ -2,9 +2,14 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
|
#ifndef PLATFORM_WINDOWS
|
||||||
|
#include <signal.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <glibmm.h>
|
#include <glibmm.h>
|
||||||
|
|
||||||
#include "pbd/convert.h"
|
#include "pbd/convert.h"
|
||||||
|
#include "pbd/crossthread.h"
|
||||||
#include "pbd/failed_constructor.h"
|
#include "pbd/failed_constructor.h"
|
||||||
#include "pbd/error.h"
|
#include "pbd/error.h"
|
||||||
#include "pbd/debug.h"
|
#include "pbd/debug.h"
|
||||||
@ -22,18 +27,12 @@ using namespace std;
|
|||||||
using namespace ARDOUR;
|
using namespace ARDOUR;
|
||||||
using namespace PBD;
|
using namespace PBD;
|
||||||
|
|
||||||
#ifdef PLATFORM_WINDOWS
|
|
||||||
#include <windows.h>
|
|
||||||
#define sleep(X) Sleep((X) * 1000)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const char* localedir = LOCALEDIR;
|
static const char* localedir = LOCALEDIR;
|
||||||
|
|
||||||
static string backend_client_name;
|
static string backend_client_name;
|
||||||
static string backend_name = "JACK";
|
static string backend_name = "JACK";
|
||||||
static volatile bool run_headless = true;
|
static CrossThreadChannel xthread (true);
|
||||||
|
static TestReceiver test_receiver;
|
||||||
TestReceiver test_receiver;
|
|
||||||
|
|
||||||
/** @param dir Session directory.
|
/** @param dir Session directory.
|
||||||
* @param state Session state file, without .ardour suffix.
|
* @param state Session state file, without .ardour suffix.
|
||||||
@ -69,23 +68,30 @@ static void
|
|||||||
access_action (const std::string& action_group, const std::string& action_item)
|
access_action (const std::string& action_group, const std::string& action_item)
|
||||||
{
|
{
|
||||||
if (action_group == "Common" && action_item == "Quit") {
|
if (action_group == "Common" && action_item == "Quit") {
|
||||||
run_headless = false;
|
xthread.deliver ('x');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
engine_halted (const char* reason)
|
engine_halted (const char* reason)
|
||||||
{
|
{
|
||||||
cerr << "The audio backend has either been shutdown";
|
cerr << "The audio backend has been shutdown";
|
||||||
if (reason && strlen (reason) > 0) {
|
if (reason && strlen (reason) > 0) {
|
||||||
cerr << ": " << reason;
|
cerr << ": " << reason;
|
||||||
} else {
|
} else {
|
||||||
cerr << ".";
|
cerr << ".";
|
||||||
}
|
}
|
||||||
cerr << endl;
|
cerr << endl;
|
||||||
run_headless = false;
|
xthread.deliver ('x');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef PLATFORM_WINDOWS
|
||||||
|
static void wearedone (int) {
|
||||||
|
cerr << "caught signal - terminating." << endl;
|
||||||
|
xthread.deliver ('x');
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_version ()
|
print_version ()
|
||||||
{
|
{
|
||||||
@ -237,11 +243,15 @@ int main (int argc, char* argv[])
|
|||||||
BasicUI::AccessAction.connect_same_thread (con, boost::bind (&access_action, _1, _2));
|
BasicUI::AccessAction.connect_same_thread (con, boost::bind (&access_action, _1, _2));
|
||||||
AudioEngine::instance()->Halted.connect_same_thread (con, boost::bind (&engine_halted, _1));
|
AudioEngine::instance()->Halted.connect_same_thread (con, boost::bind (&engine_halted, _1));
|
||||||
|
|
||||||
|
#ifndef PLATFORM_WINDOWS
|
||||||
|
signal(SIGINT, wearedone);
|
||||||
|
signal(SIGTERM, wearedone);
|
||||||
|
#endif
|
||||||
|
|
||||||
s->request_transport_speed (1.0);
|
s->request_transport_speed (1.0);
|
||||||
|
|
||||||
while (run_headless) {
|
char msg;
|
||||||
Glib::usleep (500000);
|
do {} while (0 == xthread.receive (msg, true));
|
||||||
}
|
|
||||||
|
|
||||||
AudioEngine::instance()->remove_session ();
|
AudioEngine::instance()->remove_session ();
|
||||||
delete s;
|
delete s;
|
||||||
|
Loading…
Reference in New Issue
Block a user