Browse Source

Use posix_spawn to launch macOS bridges

tags/v2.3.1
falkTX 3 years ago
parent
commit
6a1c518eb4
4 changed files with 67 additions and 17 deletions
  1. +10
    -9
      source/backend/plugin/CarlaPluginBridge.cpp
  2. +3
    -0
      source/discovery/carla-discovery.cpp
  3. +45
    -6
      source/modules/water/threads/ChildProcess.cpp
  4. +9
    -2
      source/modules/water/threads/ChildProcess.h

+ 10
- 9
source/backend/plugin/CarlaPluginBridge.cpp View File

@@ -181,15 +181,16 @@ protected:
}
#endif

#ifdef CARLA_OS_MAC
// setup binary arch
if (fBinaryArchName.isNotEmpty())
{
arguments.add("arch");
arguments.add("-arch");
arguments.add(fBinaryArchName);
}
ChildProcess::Type childType;
#ifdef CARLA_OS_MAC
if (fBinaryArchName == "arm64")
childType = ChildProcess::TypeARM;
else if (fBinaryArchName == "x86_64")
childType = ChildProcess::TypeIntel;
else
#endif
childType = ChildProcess::TypeAny;

// bridge binary
arguments.add(fBridgeBinary);
@@ -327,13 +328,13 @@ protected:
{
const File oldFolder(File::getCurrentWorkingDirectory());
projFolder.setAsCurrentWorkingDirectory();
started = fProcess->start(arguments);
started = fProcess->start(arguments, childType);
oldFolder.setAsCurrentWorkingDirectory();
}
else
#endif
{
started = fProcess->start(arguments);
started = fProcess->start(arguments, childType);
}
}



+ 3
- 0
source/discovery/carla-discovery.cpp View File

@@ -65,6 +65,9 @@
# undef Point
# include "CarlaMacUtils.cpp"
# include <spawn.h>
# if defined(USING_JUCE) && defined(__aarch64__)
# include <spawn.h>
# endif
#endif

#ifdef CARLA_OS_WIN


+ 45
- 6
source/modules/water/threads/ChildProcess.cpp View File

@@ -27,6 +27,11 @@
#include "../files/File.h"
#include "../misc/Time.h"
#ifdef CARLA_OS_MAC
# include <crt_externs.h>
# include <spawn.h>
#endif
#ifndef CARLA_OS_WIN
# include <signal.h>
# include <sys/wait.h>
@@ -118,7 +123,7 @@ private:
class ChildProcess::ActiveProcess
{
public:
ActiveProcess (const StringArray& arguments)
ActiveProcess (const StringArray& arguments, const Type type)
: childPID (0)
{
String exe (arguments[0].unquoted());
@@ -135,12 +140,40 @@ public:
argv.add (nullptr);
#ifdef CARLA_OS_MAC
cpu_type_t pref;
pid_t result = -1;
switch (type)
{
case TypeARM:
pref = CPU_TYPE_ARM64;
break;
case TypeIntel:
pref = CPU_TYPE_X86_64;
break;
default:
pref = CPU_TYPE_ANY;
break;
}
posix_spawnattr_t attr;
posix_spawnattr_init(&attr);
// posix_spawnattr_setflags(&attr, POSIX_SPAWN_USEVFORK);
CARLA_SAFE_ASSERT_RETURN(posix_spawnattr_setbinpref_np(&attr, 1, &pref, nullptr) == 0,);
char*** const environptr = _NSGetEnviron();
CARLA_SAFE_ASSERT_RETURN(posix_spawn(&result, exe.toRawUTF8(), nullptr, &attr,
argv.getRawDataPointer(), environptr != nullptr ? *environptr : nullptr) == 0,);
posix_spawnattr_destroy(&attr);
#else
const pid_t result = vfork();
#endif
if (result < 0)
{
// error
}
#ifndef CARLA_OS_MAC
else if (result == 0)
{
// child process
@@ -149,11 +182,17 @@ public:
if (execvp (exe.toRawUTF8(), argv.getRawDataPointer()))
_exit (-1);
}
#endif
else
{
// we're the parent process..
childPID = result;
}
#ifndef CARLA_OS_MAC
// unused
(void)pref;
#endif
}
~ActiveProcess()
@@ -285,7 +324,7 @@ uint32 ChildProcess::getPID() const noexcept
//=====================================================================================================================
#ifdef CARLA_OS_WIN
bool ChildProcess::start (const String& command)
bool ChildProcess::start (const String& command, Type)
{
activeProcess = new ActiveProcess (command);
@@ -317,17 +356,17 @@ bool ChildProcess::start (const StringArray& args)
return start (escaped.trim());
}
#else
bool ChildProcess::start (const String& command)
bool ChildProcess::start (const String& command, const Type type)
{
return start (StringArray::fromTokens (command, true));
return start (StringArray::fromTokens (command, true), type);
}
bool ChildProcess::start (const StringArray& args)
bool ChildProcess::start (const StringArray& args, const Type type)
{
if (args.size() == 0)
return false;
activeProcess = new ActiveProcess (args);
activeProcess = new ActiveProcess (args, type);
if (activeProcess->childPID == 0)
activeProcess = nullptr;


+ 9
- 2
source/modules/water/threads/ChildProcess.h View File

@@ -43,6 +43,13 @@ class ChildProcess
{
public:
//==============================================================================
/** Child process type, only used in macOS. */
enum Type {
TypeAny,
TypeARM,
TypeIntel
};
/** Creates a process object.
To actually launch the process, use start().
*/
@@ -62,7 +69,7 @@ public:
The streamFlags is a combinations of values to indicate which of the child's output
streams should be read and returned by readProcessOutput().
*/
bool start (const String& command);
bool start (const String& command, Type type = TypeAny);
/** Attempts to launch a child process command.
@@ -73,7 +80,7 @@ public:
The streamFlags is a combinations of values to indicate which of the child's output
streams should be read and returned by readProcessOutput().
*/
bool start (const StringArray& arguments);
bool start (const StringArray& arguments, Type type = TypeAny);
/** Returns true if the child process is alive. */
bool isRunning() const;


Loading…
Cancel
Save