int FileCacheDataEx::readyData(const char * pPath)
{
    int fd;
    int ret = openFile( pPath, fd );
    if ( ret )
        return ret;
    if ( (size_t)m_lSize < s_iMaxInMemCacheSize )
    {
        ret = allocateCache( m_lSize );
        if ( ret == 0 )
        {
            ret = nio_read( fd, m_pCache, m_lSize );
            if ( ret == m_lSize )
            {
                close( fd );
                return 0;
            }
            else
            {
                release();
            }
        }
    }
    else if (( (size_t)m_lSize < s_iMaxMMapCacheSize )
            &&((size_t)m_lSize + s_iCurTotalMMAPCache < s_iMaxTotalMMAPCache ))
    {
        m_pCache = (char *)mmap( 0, m_lSize, PROT_READ,
                MAP_PRIVATE, fd, 0 );
        s_iCurTotalMMAPCache += m_lSize;
        if ( D_ENABLED( DL_MORE ))
            LOG_D(( "[MMAP] Map %p to file:%s", m_pCache, pPath ));
        if ( m_pCache == MAP_FAILED )
        {
            m_pCache = 0;
        }
        else
        {
            setStatus( MMAPED );
            close( fd );
            return 0;
        }
    }
    setfd( fd );
    fcntl( fd, F_SETFD, FD_CLOEXEC );
    return 0;
}
Esempio n. 2
0
// class CHDemo2
//------------------

static ivar_list_t IvarListNamed(CHDemo2)[] = {
    {.ivar[0] = {.ivar_name = selector(_1), .ivar_type = encode<double>(), .ivar_offset = OFFSET(CHDemo2, _1)}}
};

RUNTIMECLASS(CHDemo2);

static class_t ClassNamed(CHDemo2) = {
    0,
    CHTagBuf::getClass(nullptr),
    selector(CHDemo2),
    runtimeclass(CHDemo2)::methods(),
    &ivar_list_CHDemo2[0],
    allocateCache(),
    selector(^#CHDemo2),
    static_cast<uint32_t>((class_registerClass(&ClassNamed(CHDemo2)), sizeof(CHDemo2))),
    1,
    3
};

ImplementTagBuf(CHDemo2);

//------------------
// class CHDemo
//------------------

static ivar_list_t IvarListNamed(CHDemo)[] = {
    {.ivar[0] = {.ivar_name = selector(_1), .ivar_type = encode<decltype(((CHDemo *)0)->_1)>(), .ivar_offset = OFFSET(CHDemo, _1)}},
    {.ivar[0] = {.ivar_name = selector(_2), .ivar_type = "^#CHDemo2", .ivar_offset = OFFSET(CHDemo, _2)}},