Browse Source

Cleanup; Only use F_SETPIPE_SZ on Linux

tags/1.9.8
falkTX 8 years ago
parent
commit
56fa7b3986
4 changed files with 18 additions and 58 deletions
  1. +1
    -1
      source/backend/CarlaUtils.cpp
  2. +1
    -1
      source/bridges-ui/CarlaBridgeUI.cpp
  3. +0
    -1
      source/includes/CarlaDefines.h
  4. +16
    -55
      source/utils/CarlaPipeUtils.cpp

+ 1
- 1
source/backend/CarlaUtils.cpp View File

@@ -766,7 +766,7 @@ int* carla_x11_get_window_pos(uintptr_t winId)


#include "CarlaPipeUtils.cpp" #include "CarlaPipeUtils.cpp"


#if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
#ifndef DEBUG
# include "water/misc/Time.cpp" # include "water/misc/Time.cpp"
#endif #endif




+ 1
- 1
source/bridges-ui/CarlaBridgeUI.cpp View File

@@ -357,7 +357,7 @@ CARLA_BRIDGE_END_NAMESPACE


#include "CarlaPipeUtils.cpp" #include "CarlaPipeUtils.cpp"


#if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
#ifndef DEBUG
# include "water/misc/Time.cpp" # include "water/misc/Time.cpp"
#endif #endif




+ 0
- 1
source/includes/CarlaDefines.h View File

@@ -110,7 +110,6 @@
# define P_SIZE "%u" # define P_SIZE "%u"
# define P_SSIZE "%i" # define P_SSIZE "%i"
#elif defined(CARLA_OS_MAC) #elif defined(CARLA_OS_MAC)
// FIXME adjust for 32bit bridges
# define P_INT64 "%lli" # define P_INT64 "%lli"
# define P_UINT64 "%llu" # define P_UINT64 "%llu"
# define P_INTPTR "%li" # define P_INTPTR "%li"


+ 16
- 55
source/utils/CarlaPipeUtils.cpp View File

@@ -34,12 +34,8 @@
#include <clocale> #include <clocale>
#include <fcntl.h> #include <fcntl.h>


#if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
# include "water/misc/Time.h"
# include "water/text/String.h"
#else
# include <ctime>
#endif
#include "water/misc/Time.h"
#include "water/text/String.h"


#ifndef CARLA_OS_WIN #ifndef CARLA_OS_WIN
# include <cerrno> # include <cerrno>
@@ -50,16 +46,14 @@
# endif # endif
#endif #endif


#ifndef F_SETPIPE_SZ
# define F_SETPIPE_SZ 1031
#endif

#ifdef CARLA_OS_WIN #ifdef CARLA_OS_WIN
# define INVALID_PIPE_VALUE INVALID_HANDLE_VALUE # define INVALID_PIPE_VALUE INVALID_HANDLE_VALUE
#else #else
# define INVALID_PIPE_VALUE -1 # define INVALID_PIPE_VALUE -1
#endif #endif


using water::Time;

#ifdef CARLA_OS_WIN #ifdef CARLA_OS_WIN
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// win32 stuff // win32 stuff
@@ -91,41 +85,6 @@ ssize_t WriteFileWin32(const HANDLE pipeh, const void* const buf, const std::siz
} }
#endif // CARLA_OS_WIN #endif // CARLA_OS_WIN


// -----------------------------------------------------------------------
// getMillisecondCounter

#if ! (defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN))
static uint32_t lastMSCounterValue = 0;
#endif

static inline
uint32_t getMillisecondCounter() noexcept
{
#if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
return water::Time::getMillisecondCounter();
#else
uint32_t now;
timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
now = static_cast<uint32_t>(t.tv_sec * 1000 + t.tv_nsec / 1000000);

if (now < lastMSCounterValue)
{
// in multi-threaded apps this might be called concurrently, so
// make sure that our last counter value only increases and doesn't
// go backwards..
if (now < lastMSCounterValue - 1000)
lastMSCounterValue = now;
}
else
{
lastMSCounterValue = now;
}

return now;
#endif
}

// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// startProcess // startProcess


@@ -171,7 +130,7 @@ bool waitForClientConnect(const HANDLE pipe, const uint32_t timeOutMilliseconds)
CARLA_SAFE_ASSERT_RETURN(timeOutMilliseconds > 0, false); CARLA_SAFE_ASSERT_RETURN(timeOutMilliseconds > 0, false);


bool connecting = true; bool connecting = true;
const uint32_t timeoutEnd(getMillisecondCounter() + timeOutMilliseconds);
const uint32_t timeoutEnd(Time::getMillisecondCounter() + timeOutMilliseconds);


for (; connecting && ::ConnectNamedPipe(pipe, nullptr) == FALSE;) for (; connecting && ::ConnectNamedPipe(pipe, nullptr) == FALSE;)
{ {
@@ -185,7 +144,7 @@ bool waitForClientConnect(const HANDLE pipe, const uint32_t timeOutMilliseconds)


case ERROR_IO_PENDING: case ERROR_IO_PENDING:
case ERROR_PIPE_LISTENING: case ERROR_PIPE_LISTENING:
if (getMillisecondCounter() < timeoutEnd)
if (Time::getMillisecondCounter() < timeoutEnd)
{ {
carla_msleep(5); carla_msleep(5);
continue; continue;
@@ -243,7 +202,7 @@ bool waitForClientFirstMessage(const P& pipe, const uint32_t timeOutMilliseconds


char c; char c;
ssize_t ret; ssize_t ret;
const uint32_t timeoutEnd(getMillisecondCounter() + timeOutMilliseconds);
const uint32_t timeoutEnd(Time::getMillisecondCounter() + timeOutMilliseconds);


#ifdef CARLA_OS_WIN #ifdef CARLA_OS_WIN
if (! waitForClientConnect(pipe, timeOutMilliseconds)) if (! waitForClientConnect(pipe, timeOutMilliseconds))
@@ -276,7 +235,7 @@ bool waitForClientFirstMessage(const P& pipe, const uint32_t timeOutMilliseconds
if (errno == EAGAIN) if (errno == EAGAIN)
#endif #endif
{ {
if (getMillisecondCounter() < timeoutEnd)
if (Time::getMillisecondCounter() < timeoutEnd)
{ {
carla_msleep(5); carla_msleep(5);
continue; continue;
@@ -311,7 +270,7 @@ bool waitForProcessToStop(const PROCESS_INFORMATION& processInfo, const uint32_t
CARLA_SAFE_ASSERT_RETURN(processInfo.hProcess != INVALID_HANDLE_VALUE, false); CARLA_SAFE_ASSERT_RETURN(processInfo.hProcess != INVALID_HANDLE_VALUE, false);
CARLA_SAFE_ASSERT_RETURN(timeOutMilliseconds > 0, false); CARLA_SAFE_ASSERT_RETURN(timeOutMilliseconds > 0, false);


const uint32_t timeoutEnd(getMillisecondCounter() + timeOutMilliseconds);
const uint32_t timeoutEnd(Time::getMillisecondCounter() + timeOutMilliseconds);


for (;;) for (;;)
{ {
@@ -322,7 +281,7 @@ bool waitForProcessToStop(const PROCESS_INFORMATION& processInfo, const uint32_t
return true; return true;
} }


if (getMillisecondCounter() >= timeoutEnd)
if (Time::getMillisecondCounter() >= timeoutEnd)
break; break;


carla_msleep(5); carla_msleep(5);
@@ -356,7 +315,7 @@ bool waitForChildToStop(const pid_t pid, const uint32_t timeOutMilliseconds, boo
CARLA_SAFE_ASSERT_RETURN(timeOutMilliseconds > 0, false); CARLA_SAFE_ASSERT_RETURN(timeOutMilliseconds > 0, false);


pid_t ret; pid_t ret;
const uint32_t timeoutEnd(getMillisecondCounter() + timeOutMilliseconds);
const uint32_t timeoutEnd(Time::getMillisecondCounter() + timeOutMilliseconds);


for (;;) for (;;)
{ {
@@ -386,7 +345,7 @@ bool waitForChildToStop(const pid_t pid, const uint32_t timeOutMilliseconds, boo
sendTerminate = false; sendTerminate = false;
::kill(pid, SIGTERM); ::kill(pid, SIGTERM);
} }
if (getMillisecondCounter() < timeoutEnd)
if (Time::getMillisecondCounter() < timeoutEnd)
{ {
carla_msleep(5); carla_msleep(5);
continue; continue;
@@ -1017,14 +976,14 @@ const char* CarlaPipeCommon::_readline() const noexcept


const char* CarlaPipeCommon::_readlineblock(const uint32_t timeOutMilliseconds) const noexcept const char* CarlaPipeCommon::_readlineblock(const uint32_t timeOutMilliseconds) const noexcept
{ {
const uint32_t timeoutEnd(getMillisecondCounter() + timeOutMilliseconds);
const uint32_t timeoutEnd(Time::getMillisecondCounter() + timeOutMilliseconds);


for (;;) for (;;)
{ {
if (const char* const msg = _readline()) if (const char* const msg = _readline())
return msg; return msg;


if (getMillisecondCounter() >= timeoutEnd)
if (Time::getMillisecondCounter() >= timeoutEnd)
break; break;


carla_msleep(5); carla_msleep(5);
@@ -1193,6 +1152,7 @@ bool CarlaPipeServer::startPipeServer(const char* const filename,
//---------------------------------------------------------------- //----------------------------------------------------------------
// set size, non-fatal // set size, non-fatal


#ifdef CARLA_OS_LINUX
try { try {
::fcntl(pipeRecvClient, F_SETPIPE_SZ, size); ::fcntl(pipeRecvClient, F_SETPIPE_SZ, size);
} CARLA_SAFE_EXCEPTION("Set pipe size"); } CARLA_SAFE_EXCEPTION("Set pipe size");
@@ -1200,6 +1160,7 @@ bool CarlaPipeServer::startPipeServer(const char* const filename,
try { try {
::fcntl(pipeRecvServer, F_SETPIPE_SZ, size); ::fcntl(pipeRecvServer, F_SETPIPE_SZ, size);
} CARLA_SAFE_EXCEPTION("Set pipe size"); } CARLA_SAFE_EXCEPTION("Set pipe size");
#endif


//---------------------------------------------------------------- //----------------------------------------------------------------
// set non-block // set non-block


Loading…
Cancel
Save