summaryrefslogtreecommitdiff
path: root/headless
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2019-07-04 22:02:52 +0200
committerRobin Gareus <robin@gareus.org>2019-07-04 22:02:52 +0200
commitbd8897686a32e5f2c921219ce319aaecab11cb88 (patch)
tree1879377a0245e0e36685ba397b84a4aac7a8da0c /headless
parent9cfcb0bd9285f0ee05d8bce413f1feffc5fddcdb (diff)
headless: Use direct x-thread wakeup instead of sleep/spin
Diffstat (limited to 'headless')
-rw-r--r--headless/load_session.cc38
1 files changed, 24 insertions, 14 deletions
diff --git a/headless/load_session.cc b/headless/load_session.cc
index 1a55971917..47fd5151b1 100644
--- a/headless/load_session.cc
+++ b/headless/load_session.cc
@@ -2,9 +2,14 @@
#include <cstdlib>
#include <getopt.h>
+#ifndef PLATFORM_WINDOWS
+#include <signal.h>
+#endif
+
#include <glibmm.h>
#include "pbd/convert.h"
+#include "pbd/crossthread.h"
#include "pbd/failed_constructor.h"
#include "pbd/error.h"
#include "pbd/debug.h"
@@ -22,18 +27,12 @@ using namespace std;
using namespace ARDOUR;
using namespace PBD;
-#ifdef PLATFORM_WINDOWS
-#include <windows.h>
-#define sleep(X) Sleep((X) * 1000)
-#endif
-
static const char* localedir = LOCALEDIR;
static string backend_client_name;
static string backend_name = "JACK";
-static volatile bool run_headless = true;
-
-TestReceiver test_receiver;
+static CrossThreadChannel xthread (true);
+static TestReceiver test_receiver;
/** @param dir Session directory.
* @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)
{
if (action_group == "Common" && action_item == "Quit") {
- run_headless = false;
+ xthread.deliver ('x');
}
}
static void
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) {
cerr << ": " << reason;
} else {
cerr << ".";
}
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
print_version ()
{
@@ -237,11 +243,15 @@ int main (int argc, char* argv[])
BasicUI::AccessAction.connect_same_thread (con, boost::bind (&access_action, _1, _2));
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);
- while (run_headless) {
- Glib::usleep (500000);
- }
+ char msg;
+ do {} while (0 == xthread.receive (msg, true));
AudioEngine::instance()->remove_session ();
delete s;