Skip to content

Commit

Permalink
maybe fixe crash in file wather thread in 32-bit (fixes #4111)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed May 13, 2024
1 parent 39e4ef1 commit 4f40056
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Binary file modified docs/manual.dat
Binary file not shown.
26 changes: 13 additions & 13 deletions src/utils/FileWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,6 @@ static DWORD WINAPI FileWatcherThread(void*) {
return 0;
}

static void StartFileThreadIfNecessary() {
if (g_threadHandle) {
return;
}
logf("StartFileThreadIfNecessary: starting a thread\n");
InitializeCriticalSection(&g_threadCritSec);
g_threadControlHandle = CreateEvent(nullptr, TRUE, FALSE, nullptr);

g_threadHandle = CreateThread(nullptr, 0, FileWatcherThread, nullptr, 0, &g_threadId);
SetThreadName("FileWatcherThread", g_threadId);
}

static WatchedDir* FindExistingWatchedDir(const char* dirPath) {
for (WatchedDir* wd = g_watchedDirs; wd; wd = wd->next) {
// TODO: normalize dirPath?
Expand Down Expand Up @@ -468,8 +456,20 @@ WatchedFile* FileWatcherSubscribe(const char* path, const std::function<void()>&
logf("FileWatcherSubscribe: path='%s' doesn't exist\n", path);
return nullptr;
}
if (IsProcess32()) {
// https://github.com/sumatrapdfreader/sumatrapdf/issues/4111
logf("FileWatcherSubscribe: not starting a file watcher thread due to 32-bit miscompilation\n");
return nullptr;
}

StartFileThreadIfNecessary();
if (!g_threadHandle) {
logf("StartFileThreadIfNecessary: starting a thread\n");
InitializeCriticalSection(&g_threadCritSec);
g_threadControlHandle = CreateEvent(nullptr, TRUE, FALSE, nullptr);

g_threadHandle = CreateThread(nullptr, 0, FileWatcherThread, nullptr, 0, &g_threadId);
SetThreadName("FileWatcherThread", g_threadId);
}

ScopedCritSec cs(&g_threadCritSec);
return NewWatchedFile(path, onFileChangedCb);
Expand Down
4 changes: 4 additions & 0 deletions src/utils/WinUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ bool IsProcess64() {
return 8 == sizeof(void*);
}

bool IsProcess32() {
return 4 == sizeof(void*);
}

// return true if running on a 64-bit OS
bool IsOs64() {
// 64-bit processes can only run on a 64-bit OS,
Expand Down
1 change: 1 addition & 0 deletions src/utils/WinUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void MoveWindow(HWND hwnd, RECT* r);

bool IsOs64();
bool IsProcess64();
bool IsProcess32();
bool IsArmBuild();
bool IsRunningInWow64();
bool IsProcessAndOsArchSame();
Expand Down

0 comments on commit 4f40056

Please sign in to comment.