/* shared memory implement */
static MM *mm_create_shm(size_t size) {
MM *p;
p = (MM *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
if (p != (MM *)-1) {
p->size = size;
p->start = (char *)p + sizeof(MM);
}
return p;
}
static void mm_destroy_shm(MM *mm) {
if (mm != NULL && mm != (MM *)-1) {
munmap(mm, mm->size);
}
}
static void mm_init(MM *mm) {
mm->start = MM_ALIGN(mm->start);
mm->lock = mm->start;
mm->start = MM_ALIGN((void *)(((char *)(mm->start)) + sizeof(mm_mutex)));
mm->available = mm->size - (((char *)(mm->start))-(char *)mm);
mm->free_list = (mm_free_bucket *)mm->start;
mm->free_list->size = mm->available;
mm->free_list->next = NULL;
时间:2009-06-13 20:29
来源:chinaunix
作者:hightman
原文链接