20 #ifndef __JackShmMem__
21 #define __JackShmMem__
24 #include "JackError.h"
25 #include "JackCompilerDeps.h"
31 #include "JackShmMem_os.h"
36 SERVER_EXPORT
void LockMemoryImp(
void* ptr,
size_t size);
37 SERVER_EXPORT
void InitLockMemoryImp(
void* ptr,
size_t size);
38 SERVER_EXPORT
void UnlockMemoryImp(
void* ptr,
size_t size);
39 SERVER_EXPORT
void LockAllMemory();
40 SERVER_EXPORT
void UnlockAllMemory();
58 void*
operator new(
size_t size)
61 return calloc(1, size);
64 void operator delete(
void* ptr,
size_t size)
71 LockMemoryImp(
this, fSize);
76 UnlockMemoryImp(
this, fSize);
91 jack_shm_info_t fInfo;
102 char* GetShmAddress()
104 return (
char*)fInfo.ptr.attached_at;
109 LockMemoryImp(
this, fInfo.size);
114 UnlockMemoryImp(
this, fInfo.size);
135 void*
operator new(
size_t size);
136 void*
operator new(
size_t size,
void* memory);
138 void operator delete(
void* p,
size_t size);
139 void operator delete(
void* p);
153 jack_shm_info_t fInfo;
155 void Init(
int index,
const char* server_name =
"default")
157 if (fInfo.index < 0 && index >= 0) {
158 jack_log(
"JackShmReadWritePtr::Init %ld %ld", index, fInfo.index);
159 if (jack_initialize_shm(server_name) < 0) {
160 throw std::bad_alloc();
163 if (jack_attach_lib_shm(&fInfo)) {
164 throw std::bad_alloc();
166 GetShmAddress()->LockMemory();
175 fInfo.ptr.attached_at = (
char*)NULL;
180 Init(index, server_name);
185 if (fInfo.index >= 0) {
186 jack_log(
"JackShmReadWritePtr::~JackShmReadWritePtr %ld", fInfo.index);
187 GetShmAddress()->UnlockMemory();
188 jack_release_lib_shm(&fInfo);
193 T* operator->()
const
195 return (T*)fInfo.ptr.attached_at;
200 return (T*)fInfo.ptr.attached_at;
209 void SetShmIndex(
int index,
const char* server_name)
211 Init(index, server_name);
221 return (T*)fInfo.ptr.attached_at;
235 jack_shm_info_t fInfo;
237 void Init(
int index,
const char* server_name =
"default")
239 if (fInfo.index < 0 && index >= 0) {
240 jack_log(
"JackShmReadWritePtr1::Init %ld %ld", index, fInfo.index);
241 if (jack_initialize_shm(server_name) < 0) {
242 throw std::bad_alloc();
245 if (jack_attach_lib_shm(&fInfo)) {
246 throw std::bad_alloc();
248 GetShmAddress()->LockMemory();
254 jack_destroy_shm(&fInfo);
263 fInfo.ptr.attached_at = NULL;
268 Init(index, server_name);
273 if (fInfo.index >= 0) {
274 jack_log(
"JackShmReadWritePtr1::~JackShmReadWritePtr1 %ld", fInfo.index);
275 GetShmAddress()->UnlockMemory();
276 jack_release_lib_shm(&fInfo);
281 T* operator->()
const
283 return (T*)fInfo.ptr.attached_at;
288 return (T*)fInfo.ptr.attached_at;
297 void SetShmIndex(
int index,
const char* server_name)
299 Init(index, server_name);
309 return (T*)fInfo.ptr.attached_at;
323 jack_shm_info_t fInfo;
325 void Init(
int index,
const char* server_name =
"default")
327 if (fInfo.index < 0 && index >= 0) {
328 jack_log(
"JackShmPtrRead::Init %ld %ld", index, fInfo.index);
329 if (jack_initialize_shm(server_name) < 0) {
330 throw std::bad_alloc();
333 if (jack_attach_lib_shm_read(&fInfo)) {
334 throw std::bad_alloc();
336 GetShmAddress()->LockMemory();
345 fInfo.ptr.attached_at = NULL;
350 Init(index, server_name);
355 if (fInfo.index >= 0) {
356 jack_log(
"JackShmPtrRead::~JackShmPtrRead %ld", fInfo.index);
357 GetShmAddress()->UnlockMemory();
358 jack_release_lib_shm(&fInfo);
363 T* operator->()
const
365 return (T*)fInfo.ptr.attached_at;
370 return (T*)fInfo.ptr.attached_at;
379 void SetShmIndex(
int index,
const char* server_name)
381 Init(index, server_name);
391 return (T*)fInfo.ptr.attached_at;