size_t mm_maxsize(MM *mm) {
size_t ret = MM_SIZE(0);
mm_free_bucket *p;
if (!mm_lock(mm)) {
return 0;
}
p = mm->free_list;
while (p != NULL) {
if (p->size > ret) {
ret = p->size;
}
p = p->next;
}
mm_unlock(mm);
return ret - MM_SIZE(0);
}
void *mm_malloc(MM *mm, size_t size) {
void *ret;
if (!mm_lock(mm)) {
return NULL;
}
ret = mm_malloc_nolock(mm,size);
mm_unlock(mm);
return ret;
}
void mm_free(MM *mm, void *x) {
mm_lock(mm);
mm_free_nolock(mm, x);
mm_unlock(mm);
}
MM *mm_create(size_t size) {
MM *p;
if (size == 0) {
size = 32 * 1024 * 1024;
}
p = mm_create_shm(size);
if (p == (MM *)-1) {
return NULL;
}
时间:2009-06-13 20:29
来源:chinaunix
作者:hightman
原文链接