bool JdbcUtil::attachMemory(void) { setError(NULL); // If we have not accessed the memory, get it // only if it has already been created. if ((sharedMemoryId==-1) && !getMemory(false)) return false; if (sharedMemory && !sharedMemory->active) { // We are attached to an old memory segment. // Detach it so we can attach the new one. if (!detachMemory()) return false; } if (sharedMemory==NULL) { // At this point we have an id to the memory, now we // can attach it. void *shm; if ((shm = shmat(sharedMemoryId, NULL, 0)) == (void *) -1) { setPerror("Cannot attach shared memory"); return false; } sharedMemory = (struct JdbcUtilMemoryStruct *) shm; } return true; }
bool JdbcUtil::removeMemory(void) { setError(NULL); if (!getMemory(false)) { // If not found, it does not exist if (errorCode == ENOENT) return true; return false; } // deactivate the old memory in case some still has it attached if (attachMemory()) { sharedMemory->active = false; detachMemory(); } // Remove the memory if (shmctl(sharedMemoryId,IPC_RMID,NULL)==-1) { setPerror("Cannot remove shared memory"); return false; } sharedMemoryId = -1; return true; }
JdbcUtil::~JdbcUtil(void) { detachMemory(); }
/** * @brief */ MemoryIOV1::~MemoryIOV1() { if ( mMemPtr ) detachMemory(); }