#define HEAD_TO_PTR(p) ((void *)(((mm_mem_head *)(p)) + 1))
#define MM mm_core
#define MM_WORD mm_mem_head
#if (defined (__GNUC__) && __GNUC__ >= 2)
# define MM_PLATFORM_ALIGNMENT (__alignof__ (MM_WORD))
#else
# define MM_PLATFORM_ALIGNMENT (sizeof(MM_WORD))
#endif
#define MM_ALIGN(n) (void*)((((size_t)(n)-1) & ~(MM_PLATFORM_ALIGNMENT-1)) + MM_PLATFORM_ALIGNMENT)
#include "mm.h"
/* MM-lock implement */
static int mm_init_lock(mm_mutex *lock) {
union semun arg;
int n = MM_SEM_NUM;
if ((lock->semid = semget(IPC_PRIVATE, n, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR)) < 0) {
return 0;
}
arg.val = 1;
while (n--) {
if (semctl(lock->semid, n, SETVAL, arg) < 0) {
semctl(lock->semid, n, IPC_RMID, 0);
}
}
return 1;
时间:2009-06-13 20:29
来源:chinaunix
作者:hightman
原文链接