LsShmOffset_t ShmPrivatePurgeData::addUpdate(purgeinfo_t *pInfo) { shm_purgedata_t *pData; shm_privpurgedata_t *pList = (shm_privpurgedata_t *)m_pool->offset2ptr(m_shmoff); lock(); pList->x_tmLastUpdate = DateTime::s_curTime; LsShmOffset_t offData = pList->x_listhead; while (offData != 0) { pData = (shm_purgedata_t *)m_pool->offset2ptr(offData); if (pData->x_purgeinfo.idTag == pInfo->idTag) break; offData = pData->x_offNext; } if (offData == 0) { int remapped = 0; offData = m_pool->alloc2(sizeof(shm_purgedata_t), remapped); if (remapped) pList = (shm_privpurgedata_t *)m_pool->offset2ptr(m_shmoff); if (offData != 0) { pData = (shm_purgedata_t *)m_pool->offset2ptr(offData); pData->x_offNext = pList->x_listhead; pList->x_listhead = offData; } else { unlock(); return 0; } } memmove(&pData->x_purgeinfo, pInfo, sizeof(*pInfo)); unlock(); return offData; }
void testShmAlloc(LsShm * shm) { register testShm_t * p; register int i; if (shm->status() != LSSHM_READY) { fprintf(debugBase::fp(), "LsShm %p NOTREADY %d\n", shm,shm->status()); return; } LsShmPool *pool = LsShmPool::get(shm, LSI_SHM_POOL_NAME); if (pool->status() != LSSHM_READY) { fprintf(debugBase::fp(), "LsShmPool %p NOTREADY %d\n", shm,shm->status()); return; } p = tArray; for (i = 0; i < (int)(sizeof(tArray)/sizeof(testShm_t)); i++) { p->roundsize = debugBase::roundPageSize(pool, p->size), fprintf(debugBase::fp(), "\nALLOC TEST %d SIZE %X\n", i, p->roundsize); int remapped = 0; if (!(p->offset = pool->alloc2(p->size, remapped))) { fprintf( debugBase::fp(), "ABORT: NO MEORY alloc2 [%8X %8X]\n", p->size, p->roundsize); abort(); } fprintf( debugBase::fp(), "ALLOC %8X %8X -> %8X %8X %s\n", p->offset, p->size, p->expected, p->roundsize, (p->offset == p->expected) ? "GOOD" : "BAD " ); p++; debugBase::dumpShm(pool, 0, NULL); fflush(debugBase::fp()); } p = tArray; i = rand() % (int)((sizeof(tArray)/sizeof(testShm_t))); for (; i < (int)(sizeof(tArray)/sizeof(testShm_t)); ) { if (i & 0x1) { fprintf(debugBase::fp(), "\nFREE TEST %d [%8X %8X] \n", i, p->offset, p->roundsize); pool->release2(p->offset, p->size); debugBase::dumpShm(pool, 0, NULL); fflush(debugBase::fp()); } p++; i++; } p = tArray; i = rand() % (int)((sizeof(tArray)/sizeof(testShm_t))); for (; i < (int)(sizeof(tArray)/sizeof(testShm_t)); ) { if (!(i & 0x1)) { fprintf(debugBase::fp(), "\nFREE TEST %d [%8X %8X] \n", i, p->offset, p->roundsize); pool->release2(p->offset, p->size); debugBase::dumpShm(pool, 0, NULL); fflush(debugBase::fp()); } p++; i++; } fflush(debugBase::fp()); }