Commit 9fb12e14 authored by pcapriotti's avatar pcapriotti
Browse files

Enable FileLock for win32 (#4363)

parent c0461976
......@@ -14,11 +14,9 @@
#ifndef RTS_FILELOCK_H
#define RTS_FILELOCK_H
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include "Stg.h"
int lockFile(int fd, dev_t dev, ino_t ino, int for_writing);
int lockFile(int fd, StgWord64 dev, StgWord64 ino, int for_writing);
int unlockFile(int fd);
#endif /* RTS_FILELOCK_H */
......@@ -14,13 +14,12 @@
#include "RtsUtils.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
typedef struct {
dev_t device;
ino_t inode;
StgWord64 device;
StgWord64 inode;
int readers; // >0 : readers, <0 : writers
} Lock;
......@@ -45,8 +44,8 @@ static int cmpLocks(StgWord w1, StgWord w2)
static int hashLock(HashTable *table, StgWord w)
{
Lock *l = (Lock *)w;
// Just xor the dev_t with the ino_t, hope this is good enough.
return hashWord(table, (StgWord)l->inode ^ (StgWord)l->device);
// Just xor all 32-bit words of inode and device, hope this is good enough.
return hashWord(table, l->inode ^ (l->inode >> 32) ^ l->device ^ (l->device >> 32));
}
void
......@@ -76,7 +75,7 @@ freeFileLocking(void)
}
int
lockFile(int fd, dev_t dev, ino_t ino, int for_writing)
lockFile(int fd, StgWord64 dev, StgWord64 ino, int for_writing)
{
Lock key, *lock;
......
......@@ -304,8 +304,6 @@ typedef struct _RtsSymbolVal {
SymI_HasProto(__hscore_get_saved_termios) \
SymI_HasProto(__hscore_set_saved_termios) \
SymI_HasProto(shutdownHaskellAndSignal) \
SymI_HasProto(lockFile) \
SymI_HasProto(unlockFile) \
SymI_HasProto(signal_handlers) \
SymI_HasProto(stg_sig_install) \
SymI_HasProto(rtsTimerSignal) \
......@@ -1284,6 +1282,8 @@ typedef struct _RtsSymbolVal {
SymI_HasProto(stg_traceCcszh) \
SymI_HasProto(stg_traceEventzh) \
SymI_HasProto(getMonotonicNSec) \
SymI_HasProto(lockFile) \
SymI_HasProto(unlockFile) \
RTS_USER_SIGNALS_SYMBOLS \
RTS_INTCHAR_SYMBOLS
......
......@@ -35,6 +35,7 @@
#include "Profiling.h"
#include "Timer.h"
#include "Globals.h"
#include "FileLock.h"
void exitLinker( void ); // there is no Linker.h file to include
#if defined(RTS_GTK_FRONTPANEL)
......@@ -52,7 +53,6 @@ void exitLinker( void ); // there is no Linker.h file to include
#if !defined(mingw32_HOST_OS)
#include "posix/TTY.h"
#include "posix/FileLock.h"
#endif
#ifdef HAVE_UNISTD_H
......@@ -215,9 +215,7 @@ hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config)
initGlobalStore();
/* initialise file locking, if necessary */
#if !defined(mingw32_HOST_OS)
initFileLocking();
#endif
#if defined(DEBUG)
/* initialise thread label table (tso->char*) */
......@@ -376,9 +374,7 @@ hs_exit_(rtsBool wait_foreign)
exitLinker();
/* free file locking tables, if necessary */
#if !defined(mingw32_HOST_OS)
freeFileLocking();
#endif
/* free the stable pointer table */
exitStablePtrTable();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment