git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2520 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.90
@@ -24,6 +24,7 @@ Romain Moret | |||||
2008-06-13 Stephane Letz <letz@grame.fr> | 2008-06-13 Stephane Letz <letz@grame.fr> | ||||
* Correct JackPosixThread::ThreadHandler termination, do not set buffer size if same value is used. | * 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 <letz@grame.fr> | 2008-06-12 Stephane Letz <letz@grame.fr> | ||||
@@ -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]; | char fName[JACK_CLIENT_NAME_SIZE + 1]; | ||||
bool fCallback[kMaxNotification]; | bool fCallback[kMaxNotification]; | ||||
@@ -85,25 +85,6 @@ class EXPORT JackDriverInterface | |||||
virtual bool IsRealTime() = 0; | 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. | \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. | \brief The base class for drivers clients. | ||||
*/ | */ | ||||
class EXPORT JackDriverClient : public JackDriverClientInterface, public JackBlockingInterface | |||||
class EXPORT JackDriverClient : public JackDriverClientInterface | |||||
{ | { | ||||
private: | private: | ||||
@@ -127,7 +108,7 @@ class EXPORT JackDriverClient : public JackDriverClientInterface, public JackBlo | |||||
bool fIsMaster; | bool fIsMaster; | ||||
public: | 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 void SetMaster(bool onoff); | ||||
virtual bool GetMaster(); | virtual bool GetMaster(); | ||||
virtual void AddSlave(JackDriverInterface* slave); | virtual void AddSlave(JackDriverInterface* slave); | ||||
@@ -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); | jack_error("Cannot connect to client name = %s\n", name); | ||||
return -1; | return -1; | ||||
} | } | ||||
fClientControl = new JackClientControl(name, pid, refnum); | |||||
// Use "placement new" to allocate object in shared memory | |||||
JackShmMemAble* shared_mem = static_cast<JackShmMemAble*>(JackShmMem::operator new(sizeof(JackClientControl))); | |||||
shared_mem->Init(); | |||||
fClientControl = new(shared_mem) JackClientControl(name, pid, refnum); | |||||
if (!fClientControl) { | if (!fClientControl) { | ||||
jack_error("Cannot allocate client shared memory segment"); | jack_error("Cannot allocate client shared memory segment"); | ||||
return -1; | 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; | return 0; | ||||
} catch (std::exception e) { | } catch (std::exception e) { | ||||
@@ -72,7 +76,8 @@ int JackExternalClient::Open(const char* name, int pid, int refnum, int* shared_ | |||||
int JackExternalClient::Close() | int JackExternalClient::Close() | ||||
{ | { | ||||
fChannel.Close(); | fChannel.Close(); | ||||
delete fClientControl; | |||||
fClientControl->~JackClientControl(); | |||||
JackShmMem::operator delete(fClientControl); | |||||
return 0; | return 0; | ||||
} | } | ||||
@@ -66,13 +66,11 @@ JackSynchro* GetSynchroTable() | |||||
JackInternalClient::JackInternalClient(JackServer* server, JackSynchro* table): JackClient(table) | JackInternalClient::JackInternalClient(JackServer* server, JackSynchro* table): JackClient(table) | ||||
{ | { | ||||
fClientControl = new JackClientControl(); | |||||
fChannel = new JackInternalClientChannel(server); | fChannel = new JackInternalClientChannel(server); | ||||
} | } | ||||
JackInternalClient::~JackInternalClient() | JackInternalClient::~JackInternalClient() | ||||
{ | { | ||||
delete fClientControl; | |||||
delete fChannel; | delete fChannel; | ||||
} | } | ||||
@@ -94,10 +92,10 @@ int JackInternalClient::Open(const char* server_name, const char* name, jack_opt | |||||
goto error; | goto error; | ||||
} | } | ||||
strcpy(fClientControl->fName, name_res); | |||||
strcpy(fClientControl.fName, name_res); | |||||
// Require new client | // 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) { | if (result < 0) { | ||||
jack_error("Cannot open client name = %s", name_res); | jack_error("Cannot open client name = %s", name_res); | ||||
goto error; | goto error; | ||||
@@ -126,7 +124,7 @@ JackEngineControl* JackInternalClient::GetEngineControl() const | |||||
JackClientControl* JackInternalClient::GetClientControl() const | JackClientControl* JackInternalClient::GetClientControl() const | ||||
{ | { | ||||
return fClientControl; | |||||
return const_cast<JackClientControl*>(&fClientControl); | |||||
} | } | ||||
JackLoadableInternalClient::JackLoadableInternalClient(JackServer* server, JackSynchro* table, const char* so_name, const char* object_data) | JackLoadableInternalClient::JackLoadableInternalClient(JackServer* server, JackSynchro* table, const char* so_name, const char* object_data) | ||||
@@ -22,6 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||||
#define __JackInternalClient__ | #define __JackInternalClient__ | ||||
#include "JackClient.h" | #include "JackClient.h" | ||||
#include "JackClientControl.h" | |||||
namespace Jack | namespace Jack | ||||
{ | { | ||||
@@ -37,7 +38,7 @@ class JackInternalClient : public JackClient | |||||
private: | private: | ||||
JackClientControl* fClientControl; /*! Client control */ | |||||
JackClientControl fClientControl; /*! Client control */ | |||||
public: | public: | ||||
@@ -34,6 +34,11 @@ static jack_shm_info_t gInfo; | |||||
size_t JackMem::gSize = 0; | size_t JackMem::gSize = 0; | ||||
JackShmMem::JackShmMem() | JackShmMem::JackShmMem() | ||||
{ | |||||
JackShmMemAble::Init(); | |||||
} | |||||
void JackShmMemAble::Init() | |||||
{ | { | ||||
fInfo.index = gInfo.index; | fInfo.index = gInfo.index; | ||||
fInfo.attached_at = gInfo.attached_at; | fInfo.attached_at = gInfo.attached_at; | ||||
@@ -61,7 +61,6 @@ class JackMem | |||||
JackMem(): fSize(gSize) | JackMem(): fSize(gSize) | ||||
{} | {} | ||||
~JackMem() | ~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: | protected: | ||||
jack_shm_info_t fInfo; | jack_shm_info_t fInfo; | ||||
protected: | |||||
JackShmMem(); | |||||
~JackShmMem() | |||||
{} | |||||
public: | 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() | 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. | \brief Pointer on shared memory segment in the client side. | ||||
*/ | */ | ||||