src/hbcore/core/hbsharedmemorymanagerut_p.cpp
changeset 28 b7da29130b0e
parent 23 e6ad4ef83b23
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
    50         if ( !success && QSharedMemory::AlreadyExists == chunk->error() ) {
    50         if ( !success && QSharedMemory::AlreadyExists == chunk->error() ) {
    51             success = chunk->attach( QSharedMemory::ReadWrite );
    51             success = chunk->attach( QSharedMemory::ReadWrite );
    52         }
    52         }
    53         writable = true;
    53         writable = true;
    54         if ( !success ) {
    54         if ( !success ) {
    55 #ifdef THEME_SERVER_TRACES
    55             THEME_GENERIC_DEBUG() << "HbSharedMemoryManager:: Could not initialize shared memory chunk";
    56             qDebug() << "HbSharedMemoryManager:: Could not initialize shared memory chunk";
       
    57 #endif //THEME_SERVER_TRACES
       
    58             delete chunk; 
    56             delete chunk; 
    59             chunk = 0;
    57             chunk = 0;
    60         }
    58         }
    61     }
    59     }
    62 
    60 
    68         if (enableRecovery && chunkHeader->identifier == INITIALIZED_CHUNK_IDENTIFIER) {
    66         if (enableRecovery && chunkHeader->identifier == INITIALIZED_CHUNK_IDENTIFIER) {
    69             // just reconnect allocators to the shared chunk
    67             // just reconnect allocators to the shared chunk
    70             mainAllocator->initialize(chunk, chunkHeader->mainAllocatorOffset);
    68             mainAllocator->initialize(chunk, chunkHeader->mainAllocatorOffset);
    71             subAllocator->initialize(chunk, chunkHeader->subAllocatorOffset, mainAllocator);
    69             subAllocator->initialize(chunk, chunkHeader->subAllocatorOffset, mainAllocator);
    72         } else {
    70         } else {
       
    71             memset(chunkHeader, 0, sizeof(HbSharedChunkHeader));
    73             chunkHeader->mainAllocatorOffset = sizeof(HbSharedChunkHeader);
    72             chunkHeader->mainAllocatorOffset = sizeof(HbSharedChunkHeader);
    74             // Clear also allocator identifier so that they will not try to re-connect
    73             // Clear also allocator identifier so that they will not try to re-connect
    75             qptrdiff *mainAllocatorIdentifier = reinterpret_cast<qptrdiff *>(static_cast<char *>(base()) + chunkHeader->mainAllocatorOffset);
    74             quint32 *mainAllocatorIdentifier = reinterpret_cast<quint32 *>(static_cast<char *>(base()) + chunkHeader->mainAllocatorOffset);            
    76             *mainAllocatorIdentifier = 0;
    75             *mainAllocatorIdentifier = 0;
    77             mainAllocator->initialize(chunk, chunkHeader->mainAllocatorOffset);
    76             mainAllocator->initialize(chunk, chunkHeader->mainAllocatorOffset);
    78             chunkHeader->subAllocatorOffset = alloc(SPACE_NEEDED_FOR_MULTISEGMENT_ALLOCATOR);
    77             chunkHeader->subAllocatorOffset = alloc(SPACE_NEEDED_FOR_MULTISEGMENT_ALLOCATOR);
    79             qptrdiff *subAllocatorIdentifier = reinterpret_cast<qptrdiff *>(static_cast<char *>(base()) + chunkHeader->subAllocatorOffset);
    78             quint32 *subAllocatorIdentifier = reinterpret_cast<quint32 *>(static_cast<char *>(base()) + chunkHeader->subAllocatorOffset);
    80             *subAllocatorIdentifier = 0;
    79             *subAllocatorIdentifier = 0;
    81             subAllocator->initialize(chunk, chunkHeader->subAllocatorOffset, mainAllocator);
    80             subAllocator->initialize(chunk, chunkHeader->subAllocatorOffset, mainAllocator);
    82             chunkHeader->identifier = INITIALIZED_CHUNK_IDENTIFIER;
    81             chunkHeader->identifier = INITIALIZED_CHUNK_IDENTIFIER;
    83 
    82 
    84             // Create empty shared cache for unit test purposes
    83             // Create empty shared cache for unit test purposes
   126 HbMemoryManager * HbSharedMemoryManagerUt::instance()
   125 HbMemoryManager * HbSharedMemoryManagerUt::instance()
   127 {
   126 {
   128     if( !memManager ){
   127     if( !memManager ){
   129         memManager = new HbSharedMemoryManagerUt();
   128         memManager = new HbSharedMemoryManagerUt();
   130         if( !memManager->initialize() ) {
   129         if( !memManager->initialize() ) {
   131             qWarning( "HbSharedMemoryManager:Could not initialize shared memory" );
   130             hbWarning( "HbSharedMemoryManager:Could not initialize shared memory" );
   132             delete memManager;
   131             delete memManager;
   133             memManager = 0;
   132             memManager = 0;
   134         }
   133         }
   135     }
   134     }
   136     return memManager;
   135     return memManager;