diff options
author | Karl Berry <karl@freefriends.org> | 2014-10-17 17:17:21 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-10-17 17:17:21 +0000 |
commit | 24bc05bb324bf123528e1c8ed342552547dee874 (patch) | |
tree | 9056aeea4e39758b160cbef70a198e725f76e50d /Build | |
parent | 0bfbfdf13aeae8e5a970f277e2982d14b8250f6c (diff) |
use flockfile/getc_unlocked/funlockfile instead of getc
git-svn-id: svn://tug.org/texlive/trunk@35390 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build')
-rw-r--r-- | Build/source/texk/kpathsea/ChangeLog | 7 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/line.c | 24 |
2 files changed, 29 insertions, 2 deletions
diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog index 3caff43c20c..bb68c836caa 100644 --- a/Build/source/texk/kpathsea/ChangeLog +++ b/Build/source/texk/kpathsea/ChangeLog @@ -1,3 +1,10 @@ +2014-10-17 Karl Berry <karl@tug.org> + + * line.c (getc, FLOCKFILE, FUNLOCKFILE): #define to getc_unlocked, etc. + (get_line): call them, so we lock once per call instead of + once per character read. Change from Adam Maxwell <amaxwell@mac.com>. + https://email.esm.psu.edu/pipermail/macosx-tex/2014-October/053026.html + 2014-09-16 Peter Breitenlohner <peb@mppmu.mpg.de> * texmf.cnf (TEX.upmpost): Added. diff --git a/Build/source/texk/kpathsea/line.c b/Build/source/texk/kpathsea/line.c index b221a4032dc..6c66a302b7f 100644 --- a/Build/source/texk/kpathsea/line.c +++ b/Build/source/texk/kpathsea/line.c @@ -1,6 +1,6 @@ /* line.c: return the next line from a file, or NULL. - Copyright 1992, 1993, 1995, 1996, 2008, 2013 Karl Berry. + Copyright 1992, 1993, 1995, 1996, 2008, 2013, 2014 Karl Berry. Copyright 1998, 1999, 2001, 2005 Olaf Weber. This library is free software; you can redistribute it and/or @@ -18,12 +18,28 @@ #include <kpathsea/config.h> #include <kpathsea/line.h> + #ifdef WIN32 #undef getc #undef ungetc #define getc win32_getc #define ungetc win32_ungetc -#endif +#define FLOCKFILE(x) +#define FUNLOCKFILE(x) + +#else /* not WIN32 */ +/* By POSIX, getc() has to be thread-safe, which means (un)locking on + every character read. It is much faster to lock the stream (once), + use getc_unlocked to read, and then unlock the stream. We need to be + thread-safe especially for the sake of MPlib. + + Perhaps we will be lucky enough to be able to do this + unconditionally, without checking in configure. We'll see. */ +#undef getc +#define getc getc_unlocked +#define FLOCKFILE(x) flockfile(x) +#define FUNLOCKFILE(x) funlockfile(x) +#endif /* not WIN32 */ /* Allocate in increments of this size. */ #define BLOCK_SIZE 75 @@ -35,6 +51,8 @@ read_line (FILE *f) unsigned limit = BLOCK_SIZE; unsigned loc = 0; char *line = xmalloc (limit); + + FLOCKFILE (f); while ((c = getc (f)) != EOF && c != '\n' && c != '\r') { line[loc] = c; @@ -67,6 +85,8 @@ read_line (FILE *f) } } } + + FUNLOCKFILE (f); return line; } |