int SharedDataManager::beginTimestampedSegment(TreeDescriptor treeId, int nid, int idx, int numItems, char *shape, int shapeSize, char *data, int dataSize, _int64 start, _int64 end, char *dim, int dimSize, int *retIdx) { Segment *segment; //printf("BEGIN TIMESTAMPED SEGMENT SHARE: %d\n", *(int *)shape); lock.lock(); SharedMemNode *node = sharedTree.find(treeId, nid); if(!node) { SharedMemNodeData nodeData; nodeData.setNid(treeId, nid); nodeData.setSegmented(true); sharedTree.insert(&nodeData); node = sharedTree.find(treeId, nid); } if(node) { SharedMemNodeData *nodeData = node->getData(); if(!nodeData->isSegmented()) { nodeData->free(&allocationManager); nodeData->setSegmented(true); } int numSegments = nodeData->getNumSegments(); if(idx > numSegments) { lock.unlock(); return 0; } if(idx == numSegments || idx < 0) { segment = (Segment *)allocationManager.allocateShared(sizeof(Segment)); // printf("ALLOCATED SEGMENT: %x\n", segment); segment->initialize(); nodeData->appendSegment(segment); *retIdx = numSegments; } else { segment = nodeData->getSegmentAt(idx); *retIdx = idx; } char *currPtr; segment->free(&allocationManager); if(dimSize == 0) { currPtr = allocationManager.allocateShared(8 * numItems); // printf("ALLOCATED SEGMENT DIM: %x\n", currPtr); segment->setDim(currPtr, 8 * numItems); } currPtr = allocationManager.allocateShared(shapeSize); // printf("ALLOCATED SEGMENT SHAPE: %x %d\n", currPtr, *(int *)shape); memcpy(currPtr, shape, shapeSize); segment->setShape(currPtr, shapeSize); currPtr = allocationManager.allocateShared(dataSize); // printf("ALLOCATED SEGMENTDATA: %x\n", currPtr); memcpy(currPtr, data, dataSize); segment->setData(currPtr, dataSize); //The following parameters are meaningful only when copying a segment from the tree into cache segment->setStartTimestamp(start); segment->setEndTimestamp(end); if(dimSize > 0) { currPtr = allocationManager.allocateShared(dimSize); // printf("ALLOCATED SEGMENT DIM : %x\n", currPtr); memcpy(currPtr, dim, dimSize); segment->setDim(currPtr, dimSize); segment->setStartTimestamp(*(_int64 *)dim); if(end == 0) segment->setEndTimestamp(*(_int64 *)dim); } segment->setTimestamped(true); lock.unlock(); //printf("END BEGIN TIMESTAMPED SEGMENT LAST SEGMENT: %x\n", nodeData->getLastSegment()); return 1; } lock.unlock(); return 0; }
int SharedDataManager::beginSegment(TreeDescriptor treeId, int nid, int idx, char *start, int startSize, char *end, int endSize, char *dim, int dimSize, char *shape, int shapeSize, char *data, int dataSize, int *retIdx) { Segment *segment; lock.lock(); SharedMemNode *node = sharedTree.find(treeId, nid); if(!node) { SharedMemNodeData nodeData; nodeData.setNid(treeId, nid); nodeData.setSegmented(true); sharedTree.insert(&nodeData); node = sharedTree.find(treeId, nid); } if(node) { SharedMemNodeData *nodeData = node->getData(); if(!nodeData->isSegmented()) { nodeData->free(&allocationManager); nodeData->setSegmented(true); } int numSegments = nodeData->getNumSegments(); if(idx > numSegments) { lock.unlock(); return 0; } if(idx == numSegments || idx < 0) { segment = (Segment *)allocationManager.allocateShared(sizeof(Segment)); segment->initialize(); nodeData->appendSegment(segment); *retIdx = numSegments; } else { segment = nodeData->getSegmentAt(idx); *retIdx = idx; } char *currPtr; segment->free(&allocationManager); currPtr = allocationManager.allocateShared(startSize); memcpy(currPtr, start, startSize); segment->setStart(currPtr, startSize); currPtr = allocationManager.allocateShared(endSize); memcpy(currPtr, end, endSize); segment->setEnd(currPtr, endSize); currPtr = allocationManager.allocateShared(dimSize); memcpy(currPtr, dim, dimSize); segment->setDim(currPtr, dimSize); currPtr = allocationManager.allocateShared(shapeSize); memcpy(currPtr, shape, shapeSize); segment->setShape(currPtr, shapeSize); currPtr = allocationManager.allocateShared(dataSize); memcpy(currPtr, data, dataSize); segment->setData(currPtr, dataSize); segment->setTimestamped(false); lock.unlock(); return 1; } lock.unlock(); return 0; }