diff --git a/ChangeLog b/ChangeLog index 49de5f51..a5c3dd01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,7 @@ Romain Moret 2008-06-13 Stephane Letz * Correct JackPosixThread::ThreadHandler termination, do not set buffer size if same value is used. + * Another Tim Blechmann cleanup patch + do no allocate JackClientControl in shared memory for server internal clients. 2008-06-12 Stephane Letz diff --git a/common/JackClientControl.h b/common/JackClientControl.h index 6ca73c45..77c3f41d 100644 --- a/common/JackClientControl.h +++ b/common/JackClientControl.h @@ -31,10 +31,10 @@ namespace Jack { /*! -\brief Client control in shared memory. +\brief Client control possibly in shared memory. */ -struct JackClientControl : public JackShmMem +struct JackClientControl : public JackShmMemAble { char fName[JACK_CLIENT_NAME_SIZE + 1]; bool fCallback[kMaxNotification]; diff --git a/common/JackDriver.h b/common/JackDriver.h index 6399be8e..501758e8 100644 --- a/common/JackDriver.h +++ b/common/JackDriver.h @@ -85,25 +85,6 @@ class EXPORT JackDriverInterface virtual bool IsRealTime() = 0; }; - -/* - \brief The base interface for blocking drivers. - */ - -class EXPORT JackBlockingInterface -{ - - public: - - JackBlockingInterface() - {} - virtual ~JackBlockingInterface() - {} - - virtual bool Init() = 0; /* To be called by the wrapping thread Init method when the driver is a "blocking" one */ - -}; - /*! \brief The base interface for drivers clients. */ @@ -115,7 +96,7 @@ class EXPORT JackDriverClientInterface : public JackDriverInterface, public Jack \brief The base class for drivers clients. */ -class EXPORT JackDriverClient : public JackDriverClientInterface, public JackBlockingInterface +class EXPORT JackDriverClient : public JackDriverClientInterface { private: @@ -127,7 +108,7 @@ class EXPORT JackDriverClient : public JackDriverClientInterface, public JackBlo bool fIsMaster; public: - + virtual bool Init() = 0; /* To be called by the wrapping thread Init method when the driver is a "blocking" one */ virtual void SetMaster(bool onoff); virtual bool GetMaster(); virtual void AddSlave(JackDriverInterface* slave); diff --git a/common/JackExternalClient.cpp b/common/JackExternalClient.cpp index bf164937..6024493e 100644 --- a/common/JackExternalClient.cpp +++ b/common/JackExternalClient.cpp @@ -53,15 +53,19 @@ int JackExternalClient::Open(const char* name, int pid, int refnum, int* shared_ jack_error("Cannot connect to client name = %s\n", name); return -1; } - - fClientControl = new JackClientControl(name, pid, refnum); + + // Use "placement new" to allocate object in shared memory + JackShmMemAble* shared_mem = static_cast(JackShmMem::operator new(sizeof(JackClientControl))); + shared_mem->Init(); + fClientControl = new(shared_mem) JackClientControl(name, pid, refnum); + if (!fClientControl) { jack_error("Cannot allocate client shared memory segment"); return -1; } - - *shared_client = fClientControl->GetShmIndex(); - jack_log("JackExternalClient::Open name = %s index = %ld base = %x", name, fClientControl->GetShmIndex(), fClientControl->GetShmAddress()); + + *shared_client = shared_mem->GetShmIndex(); + jack_log("JackExternalClient::Open name = %s index = %ld base = %x", name, shared_mem->GetShmIndex(), shared_mem->GetShmAddress()); return 0; } catch (std::exception e) { @@ -72,7 +76,8 @@ int JackExternalClient::Open(const char* name, int pid, int refnum, int* shared_ int JackExternalClient::Close() { fChannel.Close(); - delete fClientControl; + fClientControl->~JackClientControl(); + JackShmMem::operator delete(fClientControl); return 0; } diff --git a/common/JackInternalClient.cpp b/common/JackInternalClient.cpp index eba0dfc8..15723a4f 100644 --- a/common/JackInternalClient.cpp +++ b/common/JackInternalClient.cpp @@ -66,13 +66,11 @@ JackSynchro* GetSynchroTable() JackInternalClient::JackInternalClient(JackServer* server, JackSynchro* table): JackClient(table) { - fClientControl = new JackClientControl(); fChannel = new JackInternalClientChannel(server); } JackInternalClient::~JackInternalClient() { - delete fClientControl; delete fChannel; } @@ -94,10 +92,10 @@ int JackInternalClient::Open(const char* server_name, const char* name, jack_opt goto error; } - strcpy(fClientControl->fName, name_res); + strcpy(fClientControl.fName, name_res); // Require new client - fChannel->ClientOpen(name_res, &fClientControl->fRefNum, &fEngineControl, &fGraphManager, this, &result); + fChannel->ClientOpen(name_res, &fClientControl.fRefNum, &fEngineControl, &fGraphManager, this, &result); if (result < 0) { jack_error("Cannot open client name = %s", name_res); goto error; @@ -126,7 +124,7 @@ JackEngineControl* JackInternalClient::GetEngineControl() const JackClientControl* JackInternalClient::GetClientControl() const { - return fClientControl; + return const_cast(&fClientControl); } JackLoadableInternalClient::JackLoadableInternalClient(JackServer* server, JackSynchro* table, const char* so_name, const char* object_data) diff --git a/common/JackInternalClient.h b/common/JackInternalClient.h index 795d59cb..676b5a1a 100644 --- a/common/JackInternalClient.h +++ b/common/JackInternalClient.h @@ -22,6 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define __JackInternalClient__ #include "JackClient.h" +#include "JackClientControl.h" namespace Jack { @@ -37,7 +38,7 @@ class JackInternalClient : public JackClient private: - JackClientControl* fClientControl; /*! Client control */ + JackClientControl fClientControl; /*! Client control */ public: diff --git a/common/JackShmMem.cpp b/common/JackShmMem.cpp index 92c4f299..400869c4 100644 --- a/common/JackShmMem.cpp +++ b/common/JackShmMem.cpp @@ -34,6 +34,11 @@ static jack_shm_info_t gInfo; size_t JackMem::gSize = 0; JackShmMem::JackShmMem() +{ + JackShmMemAble::Init(); +} + +void JackShmMemAble::Init() { fInfo.index = gInfo.index; fInfo.attached_at = gInfo.attached_at; diff --git a/common/JackShmMem.h b/common/JackShmMem.h index 61d62918..d713bf70 100644 --- a/common/JackShmMem.h +++ b/common/JackShmMem.h @@ -61,7 +61,6 @@ class JackMem JackMem(): fSize(gSize) {} - ~JackMem() {} @@ -91,31 +90,20 @@ class JackMem }; /*! -\brief The base class for shared memory management. +\brief -A class which objects need to be allocated in shared memory derives from this class. +A class which objects possibly want to be allocated in shared memory derives from this class. */ -class EXPORT JackShmMem +class JackShmMemAble { - protected: - + jack_shm_info_t fInfo; - protected: - - JackShmMem(); - - ~JackShmMem() - {} - public: - - void* operator new(size_t size); - void* operator new(size_t size, void* memory); - void operator delete(void* p, size_t size); - void operator delete(void* p); + + void Init(); int GetShmIndex() { @@ -139,6 +127,31 @@ class EXPORT JackShmMem }; +/*! +\brief The base class for shared memory management. + +A class which objects need to be allocated in shared memory derives from this class. +*/ + +class EXPORT JackShmMem : public JackShmMemAble +{ + + protected: + + JackShmMem(); + ~JackShmMem() + {} + + public: + + void* operator new(size_t size); + void* operator new(size_t size, void* memory); + + void operator delete(void* p, size_t size); + void operator delete(void* p); + +}; + /*! \brief Pointer on shared memory segment in the client side. */