Skip to content

Commit 8c831a3

Browse files
committed
Fix Linux compilation hang during LV2 build
1 parent b2b0cc3 commit 8c831a3

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

Source/Utility/FileSystemWatcher.cxx

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ using namespace juce;
2929
#include <unistd.h>
3030
#include <sys/stat.h>
3131
#include <sys/time.h>
32+
#include <poll.h>
3233
#endif
3334

3435
#if JUCE_MAC
@@ -150,49 +151,52 @@ class FileSystemWatcher::Impl : public Thread,
150151
void run() override
151152
{
152153
char buf[BUF_LEN];
153-
154154
const struct inotify_event* iNotifyEvent;
155155
char* ptr;
156-
156+
157157
while (!shouldQuit)
158158
{
159-
int numRead = read (fd, buf, BUF_LEN);
160-
161-
if (numRead <= 0 || threadShouldExit())
162-
break;
163-
164-
for (ptr = buf; ptr < buf + numRead; ptr += sizeof(struct inotify_event) + iNotifyEvent->len)
165-
{
166-
iNotifyEvent = (const struct inotify_event*)ptr;
167-
Event e;
168-
169-
e.file = File {folder.getFullPathName() + '/' + iNotifyEvent->name};
170-
171-
if (iNotifyEvent->mask & IN_CREATE) e.fsEvent = FileSystemEvent::fileCreated;
172-
else if (iNotifyEvent->mask & IN_CLOSE_WRITE) e.fsEvent = FileSystemEvent::fileUpdated;
173-
else if (iNotifyEvent->mask & IN_MOVED_FROM) e.fsEvent = FileSystemEvent::fileRenamedOldName;
174-
else if (iNotifyEvent->mask & IN_MOVED_TO) e.fsEvent = FileSystemEvent::fileRenamedNewName;
175-
else if (iNotifyEvent->mask & IN_DELETE) e.fsEvent = FileSystemEvent::fileDeleted;
176-
177-
ScopedLock sl(lock);
178-
179-
bool duplicateEvent = false;
180-
for (auto existing : events)
159+
struct pollfd pfd;
160+
pfd.fd = fd;
161+
pfd.events = POLLIN;
162+
163+
// Poll with 100ms timeout
164+
int pollResult = poll(&pfd, 1, 100);
165+
166+
if (threadShouldExit()) break; // Check exit condition regularly
167+
168+
if (pollResult > 0 && (pfd.revents & POLLIN)) {
169+
int numRead = read(fd, buf, BUF_LEN);
170+
if (numRead <= 0 || threadShouldExit())
171+
break;
172+
173+
for (ptr = buf; ptr < buf + numRead; ptr += sizeof(struct inotify_event) + iNotifyEvent->len)
181174
{
182-
if (e == existing)
175+
iNotifyEvent = (const struct inotify_event*)ptr;
176+
Event e;
177+
e.file = File {folder.getFullPathName() + '/' + iNotifyEvent->name};
178+
if (iNotifyEvent->mask & IN_CREATE) e.fsEvent = FileSystemEvent::fileCreated;
179+
else if (iNotifyEvent->mask & IN_CLOSE_WRITE) e.fsEvent = FileSystemEvent::fileUpdated;
180+
else if (iNotifyEvent->mask & IN_MOVED_FROM) e.fsEvent = FileSystemEvent::fileRenamedOldName;
181+
else if (iNotifyEvent->mask & IN_MOVED_TO) e.fsEvent = FileSystemEvent::fileRenamedNewName;
182+
else if (iNotifyEvent->mask & IN_DELETE) e.fsEvent = FileSystemEvent::fileDeleted;
183+
ScopedLock sl(lock);
184+
bool duplicateEvent = false;
185+
for (auto existing : events)
183186
{
184-
duplicateEvent = true;
185-
break;
187+
if (e == existing)
188+
{
189+
duplicateEvent = true;
190+
break;
191+
}
186192
}
193+
if (! duplicateEvent)
194+
events.add (std::move (e));
187195
}
188-
189-
if (! duplicateEvent)
190-
events.add (std::move (e));
196+
ScopedLock sl (lock);
197+
if (events.size() > 0)
198+
triggerAsyncUpdate();
191199
}
192-
193-
ScopedLock sl (lock);
194-
if (events.size() > 0)
195-
triggerAsyncUpdate();
196200
}
197201
}
198202

0 commit comments

Comments
 (0)