Example #1
0
purgeinfo_t *ShmPrivatePurgeData::findTagInfo(int idTag)
{
    shm_purgedata_t *pData = NULL;
    shm_privpurgedata_t *pList =
        (shm_privpurgedata_t *)m_pool->offset2ptr(m_shmoff);
    lock();
    LsShmOffset_t offData = pList->x_listhead;
    while (offData != 0)
    {
        pData = (shm_purgedata_t *)m_pool->offset2ptr(offData);
        if (pData->x_purgeinfo.idTag == idTag)
        {
//             LOG4CXX_NS::Logger::getRootLogger()->debug(
//                     "tag: %d, entry timestamp: %d.%d, purge timestamp: %d.%d, flag, %d",
//                     idTag, sec, (int)msec, pData->x_purgeinfo.tmSecs,
//                     pData->x_purgeinfo.tmMsec, pData->x_purgeinfo.flags );

            unlock();
            return &pData->x_purgeinfo;
        }
        offData = pData->x_offNext;
    }
    unlock();
    return NULL;
}
Example #2
0
static inline LsShmHash *LsLuaShmOpen(const char *name)
{
    AutoStr2 *pName;
    LsShmHash *pRet;
    LsShm *pShm = LsShm::open(name, 0, NULL);
    if (pShm == NULL)
        return NULL;
    LsShmPool *pPool = pShm->getGlobalPool();
    if (pPool == NULL)
        return NULL;
    pName = new AutoStr2(name);
    pName->append("hash", 4);
    pRet =  pPool->getNamedHash(pName->c_str(), LSSHM_HASHINITSIZE,
                                LsShmHash::hashString, LsShmHash::compString,
                                LSSHM_FLAG_NONE);
    delete pName;
    return pRet;
}
Example #3
0
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;
}
Example #4
0
//
//  testing the raw interface
//
int    genericTest()
{
    register LsShm * p;
    const char * mapName = LSI_SHM_MAP_NAME;
   
    HttpLog::log(LSI_LOG_NOTICE, "Generic RAW LiterSpeed SHM TESTER\r\n");
    
    p = LsShm::get(mapName, LS_SHMSIZE);
    
    if (debugBase::checkStatus(mapName, mapName, p->status()))
        return -1;
    
    LsShmPool * sysPool;
    sysPool = LsShmPool::get(p, LSSHM_SYSPOOL);
    
    if (debugBase::checkStatus(LSSHM_SYSPOOL, LSSHM_SYSPOOL, sysPool->status()))
        return -1;
    
#if 0
    // testShmAlloc(p);
    testShmPool(p);
    fflush(debugBase::fp());
    
    testShmReg(p);
    fflush(debugBase::fp());
#endif
    
    testShmHash(p, sysPool);
    fflush(debugBase::fp());
    
#if 0
    fprintf(debugBase::fp(), "===============  REG  ==========\n");
    debugBase::dumpShmReg(p);
    fprintf(debugBase::fp(), "================================\n");
    fflush(debugBase::fp());
#endif
    return 0;
}    
Example #5
0
//
//  LiteSpeed SHM small memory tester!
//
void    testShmPool(LsShm * shm)
{
    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;
    }
    
    debugBase::dumpShm(pool, 0, NULL);
    debugBase::dumpShmPool(pool, 0, NULL);
    fflush(debugBase::fp());
    
    testPoolAlloc(pool, dArray, sizeof(dArray)/sizeof(testShm_t), 0);
}
Example #6
0
int ShmCacheManager::init(const char *pStoreDir)
{
    LsShm *pShm;
    LsShmPool *pPool;
    const char *pFileName = ".cacheman";
    int attempts;
    int ret = -1;
    for (attempts = 0; attempts < 3; ++attempts)
    {
        pShm = LsShm::open(pFileName, 40960, pStoreDir);

        if (!pShm)
        {
            pShm = LsShm::open(pFileName, 40960, pStoreDir);
            if (!pShm)
            {
                logShmError();
                return LS_FAIL;
            }
        }

        pPool = pShm->getGlobalPool();
        if (!pPool)
        {
            pShm->deleteFile();
            pShm->close();
            continue;
        }

        pPool->disableLock();
        pPool->lock();

        if ((initCacheInfo(pPool) == LS_FAIL)
            || (ret = initTables(pPool)) == LS_FAIL)
        {
            pPool->unlock();
            pPool->close();
            pShm->deleteFile();
            pShm->close();
        }
        else
            break;
    }

    pPool->unlock();
    pPool->enableLock();

    return ret;
}
Example #7
0
void ShmPrivatePurgeData::unlock()
{
    shm_privpurgedata_t *pList =
        (shm_privpurgedata_t *)m_pool->offset2ptr(m_shmoff);
    ls_spinlock_unlock(&pList->x_lock);
}
Example #8
0
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());
}