Skip to content

Commit 9ac59e5

Browse files
committed
dont call fflush for each line written when generating a tmp file
fclose contains a fflush or equivelent call per posix/C. Calling fflush after every line will mean <=80 byte writes to the disk/FS driver/kernel. Calling fflush after every write of a line console is understandable, for a disk it isn't. By removing/merging the fflush with fclose, in most cases the entire temp file will be buffered in stdio in user mode and sent to the kernel only when the file is closed. Move the error check to fclose. On VS >= 2005, this also means that the MT lock will be aquired once for the fclose, not once (or more) for fflush then again for fclose. My test workload for dmake (a perl build) makes 3 temp files per "dmake all". The number of fflush calls was reduced from 140 to 137 with this patch. The number of WriteFile calls stayed the same at 145, probably since the temp files are 1 line long. The majority of fflush calls are writing to console in my workload.
1 parent b01c3fa commit 9ac59e5

42 files changed

Lines changed: 92 additions & 96 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

function.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ char *data;
392392

393393
data = Expand(data);
394394

395-
Append_line( data, TRUE, tmpfile, name, FALSE, FALSE );
396-
Close_temp( Current_target, tmpfile );
395+
Append_line( data, TRUE, tmpfile, FALSE, FALSE );
396+
Close_temp( Current_target, tmpfile, name );
397397
FREE(data);
398398

399399
return( text );

mac/public.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int Exec_commands ANSI((CELLPTR));
5959
void Print_cmnd ANSI((char *, int, int));
6060
int Push_dir ANSI((char *, char *, int));
6161
void Pop_dir ANSI((int));
62-
void Append_line ANSI((char *, int, FILE *, char *, int, int));
62+
void Append_line ANSI((char *, int, FILE *, int, int));
6363
void Stat_target ANSI((CELLPTR, int, int));
6464
char *Expand ANSI((char *));
6565
char *Apply_edit ANSI((char *, char *, char *, int, int));
@@ -128,7 +128,7 @@ FILE* Get_temp ANSI((char **, char *));
128128
FILE *Start_temp ANSI((char *, CELLPTR, char **));
129129
void Open_temp_error ANSI((char *, char *));
130130
void Link_temp ANSI((CELLPTR, FILE *, char *));
131-
void Close_temp ANSI((CELLPTR, FILE *));
131+
void Close_temp ANSI((CELLPTR, FILE *, char *));
132132
void Unlink_temp_files ANSI((CELLPTR));
133133
void Handle_result ANSI((int, int, int, CELLPTR));
134134
void Update_time_stamp ANSI((CELLPTR));

make.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct {
5454
static void _drop_mac ANSI((HASHPTR));
5555
static void _set_recipe ANSI((char*, int));
5656
static void _set_tmd ANSI(());
57-
static void _append_file ANSI((STRINGPTR, FILE*, char*, int));
57+
static void _append_file ANSI((STRINGPTR, FILE*, int));
5858
static LINKPTR _dup_prq ANSI((LINKPTR));
5959
static LINKPTR _expand_dynamic_prq ANSI(( LINKPTR, LINKPTR, char * ));
6060
static char* _prefix ANSI((char *, char *));
@@ -1316,7 +1316,7 @@ CELLPTR cp;
13161316

13171317
/* Emit group prolog */
13181318
if( attr & A_PROLOG )
1319-
_append_file( _recipes[RP_GPPROLOG], tmpfile, cp->CE_NAME, trace );
1319+
_append_file( _recipes[RP_GPPROLOG], tmpfile, trace );
13201320
}
13211321

13221322
if( !useshell )
@@ -1420,7 +1420,7 @@ CELLPTR cp;
14201420

14211421
if( group )
14221422
/* Append_line() calls Print_cmnd(). */
1423-
Append_line( cmnd, TRUE, tmpfile, cp->CE_NAME, trace, 0 );
1423+
Append_line( cmnd, TRUE, tmpfile, trace, 0 );
14241424
else {
14251425
/* Don't print empty recipe lines. .ROOT and .TARGETS
14261426
* deliberately might have empty "" recipes and we don't want
@@ -1440,14 +1440,14 @@ CELLPTR cp;
14401440
* execute the command */
14411441
if( group && !(cp->ce_attr & A_ERROR) ) {
14421442
if( attr & A_EPILOG ) /* emit epilog */
1443-
_append_file( _recipes[RP_GPEPILOG], tmpfile, cp->CE_NAME, trace );
1443+
_append_file( _recipes[RP_GPEPILOG], tmpfile, trace );
14441444

14451445
if( trace ) fputs("]\n", stdout);
14461446

14471447
do_it = !Trace;
14481448
if( do_it )
14491449
{
1450-
Close_temp( cp, tmpfile );
1450+
Close_temp( cp, tmpfile, cp->CE_NAME );
14511451
#if defined(UNIX)
14521452

14531453
chmod(groupfile,0700);
@@ -1656,11 +1656,10 @@ int ind;
16561656

16571657

16581658
PUBLIC void
1659-
Append_line( cmnd, newline, tmpfile, name, printit, map )
1659+
Append_line( cmnd, newline, tmpfile, printit, map )
16601660
char *cmnd;
16611661
int newline;
16621662
FILE *tmpfile;
1663-
char *name;
16641663
int printit;
16651664
int map;
16661665
{
@@ -1670,25 +1669,20 @@ int map;
16701669

16711670
fputs(cmnd, tmpfile);
16721671
if( newline ) fputc('\n', tmpfile);
1673-
fflush(tmpfile);
1674-
1675-
if( ferror(tmpfile) )
1676-
Fatal("Write error on temporary file, while processing `%s'", name);
16771672
}
16781673

16791674

16801675

16811676
static void
1682-
_append_file( rp, tmpfile, name, printit )
1677+
_append_file( rp, tmpfile, printit )
16831678
register STRINGPTR rp;
16841679
FILE *tmpfile;
1685-
char *name;
16861680
int printit;
16871681
{
16881682
char *cmnd;
16891683

16901684
while( rp != NIL(STRING) ) {
1691-
Append_line(cmnd = Expand(rp->st_string), TRUE, tmpfile, name, printit,0);
1685+
Append_line(cmnd = Expand(rp->st_string), TRUE, tmpfile, printit,0);
16921686
FREE(cmnd);
16931687
rp = rp->st_next;
16941688
}

msdos/borland/bcc30/public.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int Exec_commands ANSI((CELLPTR));
5959
void Print_cmnd ANSI((char *, int, int));
6060
int Push_dir ANSI((char *, char *, int));
6161
void Pop_dir ANSI((int));
62-
void Append_line ANSI((char *, int, FILE *, char *, int, int));
62+
void Append_line ANSI((char *, int, FILE *, int, int));
6363
void Stat_target ANSI((CELLPTR, int, int));
6464
char *Expand ANSI((char *));
6565
char *Apply_edit ANSI((char *, char *, char *, int, int));
@@ -128,7 +128,7 @@ FILE* Get_temp ANSI((char **, char *));
128128
FILE *Start_temp ANSI((char *, CELLPTR, char **));
129129
void Open_temp_error ANSI((char *, char *));
130130
void Link_temp ANSI((CELLPTR, FILE *, char *));
131-
void Close_temp ANSI((CELLPTR, FILE *));
131+
void Close_temp ANSI((CELLPTR, FILE *, char *));
132132
void Unlink_temp_files ANSI((CELLPTR));
133133
void Handle_result ANSI((int, int, int, CELLPTR));
134134
void Update_time_stamp ANSI((CELLPTR));

msdos/borland/bcc40/public.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int Exec_commands ANSI((CELLPTR));
5959
void Print_cmnd ANSI((char *, int, int));
6060
int Push_dir ANSI((char *, char *, int));
6161
void Pop_dir ANSI((int));
62-
void Append_line ANSI((char *, int, FILE *, char *, int, int));
62+
void Append_line ANSI((char *, int, FILE *, int, int));
6363
void Stat_target ANSI((CELLPTR, int, int));
6464
char *Expand ANSI((char *));
6565
char *Apply_edit ANSI((char *, char *, char *, int, int));
@@ -128,7 +128,7 @@ FILE* Get_temp ANSI((char **, char *));
128128
FILE *Start_temp ANSI((char *, CELLPTR, char **));
129129
void Open_temp_error ANSI((char *, char *));
130130
void Link_temp ANSI((CELLPTR, FILE *, char *));
131-
void Close_temp ANSI((CELLPTR, FILE *));
131+
void Close_temp ANSI((CELLPTR, FILE *, char *));
132132
void Unlink_temp_files ANSI((CELLPTR));
133133
void Handle_result ANSI((int, int, int, CELLPTR));
134134
void Update_time_stamp ANSI((CELLPTR));

msdos/borland/bcc45/public.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int Exec_commands ANSI((CELLPTR));
5959
void Print_cmnd ANSI((char *, int, int));
6060
int Push_dir ANSI((char *, char *, int));
6161
void Pop_dir ANSI((int));
62-
void Append_line ANSI((char *, int, FILE *, char *, int, int));
62+
void Append_line ANSI((char *, int, FILE *, int, int));
6363
void Stat_target ANSI((CELLPTR, int, int));
6464
char *Expand ANSI((char *));
6565
char *Apply_edit ANSI((char *, char *, char *, int, int));
@@ -128,7 +128,7 @@ FILE* Get_temp ANSI((char **, char *));
128128
FILE *Start_temp ANSI((char *, CELLPTR, char **));
129129
void Open_temp_error ANSI((char *, char *));
130130
void Link_temp ANSI((CELLPTR, FILE *, char *));
131-
void Close_temp ANSI((CELLPTR, FILE *));
131+
void Close_temp ANSI((CELLPTR, FILE *, char *));
132132
void Unlink_temp_files ANSI((CELLPTR));
133133
void Handle_result ANSI((int, int, int, CELLPTR));
134134
void Update_time_stamp ANSI((CELLPTR));

msdos/borland/bcc50/public.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int Exec_commands ANSI((CELLPTR));
5959
void Print_cmnd ANSI((char *, int, int));
6060
int Push_dir ANSI((char *, char *, int));
6161
void Pop_dir ANSI((int));
62-
void Append_line ANSI((char *, int, FILE *, char *, int, int));
62+
void Append_line ANSI((char *, int, FILE *, int, int));
6363
void Stat_target ANSI((CELLPTR, int, int));
6464
char *Expand ANSI((char *));
6565
char *Apply_edit ANSI((char *, char *, char *, int, int));
@@ -128,7 +128,7 @@ FILE* Get_temp ANSI((char **, char *));
128128
FILE *Start_temp ANSI((char *, CELLPTR, char **));
129129
void Open_temp_error ANSI((char *, char *));
130130
void Link_temp ANSI((CELLPTR, FILE *, char *));
131-
void Close_temp ANSI((CELLPTR, FILE *));
131+
void Close_temp ANSI((CELLPTR, FILE *, char *));
132132
void Unlink_temp_files ANSI((CELLPTR));
133133
void Handle_result ANSI((int, int, int, CELLPTR));
134134
void Update_time_stamp ANSI((CELLPTR));

msdos/borland/tcc20/public.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int Exec_commands ANSI((CELLPTR));
5959
void Print_cmnd ANSI((char *, int, int));
6060
int Push_dir ANSI((char *, char *, int));
6161
void Pop_dir ANSI((int));
62-
void Append_line ANSI((char *, int, FILE *, char *, int, int));
62+
void Append_line ANSI((char *, int, FILE *, int, int));
6363
void Stat_target ANSI((CELLPTR, int, int));
6464
char *Expand ANSI((char *));
6565
char *Apply_edit ANSI((char *, char *, char *, int, int));
@@ -128,7 +128,7 @@ FILE* Get_temp ANSI((char **, char *));
128128
FILE *Start_temp ANSI((char *, CELLPTR, char **));
129129
void Open_temp_error ANSI((char *, char *));
130130
void Link_temp ANSI((CELLPTR, FILE *, char *));
131-
void Close_temp ANSI((CELLPTR, FILE *));
131+
void Close_temp ANSI((CELLPTR, FILE *, char *));
132132
void Unlink_temp_files ANSI((CELLPTR));
133133
void Handle_result ANSI((int, int, int, CELLPTR));
134134
void Update_time_stamp ANSI((CELLPTR));

msdos/microsft/msc51/public.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int Exec_commands ANSI((CELLPTR));
5959
void Print_cmnd ANSI((char *, int, int));
6060
int Push_dir ANSI((char *, char *, int));
6161
void Pop_dir ANSI((int));
62-
void Append_line ANSI((char *, int, FILE *, char *, int, int));
62+
void Append_line ANSI((char *, int, FILE *, int, int));
6363
void Stat_target ANSI((CELLPTR, int, int));
6464
char *Expand ANSI((char *));
6565
char *Apply_edit ANSI((char *, char *, char *, int, int));
@@ -128,7 +128,7 @@ FILE* Get_temp ANSI((char **, char *));
128128
FILE *Start_temp ANSI((char *, CELLPTR, char **));
129129
void Open_temp_error ANSI((char *, char *));
130130
void Link_temp ANSI((CELLPTR, FILE *, char *));
131-
void Close_temp ANSI((CELLPTR, FILE *));
131+
void Close_temp ANSI((CELLPTR, FILE *, char *));
132132
void Unlink_temp_files ANSI((CELLPTR));
133133
void Handle_result ANSI((int, int, int, CELLPTR));
134134
void Update_time_stamp ANSI((CELLPTR));

msdos/microsft/msc60/public.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int Exec_commands ANSI((CELLPTR));
5959
void Print_cmnd ANSI((char *, int, int));
6060
int Push_dir ANSI((char *, char *, int));
6161
void Pop_dir ANSI((int));
62-
void Append_line ANSI((char *, int, FILE *, char *, int, int));
62+
void Append_line ANSI((char *, int, FILE *, int, int));
6363
void Stat_target ANSI((CELLPTR, int, int));
6464
char *Expand ANSI((char *));
6565
char *Apply_edit ANSI((char *, char *, char *, int, int));
@@ -128,7 +128,7 @@ FILE* Get_temp ANSI((char **, char *));
128128
FILE *Start_temp ANSI((char *, CELLPTR, char **));
129129
void Open_temp_error ANSI((char *, char *));
130130
void Link_temp ANSI((CELLPTR, FILE *, char *));
131-
void Close_temp ANSI((CELLPTR, FILE *));
131+
void Close_temp ANSI((CELLPTR, FILE *, char *));
132132
void Unlink_temp_files ANSI((CELLPTR));
133133
void Handle_result ANSI((int, int, int, CELLPTR));
134134
void Update_time_stamp ANSI((CELLPTR));

0 commit comments

Comments
 (0)