src/libruntime/rmem/cache.c
/**
 * @brief Searches for a page in the cache.
 *
 * @param pgnum Number of the target page.
 *
 * @returns Upon successful completion, the page index is
 * returned. Upon failure a negative error code is returned instead.
 */
@brief Searches for a page in the cache.
@param pgnum Number of the target page.

@returns Upon successful completion, the page index is
returned. Upon failure a negative error code is returned instead.
@brief Searches for a page in the cache . @param pgnum Number of the target page . @returns Upon successful completion the page index is returned . Upon failure a negative error code is returned instead .
static int nanvix_rcache_page_search(rpage_t pgnum)
{
	cache_time++;
	int pgnum_block;
	for (int i = 0; i < RMEM_CACHE_LENGTH; i++)
	{
		pgnum_block = (int)(pgnum) - (int)(cache_lines[i*RMEM_CACHE_BLOCK_SIZE].pgnum);
		if (pgnum_block >= 0 && pgnum_block < RMEM_CACHE_BLOCK_SIZE && cache_lines[i*RMEM_CACHE_BLOCK_SIZE].pgnum != RMEM_NULL)
		{
			for (int j = 0; j < RMEM_CACHE_BLOCK_SIZE; j++)
			{
				if (cache_lines[i*RMEM_CACHE_BLOCK_SIZE+j].pgnum == pgnum)
				{
					return (i*RMEM_CACHE_BLOCK_SIZE+j);
				}
			}
		}
	}
	return (-EFAULT);
}
static int nanvix_rcache_page_search ( rpage_t pgnum ) { cache_time ++ ; int pgnum_block ; for ( int i = 0 ; i < RMEM_CACHE_LENGTH ; i ++ ) { pgnum_block = ( int ) ( pgnum ) - ( int ) ( cache_lines [ i * RMEM_CACHE_BLOCK_SIZE ] . pgnum ) ; if ( pgnum_block >= 0 && pgnum_block < RMEM_CACHE_BLOCK_SIZE && cache_lines [ i * RMEM_CACHE_BLOCK_SIZE ] . pgnum != RMEM_NULL ) { for ( int j = 0 ; j < RMEM_CACHE_BLOCK_SIZE ; j ++ ) { if ( cache_lines [ i * RMEM_CACHE_BLOCK_SIZE + j ] . pgnum == pgnum ) { return ( i * RMEM_CACHE_BLOCK_SIZE + j ) ; } } } } return ( - EFAULT ) ; }
@brief Searches for a page in the cache.
@brief Searches for a page in the cache .