Browse Source

Memory locking tools

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1366 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/0.62
sletz 19 years ago
parent
commit
0b91ecdd83
5 changed files with 77 additions and 33 deletions
  1. +0
    -3
      common/JackClientControl.h
  2. +9
    -1
      common/JackEngine.cpp
  3. +36
    -1
      common/JackShmMem.cpp
  4. +30
    -27
      common/JackShmMem.h
  5. +2
    -1
      common/shm.h

+ 0
- 3
common/JackClientControl.h View File

@@ -56,9 +56,6 @@ struct JackClientControl : public JackShmMem
Init("", -1);
}

virtual ~JackClientControl()
{}

void Init(const char* name, int refnum)
{
strcpy(fName, name);


+ 9
- 1
common/JackEngine.cpp View File

@@ -33,7 +33,15 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{

JackEngine::JackEngine(JackGraphManager* manager, JackSynchro** table, JackEngineControl* control, JackSyncInterface* signal, bool sync, long time_out_ms, bool rt, long priority, bool ve)
JackEngine::JackEngine(JackGraphManager* manager,
JackSynchro** table,
JackEngineControl* control,
JackSyncInterface* signal,
bool sync,
long time_out_ms,
bool rt,
long priority,
bool ve)
{
fGraphManager = manager;
fSynchroTable = table;


+ 36
- 1
common/JackShmMem.cpp View File

@@ -29,7 +29,7 @@ unsigned long JackShmMem::fSegmentNum = 0;
unsigned long JackShmMem::fSegmentCount = 0;

jack_shm_info_t JackShmMem::gInfo;
size_t JackLockMem::gSize = 0;
size_t JackMem::gSize = 0;

void* JackShmMem::operator new(size_t size)
{
@@ -62,7 +62,9 @@ void* JackShmMem::operator new(size_t size)
// It is unsafe to set object fields directly (may be overwritten during object initialization),
// so use an intermediate global data
gInfo.index = info.index;
gInfo.size = size;
gInfo.attached_at = info.attached_at;
JackLog("JackShmMem::new index = %ld attached = %x size = %ld \n", info.index, info.attached_at, size);
return obj;

@@ -89,5 +91,38 @@ void JackShmMem::operator delete(void* p, size_t size)
}
}

void LockMemoryImp(void* ptr, size_t size)
{
#ifdef __APPLE__
int res = mlock(ptr, size);
#elif linux_
int res = mlock(ptr, size);
#elif WIN32
int res = VirtualLock(ptr, size);
#endif
if (res != 0) {
jack_error("Cannot lock down memory area (%s)", strerror(errno));
} else {
JackLog("Succeeded in locking %u byte memory area\n", size);
}
}

void UnlockMemoryImp(void* ptr, size_t size)
{
#ifdef __APPLE__
int res = munlock(ptr, size);
#elif linux_
int res = munlock(ptr, size);
#elif WIN32
int res = VirtualUnlock(ptr, size);
#endif
if (res != 0) {
jack_error("Cannot unlock down memory area (%s)", strerror(errno));
} else {
JackLog("Succeeded in unlocking %u byte memory area\n", size);
}
}


} // end of namespace


+ 30
- 27
common/JackShmMem.h View File

@@ -38,7 +38,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{

class JackLockMem
void LockMemoryImp(void* ptr, size_t size);
void UnlockMemoryImp(void* ptr, size_t size);

class JackMem
{
private:

@@ -50,7 +53,7 @@ class JackLockMem
void* operator new(size_t size)
{
gSize = size;
return malloc(size);
return calloc(1, size);
}
void operator delete(void* ptr, size_t size)
@@ -58,49 +61,36 @@ class JackLockMem
free(ptr);
}

JackLockMem():fSize(gSize)
JackMem():fSize(gSize)
{}

virtual ~JackLockMem()
virtual ~JackMem()
{
UnlockMemory();
UnlockMemoryImp(this, fSize);
}
void LockMemory()
void LockMemory()
{
#ifdef __APPLE__
mlock(this, fSize);
#elif linux_
mlock(this, fSize);
#elif WIN32
VirtualLock(this, fSize);
#endif
LockMemoryImp(this, fSize);
}
void UnlockMemory()
void UnlockMemory()
{
#ifdef __APPLE__
munlock(this, fSize);
#elif linux_
munlock(this, fSize);
#elif WIN32
VirtualUnlock(this, fSize);
#endif
UnlockMemoryImp(this, fSize);
}

};


/*!
\brief The base class for shared memory management.
A class which objects need to be allocated in shared memory derives from this class.
*/

class JackShmMem
class JackShmMem
{

private:
protected:

jack_shm_info_t fInfo;
static unsigned long fSegmentNum;
@@ -115,11 +105,14 @@ class JackShmMem
JackShmMem()
{
fInfo.index = gInfo.index;
fInfo.attached_at = gInfo.attached_at;
}
fInfo.attached_at = gInfo.attached_at;
fInfo.size = gInfo.size;
}

virtual ~JackShmMem()
{}
{
UnlockMemoryImp(this, fInfo.size);
}

int GetShmIndex()
{
@@ -130,6 +123,16 @@ class JackShmMem
{
return (char*)fInfo.attached_at;
}
void LockMemory()
{
LockMemoryImp(this, fInfo.size);
}
void UnlockMemory()
{
UnlockMemoryImp(this, fInfo.size);
}

};



+ 2
- 1
common/shm.h View File

@@ -117,7 +117,8 @@ extern "C"
*/
typedef struct _jack_shm_info {
jack_shm_registry_index_t index; /* offset into the registry */
void *attached_at; /* address where attached */
size_t size;
void *attached_at; /* address where attached */
}
jack_shm_info_t;



Loading…
Cancel
Save