comparison src/alloc.c @ 69348:2c8e608f28e7

(USE_POSIX_MEMALIGN): New macro. (ABLOCKS_BASE, lisp_align_malloc, lisp_align_free): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 09 Mar 2006 23:06:58 +0000
parents 977852fb2e3b
children a685fca1ccb6
comparison
equal deleted inserted replaced
69347:f82697609957 69348:2c8e608f28e7
881 881
882 /* Allocation of aligned blocks of memory to store Lisp data. */ 882 /* Allocation of aligned blocks of memory to store Lisp data. */
883 /* The entry point is lisp_align_malloc which returns blocks of at most */ 883 /* The entry point is lisp_align_malloc which returns blocks of at most */
884 /* BLOCK_BYTES and guarantees they are aligned on a BLOCK_ALIGN boundary. */ 884 /* BLOCK_BYTES and guarantees they are aligned on a BLOCK_ALIGN boundary. */
885 885
886 /* Use posix_memalloc if the system has it and we're using the system's
887 malloc (because our gmalloc.c routines don't have posix_memalign although
888 its memalloc could be used). */
889 #define USE_POSIX_MEMALIGN (HAVE_POSIX_MEMALIGN && SYSTEM_MALLOC)
886 890
887 /* BLOCK_ALIGN has to be a power of 2. */ 891 /* BLOCK_ALIGN has to be a power of 2. */
888 #define BLOCK_ALIGN (1 << 10) 892 #define BLOCK_ALIGN (1 << 10)
889 893
890 /* Padding to leave at the end of a malloc'd block. This is to give 894 /* Padding to leave at the end of a malloc'd block. This is to give
946 950
947 /* Virtual `busy' field. */ 951 /* Virtual `busy' field. */
948 #define ABLOCKS_BUSY(abase) ((abase)->blocks[0].abase) 952 #define ABLOCKS_BUSY(abase) ((abase)->blocks[0].abase)
949 953
950 /* Pointer to the (not necessarily aligned) malloc block. */ 954 /* Pointer to the (not necessarily aligned) malloc block. */
951 #ifdef HAVE_POSIX_MEMALIGN 955 #ifdef USE_POSIX_MEMALIGN
952 #define ABLOCKS_BASE(abase) (abase) 956 #define ABLOCKS_BASE(abase) (abase)
953 #else 957 #else
954 #define ABLOCKS_BASE(abase) \ 958 #define ABLOCKS_BASE(abase) \
955 (1 & (long) ABLOCKS_BUSY (abase) ? abase : ((void**)abase)[-1]) 959 (1 & (long) ABLOCKS_BUSY (abase) ? abase : ((void**)abase)[-1])
956 #endif 960 #endif
987 because mapped region contents are not preserved in 991 because mapped region contents are not preserved in
988 a dumped Emacs. */ 992 a dumped Emacs. */
989 mallopt (M_MMAP_MAX, 0); 993 mallopt (M_MMAP_MAX, 0);
990 #endif 994 #endif
991 995
992 #ifdef HAVE_POSIX_MEMALIGN 996 #ifdef USE_POSIX_MEMALIGN
993 { 997 {
994 int err = posix_memalign (&base, BLOCK_ALIGN, ABLOCKS_BYTES); 998 int err = posix_memalign (&base, BLOCK_ALIGN, ABLOCKS_BYTES);
995 if (err) 999 if (err)
996 base = NULL; 1000 base = NULL;
997 abase = base; 1001 abase = base;
1103 else 1107 else
1104 tem = &(*tem)->x.next_free; 1108 tem = &(*tem)->x.next_free;
1105 } 1109 }
1106 eassert ((aligned & 1) == aligned); 1110 eassert ((aligned & 1) == aligned);
1107 eassert (i == (aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1)); 1111 eassert (i == (aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1));
1108 #ifdef HAVE_POSIX_MEMALIGN 1112 #ifdef USE_POSIX_MEMALIGN
1109 eassert ((unsigned long)ABLOCKS_BASE (abase) % BLOCK_ALIGN == 0); 1113 eassert ((unsigned long)ABLOCKS_BASE (abase) % BLOCK_ALIGN == 0);
1110 #endif 1114 #endif
1111 free (ABLOCKS_BASE (abase)); 1115 free (ABLOCKS_BASE (abase));
1112 } 1116 }
1113 UNBLOCK_INPUT; 1117 UNBLOCK_INPUT;