diff options
author | Crazycolorz5 <Crazycolorz5@gmail.com> | 2019-01-20 19:26:58 -0500 |
---|---|---|
committer | Ben Gamari <ben@well-typed.com> | 2019-11-17 07:31:49 -0500 |
commit | b109cb0efdbf62c264a45f0faeb18ff904cc5745 (patch) | |
tree | 0431dc52214aa5a179ebb551f4757169f5c409e0 /rts/FileLock.c | |
parent | 2f5ed225b78b32c65d023072d78ae5d176e2f04b (diff) | |
download | haskell-wip/D4889.tar.gz |
rts: Specialize hashing at call site rather than in struct.wip/D4889
Separate word and string hash tables on the type level, and do not store
the hashing function. Thus when a different hash function is desire it
is provided upon accessing the table. This is worst case the same as
before the change, and in the majority of cases is better. Also mark the
functions for aggressive inlining to improve performance. {F1686506}
Reviewers: bgamari, erikd, simonmar
Subscribers: rwbarton, thomie, carter
GHC Trac Issues: #13165
Differential Revision: https://phabricator.haskell.org/D4889
Diffstat (limited to 'rts/FileLock.c')
-rw-r--r-- | rts/FileLock.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/rts/FileLock.c b/rts/FileLock.c index ac21bea206..351d2a58f7 100644 --- a/rts/FileLock.c +++ b/rts/FileLock.c @@ -34,14 +34,14 @@ static HashTable *fd_hash; static Mutex file_lock_mutex; #endif -static int cmpLocks(StgWord w1, StgWord w2) +STATIC_INLINE int cmpLocks(StgWord w1, StgWord w2) { Lock *l1 = (Lock *)w1; Lock *l2 = (Lock *)w2; return (l1->device == l2->device && l1->inode == l2->inode); } -static int hashLock(const HashTable *table, StgWord w) +STATIC_INLINE int hashLock(const HashTable *table, StgWord w) { Lock *l = (Lock *)w; StgWord key = l->inode ^ (l->inode >> 32) ^ l->device ^ (l->device >> 32); @@ -52,7 +52,7 @@ static int hashLock(const HashTable *table, StgWord w) void initFileLocking(void) { - obj_hash = allocHashTable_(hashLock, cmpLocks); + obj_hash = allocHashTable(); fd_hash = allocHashTable(); /* ordinary word-based table */ #if defined(THREADED_RTS) initMutex(&file_lock_mutex); @@ -85,7 +85,7 @@ lockFile(int fd, StgWord64 dev, StgWord64 ino, int for_writing) key.device = dev; key.inode = ino; - lock = lookupHashTable(obj_hash, (StgWord)&key); + lock = lookupHashTable_(obj_hash, (StgWord)&key, hashLock, cmpLocks); if (lock == NULL) { @@ -93,7 +93,7 @@ lockFile(int fd, StgWord64 dev, StgWord64 ino, int for_writing) lock->device = dev; lock->inode = ino; lock->readers = for_writing ? -1 : 1; - insertHashTable(obj_hash, (StgWord)lock, (void *)lock); + insertHashTable_(obj_hash, (StgWord)lock, (void *)lock, hashLock); insertHashTable(fd_hash, fd, lock); RELEASE_LOCK(&file_lock_mutex); return 0; @@ -135,7 +135,7 @@ unlockFile(int fd) } if (lock->readers == 0) { - removeHashTable(obj_hash, (StgWord)lock, NULL); + removeHashTable_(obj_hash, (StgWord)lock, NULL, hashLock, cmpLocks); stgFree(lock); } removeHashTable(fd_hash, fd, NULL); |