aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier2007-09-29 20:10:22 +0000
committerStefan Monnier2007-09-29 20:10:22 +0000
commitdafc79fa1bc62a089e613b5f9753df3789bdfce2 (patch)
tree1214ef4d1efc9b23ac98e337bdd68cbf8979fcff /src
parented0c79c6fd48156b8ff578433f66764c2b68bfed (diff)
downloademacs-dafc79fa1bc62a089e613b5f9753df3789bdfce2.tar.gz
emacs-dafc79fa1bc62a089e613b5f9753df3789bdfce2.zip
(MALLOC_BLOCK_INPUT, MALLOC_UNBLOCK_INPUT): New macros
to avoid unnecessary BLOCK_INPUTs when SYNC_INPUT is used. (xmalloc, xrealloc, xfree, lisp_malloc, lisp_free, lisp_align_malloc) (lisp_align_free, make_interval, allocate_vectorlike, allocate_string_data) (make_float, Fcons, allocate_string, Fmake_symbol, allocate_misc): Use them.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/alloc.c117
2 files changed, 51 insertions, 73 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index d5ca272fe51..33d82ad9b6c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,12 @@
12007-09-29 Stefan Monnier <monnier@iro.umontreal.ca> 12007-09-29 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * alloc.c (MALLOC_BLOCK_INPUT, MALLOC_UNBLOCK_INPUT): New macros
4 to avoid unnecessary BLOCK_INPUTs when SYNC_INPUT is used.
5 (xmalloc, xrealloc, xfree, lisp_malloc, lisp_free, lisp_align_malloc)
6 (lisp_align_free, make_interval, allocate_string, allocate_string_data)
7 (make_float, Fcons, allocate_vectorlike, Fmake_symbol, allocate_misc):
8 Use them.
9
3 * xfaces.c (load_face_font, free_realized_face, clear_face_gcs): 10 * xfaces.c (load_face_font, free_realized_face, clear_face_gcs):
4 Don't let signal handlers run when a GC is freed but not yet NULL'ed. 11 Don't let signal handlers run when a GC is freed but not yet NULL'ed.
5 (x_free_gc): Remove BLOCK_INPUT since it's now redundant. 12 (x_free_gc): Remove BLOCK_INPUT since it's now redundant.
diff --git a/src/alloc.c b/src/alloc.c
index aada45cd93b..245716fe06c 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -748,6 +748,15 @@ overrun_check_free (block)
748#define free overrun_check_free 748#define free overrun_check_free
749#endif 749#endif
750 750
751#ifdef SYNC_INPUT
752/* When using SYNC_INPUT, we don't call malloc from a signal handler, so
753 there's no need to block input around malloc. */
754#define MALLOC_BLOCK_INPUT ((void)0)
755#define MALLOC_UNBLOCK_INPUT ((void)0)
756#else
757#define MALLOC_BLOCK_INPUT BLOCK_INPUT
758#define MALLOC_UNBLOCK_INPUT UNBLOCK_INPUT
759#endif
751 760
752/* Like malloc but check for no memory and block interrupt input.. */ 761/* Like malloc but check for no memory and block interrupt input.. */
753 762
@@ -757,9 +766,9 @@ xmalloc (size)
757{ 766{
758 register POINTER_TYPE *val; 767 register POINTER_TYPE *val;
759 768
760 BLOCK_INPUT; 769 MALLOC_BLOCK_INPUT;
761 val = (POINTER_TYPE *) malloc (size); 770 val = (POINTER_TYPE *) malloc (size);
762 UNBLOCK_INPUT; 771 MALLOC_UNBLOCK_INPUT;
763 772
764 if (!val && size) 773 if (!val && size)
765 memory_full (); 774 memory_full ();
@@ -776,14 +785,14 @@ xrealloc (block, size)
776{ 785{
777 register POINTER_TYPE *val; 786 register POINTER_TYPE *val;
778 787
779 BLOCK_INPUT; 788 MALLOC_BLOCK_INPUT;
780 /* We must call malloc explicitly when BLOCK is 0, since some 789 /* We must call malloc explicitly when BLOCK is 0, since some
781 reallocs don't do this. */ 790 reallocs don't do this. */
782 if (! block) 791 if (! block)
783 val = (POINTER_TYPE *) malloc (size); 792 val = (POINTER_TYPE *) malloc (size);
784 else 793 else
785 val = (POINTER_TYPE *) realloc (block, size); 794 val = (POINTER_TYPE *) realloc (block, size);
786 UNBLOCK_INPUT; 795 MALLOC_UNBLOCK_INPUT;
787 796
788 if (!val && size) memory_full (); 797 if (!val && size) memory_full ();
789 return val; 798 return val;
@@ -796,9 +805,9 @@ void
796xfree (block) 805xfree (block)
797 POINTER_TYPE *block; 806 POINTER_TYPE *block;
798{ 807{
799 BLOCK_INPUT; 808 MALLOC_BLOCK_INPUT;
800 free (block); 809 free (block);
801 UNBLOCK_INPUT; 810 MALLOC_UNBLOCK_INPUT;
802 /* We don't call refill_memory_reserve here 811 /* We don't call refill_memory_reserve here
803 because that duplicates doing so in emacs_blocked_free 812 because that duplicates doing so in emacs_blocked_free
804 and the criterion should go there. */ 813 and the criterion should go there. */
@@ -849,7 +858,7 @@ lisp_malloc (nbytes, type)
849{ 858{
850 register void *val; 859 register void *val;
851 860
852 BLOCK_INPUT; 861 MALLOC_BLOCK_INPUT;
853 862
854#ifdef GC_MALLOC_CHECK 863#ifdef GC_MALLOC_CHECK
855 allocated_mem_type = type; 864 allocated_mem_type = type;
@@ -879,7 +888,7 @@ lisp_malloc (nbytes, type)
879 mem_insert (val, (char *) val + nbytes, type); 888 mem_insert (val, (char *) val + nbytes, type);
880#endif 889#endif
881 890
882 UNBLOCK_INPUT; 891 MALLOC_UNBLOCK_INPUT;
883 if (!val && nbytes) 892 if (!val && nbytes)
884 memory_full (); 893 memory_full ();
885 return val; 894 return val;
@@ -892,12 +901,12 @@ static void
892lisp_free (block) 901lisp_free (block)
893 POINTER_TYPE *block; 902 POINTER_TYPE *block;
894{ 903{
895 BLOCK_INPUT; 904 MALLOC_BLOCK_INPUT;
896 free (block); 905 free (block);
897#if GC_MARK_STACK && !defined GC_MALLOC_CHECK 906#if GC_MARK_STACK && !defined GC_MALLOC_CHECK
898 mem_delete (mem_find (block)); 907 mem_delete (mem_find (block));
899#endif 908#endif
900 UNBLOCK_INPUT; 909 MALLOC_UNBLOCK_INPUT;
901} 910}
902 911
903/* Allocation of aligned blocks of memory to store Lisp data. */ 912/* Allocation of aligned blocks of memory to store Lisp data. */
@@ -998,7 +1007,7 @@ lisp_align_malloc (nbytes, type)
998 1007
999 eassert (nbytes <= BLOCK_BYTES); 1008 eassert (nbytes <= BLOCK_BYTES);
1000 1009
1001 BLOCK_INPUT; 1010 MALLOC_BLOCK_INPUT;
1002 1011
1003#ifdef GC_MALLOC_CHECK 1012#ifdef GC_MALLOC_CHECK
1004 allocated_mem_type = type; 1013 allocated_mem_type = type;
@@ -1030,7 +1039,7 @@ lisp_align_malloc (nbytes, type)
1030 1039
1031 if (base == 0) 1040 if (base == 0)
1032 { 1041 {
1033 UNBLOCK_INPUT; 1042 MALLOC_UNBLOCK_INPUT;
1034 memory_full (); 1043 memory_full ();
1035 } 1044 }
1036 1045
@@ -1056,7 +1065,7 @@ lisp_align_malloc (nbytes, type)
1056 { 1065 {
1057 lisp_malloc_loser = base; 1066 lisp_malloc_loser = base;
1058 free (base); 1067 free (base);
1059 UNBLOCK_INPUT; 1068 MALLOC_UNBLOCK_INPUT;
1060 memory_full (); 1069 memory_full ();
1061 } 1070 }
1062 } 1071 }
@@ -1089,7 +1098,7 @@ lisp_align_malloc (nbytes, type)
1089 mem_insert (val, (char *) val + nbytes, type); 1098 mem_insert (val, (char *) val + nbytes, type);
1090#endif 1099#endif
1091 1100
1092 UNBLOCK_INPUT; 1101 MALLOC_UNBLOCK_INPUT;
1093 if (!val && nbytes) 1102 if (!val && nbytes)
1094 memory_full (); 1103 memory_full ();
1095 1104
@@ -1104,7 +1113,7 @@ lisp_align_free (block)
1104 struct ablock *ablock = block; 1113 struct ablock *ablock = block;
1105 struct ablocks *abase = ABLOCK_ABASE (ablock); 1114 struct ablocks *abase = ABLOCK_ABASE (ablock);
1106 1115
1107 BLOCK_INPUT; 1116 MALLOC_BLOCK_INPUT;
1108#if GC_MARK_STACK && !defined GC_MALLOC_CHECK 1117#if GC_MARK_STACK && !defined GC_MALLOC_CHECK
1109 mem_delete (mem_find (block)); 1118 mem_delete (mem_find (block));
1110#endif 1119#endif
@@ -1137,7 +1146,7 @@ lisp_align_free (block)
1137#endif 1146#endif
1138 free (ABLOCKS_BASE (abase)); 1147 free (ABLOCKS_BASE (abase));
1139 } 1148 }
1140 UNBLOCK_INPUT; 1149 MALLOC_UNBLOCK_INPUT;
1141} 1150}
1142 1151
1143/* Return a new buffer structure allocated from the heap with 1152/* Return a new buffer structure allocated from the heap with
@@ -1166,6 +1175,8 @@ allocate_buffer ()
1166 can use GNU malloc. */ 1175 can use GNU malloc. */
1167 1176
1168#ifndef SYNC_INPUT 1177#ifndef SYNC_INPUT
1178/* When using SYNC_INPUT, we don't call malloc from a signal handler, so
1179 there's no need to block input around malloc. */
1169 1180
1170#ifndef DOUG_LEA_MALLOC 1181#ifndef DOUG_LEA_MALLOC
1171extern void * (*__malloc_hook) P_ ((size_t, const void *)); 1182extern void * (*__malloc_hook) P_ ((size_t, const void *));
@@ -1450,9 +1461,7 @@ make_interval ()
1450 1461
1451 /* eassert (!handling_signal); */ 1462 /* eassert (!handling_signal); */
1452 1463
1453#ifndef SYNC_INPUT 1464 MALLOC_BLOCK_INPUT;
1454 BLOCK_INPUT;
1455#endif
1456 1465
1457 if (interval_free_list) 1466 if (interval_free_list)
1458 { 1467 {
@@ -1476,9 +1485,7 @@ make_interval ()
1476 val = &interval_block->intervals[interval_block_index++]; 1485 val = &interval_block->intervals[interval_block_index++];
1477 } 1486 }
1478 1487
1479#ifndef SYNC_INPUT 1488 MALLOC_UNBLOCK_INPUT;
1480 UNBLOCK_INPUT;
1481#endif
1482 1489
1483 consing_since_gc += sizeof (struct interval); 1490 consing_since_gc += sizeof (struct interval);
1484 intervals_consed++; 1491 intervals_consed++;
@@ -1881,9 +1888,7 @@ allocate_string ()
1881 1888
1882 /* eassert (!handling_signal); */ 1889 /* eassert (!handling_signal); */
1883 1890
1884#ifndef SYNC_INPUT 1891 MALLOC_BLOCK_INPUT;
1885 BLOCK_INPUT;
1886#endif
1887 1892
1888 /* If the free-list is empty, allocate a new string_block, and 1893 /* If the free-list is empty, allocate a new string_block, and
1889 add all the Lisp_Strings in it to the free-list. */ 1894 add all the Lisp_Strings in it to the free-list. */
@@ -1914,9 +1919,7 @@ allocate_string ()
1914 s = string_free_list; 1919 s = string_free_list;
1915 string_free_list = NEXT_FREE_LISP_STRING (s); 1920 string_free_list = NEXT_FREE_LISP_STRING (s);
1916 1921
1917#ifndef SYNC_INPUT 1922 MALLOC_UNBLOCK_INPUT;
1918 UNBLOCK_INPUT;
1919#endif
1920 1923
1921 /* Probably not strictly necessary, but play it safe. */ 1924 /* Probably not strictly necessary, but play it safe. */
1922 bzero (s, sizeof *s); 1925 bzero (s, sizeof *s);
@@ -1968,9 +1971,7 @@ allocate_string_data (s, nchars, nbytes)
1968 old_data = s->data ? SDATA_OF_STRING (s) : NULL; 1971 old_data = s->data ? SDATA_OF_STRING (s) : NULL;
1969 old_nbytes = GC_STRING_BYTES (s); 1972 old_nbytes = GC_STRING_BYTES (s);
1970 1973
1971#ifndef SYNC_INPUT 1974 MALLOC_BLOCK_INPUT;
1972 BLOCK_INPUT;
1973#endif
1974 1975
1975 if (nbytes > LARGE_STRING_BYTES) 1976 if (nbytes > LARGE_STRING_BYTES)
1976 { 1977 {
@@ -1986,18 +1987,14 @@ allocate_string_data (s, nchars, nbytes)
1986 mmap'ed data typically have an address towards the top of the 1987 mmap'ed data typically have an address towards the top of the
1987 address space, which won't fit into an EMACS_INT (at least on 1988 address space, which won't fit into an EMACS_INT (at least on
1988 32-bit systems with the current tagging scheme). --fx */ 1989 32-bit systems with the current tagging scheme). --fx */
1989 BLOCK_INPUT;
1990 mallopt (M_MMAP_MAX, 0); 1990 mallopt (M_MMAP_MAX, 0);
1991 UNBLOCK_INPUT;
1992#endif 1991#endif
1993 1992
1994 b = (struct sblock *) lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP); 1993 b = (struct sblock *) lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP);
1995 1994
1996#ifdef DOUG_LEA_MALLOC 1995#ifdef DOUG_LEA_MALLOC
1997 /* Back to a reasonable maximum of mmap'ed areas. */ 1996 /* Back to a reasonable maximum of mmap'ed areas. */
1998 BLOCK_INPUT;
1999 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); 1997 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS);
2000 UNBLOCK_INPUT;
2001#endif 1998#endif
2002 1999
2003 b->next_free = &b->first_data; 2000 b->next_free = &b->first_data;
@@ -2028,9 +2025,7 @@ allocate_string_data (s, nchars, nbytes)
2028 data = b->next_free; 2025 data = b->next_free;
2029 b->next_free = (struct sdata *) ((char *) data + needed + GC_STRING_EXTRA); 2026 b->next_free = (struct sdata *) ((char *) data + needed + GC_STRING_EXTRA);
2030 2027
2031#ifndef SYNC_INPUT 2028 MALLOC_UNBLOCK_INPUT;
2032 UNBLOCK_INPUT;
2033#endif
2034 2029
2035 data->string = s; 2030 data->string = s;
2036 s->data = SDATA_DATA (data); 2031 s->data = SDATA_DATA (data);
@@ -2619,9 +2614,7 @@ make_float (float_value)
2619 2614
2620 /* eassert (!handling_signal); */ 2615 /* eassert (!handling_signal); */
2621 2616
2622#ifndef SYNC_INPUT 2617 MALLOC_BLOCK_INPUT;
2623 BLOCK_INPUT;
2624#endif
2625 2618
2626 if (float_free_list) 2619 if (float_free_list)
2627 { 2620 {
@@ -2648,9 +2641,7 @@ make_float (float_value)
2648 float_block_index++; 2641 float_block_index++;
2649 } 2642 }
2650 2643
2651#ifndef SYNC_INPUT 2644 MALLOC_UNBLOCK_INPUT;
2652 UNBLOCK_INPUT;
2653#endif
2654 2645
2655 XFLOAT_DATA (val) = float_value; 2646 XFLOAT_DATA (val) = float_value;
2656 eassert (!FLOAT_MARKED_P (XFLOAT (val))); 2647 eassert (!FLOAT_MARKED_P (XFLOAT (val)));
@@ -2748,9 +2739,7 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
2748 2739
2749 /* eassert (!handling_signal); */ 2740 /* eassert (!handling_signal); */
2750 2741
2751#ifndef SYNC_INPUT 2742 MALLOC_BLOCK_INPUT;
2752 BLOCK_INPUT;
2753#endif
2754 2743
2755 if (cons_free_list) 2744 if (cons_free_list)
2756 { 2745 {
@@ -2776,9 +2765,7 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
2776 cons_block_index++; 2765 cons_block_index++;
2777 } 2766 }
2778 2767
2779#ifndef SYNC_INPUT 2768 MALLOC_UNBLOCK_INPUT;
2780 UNBLOCK_INPUT;
2781#endif
2782 2769
2783 XSETCAR (val, car); 2770 XSETCAR (val, car);
2784 XSETCDR (val, cdr); 2771 XSETCDR (val, cdr);
@@ -2935,13 +2922,13 @@ allocate_vectorlike (len, type)
2935 struct Lisp_Vector *p; 2922 struct Lisp_Vector *p;
2936 size_t nbytes; 2923 size_t nbytes;
2937 2924
2925 MALLOC_BLOCK_INPUT;
2926
2938#ifdef DOUG_LEA_MALLOC 2927#ifdef DOUG_LEA_MALLOC
2939 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed 2928 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed
2940 because mapped region contents are not preserved in 2929 because mapped region contents are not preserved in
2941 a dumped Emacs. */ 2930 a dumped Emacs. */
2942 BLOCK_INPUT;
2943 mallopt (M_MMAP_MAX, 0); 2931 mallopt (M_MMAP_MAX, 0);
2944 UNBLOCK_INPUT;
2945#endif 2932#endif
2946 2933
2947 /* This gets triggered by code which I haven't bothered to fix. --Stef */ 2934 /* This gets triggered by code which I haven't bothered to fix. --Stef */
@@ -2952,24 +2939,16 @@ allocate_vectorlike (len, type)
2952 2939
2953#ifdef DOUG_LEA_MALLOC 2940#ifdef DOUG_LEA_MALLOC
2954 /* Back to a reasonable maximum of mmap'ed areas. */ 2941 /* Back to a reasonable maximum of mmap'ed areas. */
2955 BLOCK_INPUT;
2956 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); 2942 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS);
2957 UNBLOCK_INPUT;
2958#endif 2943#endif
2959 2944
2960 consing_since_gc += nbytes; 2945 consing_since_gc += nbytes;
2961 vector_cells_consed += len; 2946 vector_cells_consed += len;
2962 2947
2963#ifndef SYNC_INPUT
2964 BLOCK_INPUT;
2965#endif
2966
2967 p->next = all_vectors; 2948 p->next = all_vectors;
2968 all_vectors = p; 2949 all_vectors = p;
2969 2950
2970#ifndef SYNC_INPUT 2951 MALLOC_UNBLOCK_INPUT;
2971 UNBLOCK_INPUT;
2972#endif
2973 2952
2974 ++n_vectors; 2953 ++n_vectors;
2975 return p; 2954 return p;
@@ -3277,9 +3256,7 @@ Its value and function definition are void, and its property list is nil. */)
3277 3256
3278 /* eassert (!handling_signal); */ 3257 /* eassert (!handling_signal); */
3279 3258
3280#ifndef SYNC_INPUT 3259 MALLOC_BLOCK_INPUT;
3281 BLOCK_INPUT;
3282#endif
3283 3260
3284 if (symbol_free_list) 3261 if (symbol_free_list)
3285 { 3262 {
@@ -3302,9 +3279,7 @@ Its value and function definition are void, and its property list is nil. */)
3302 symbol_block_index++; 3279 symbol_block_index++;
3303 } 3280 }
3304 3281
3305#ifndef SYNC_INPUT 3282 MALLOC_UNBLOCK_INPUT;
3306 UNBLOCK_INPUT;
3307#endif
3308 3283
3309 p = XSYMBOL (val); 3284 p = XSYMBOL (val);
3310 p->xname = name; 3285 p->xname = name;
@@ -3367,9 +3342,7 @@ allocate_misc ()
3367 3342
3368 /* eassert (!handling_signal); */ 3343 /* eassert (!handling_signal); */
3369 3344
3370#ifndef SYNC_INPUT 3345 MALLOC_BLOCK_INPUT;
3371 BLOCK_INPUT;
3372#endif
3373 3346
3374 if (marker_free_list) 3347 if (marker_free_list)
3375 { 3348 {
@@ -3393,9 +3366,7 @@ allocate_misc ()
3393 marker_block_index++; 3366 marker_block_index++;
3394 } 3367 }
3395 3368
3396#ifndef SYNC_INPUT 3369 MALLOC_UNBLOCK_INPUT;
3397 UNBLOCK_INPUT;
3398#endif
3399 3370
3400 --total_free_markers; 3371 --total_free_markers;
3401 consing_since_gc += sizeof (union Lisp_Misc); 3372 consing_since_gc += sizeof (union Lisp_Misc);