进程描述符 哈希值
/********************************************************************************函数名称:static s32 hash_it(void *x)
*函数功能:计算任意指针的哈希值,用于在hash链表中快速找到任务进程对应的内核结构体
*输入参数:无
*输出参数:无
*函数返回值:static s32:计算的哈希值
*其他:无
*******************************************************************************/
static s32 hash_it(void *x)
{
u32 tmp = (u32)x;
tmp = tmp ^ (tmp >> MAP_SHIFT) ^ (tmp >> (MAP_SHIFT * 2));
return (s32)(tmp % MAP_SIZE);
}
/*******************************************************************************
*函数名称:void *hash_find(struct task_struct *task)
*函数功能:根据进程task结构指针的哈希值找出对应的子进程结构
*输入参数:
@struct task_struct *task:进程task结构指针
*输出参数:无
*函数返回值:void *:子进程结构指针
*其他:无
*******************************************************************************/
void *hash_find(struct task_struct *task)
{
s32 index = hash_it(task);
struct p_body_s *body = NULL;
list_for_each_entry(body, &hashmap.table.list, hash_process)
{//遍历hash表
if (body->mypid ==task->pid && body->myself == task)
{ /*find it */
return (void *)body;
}
}
return (void *)0; 我的问题是哈希函数是咋出来的??
MAP_SHIFT 6
MAP_SIZE 64
页:
[1]