From 1d026619ef5f098a0349ba2fa1b29d5697718bad Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Tue, 20 Nov 2007 14:08:59 +0000 Subject: Move file locking into the RTS, fixing #629, #1109 File locking (of the Haskell 98 variety) was previously done using a static table with linear search, which had two problems: the array had a fixed size and was sometimes too small (#1109), and performance of lockFile/unlockFile was suboptimal due to the linear search. Also the algorithm failed to count readers as required by Haskell 98 (#629). Now it's done using a hash table (provided by the RTS). Furthermore I avoided the extra fstat() for every open file by passing the dev_t and ino_t into lockFile. This and the improvements to the locking algorithm result in a healthy 20% or so performance increase for opening/closing files (see openFile008 test). --- includes/FileLock.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 includes/FileLock.h (limited to 'includes/FileLock.h') diff --git a/includes/FileLock.h b/includes/FileLock.h new file mode 100644 index 0000000000..3fc1a81aec --- /dev/null +++ b/includes/FileLock.h @@ -0,0 +1,12 @@ +/* ----------------------------------------------------------------------------- + * + * (c) The GHC Team, 2007 + * + * File locking support as required by Haskell 98 + * + * ---------------------------------------------------------------------------*/ + +void initFileLocking(void); +void freeFileLocking(void); +int lockFile(int fd, dev_t dev, ino_t ino, int for_writing); +int unlockFile(int fd); -- cgit v1.2.1