Skip to content

Commit feb2f9b

Browse files
committed
Simplify code in a few places (nits)
1 parent 3c14f6a commit feb2f9b

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/main/java/engineering/swat/watch/impl/jdk/JDKPoller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ public static Closeable register(SubscriptionKey path, Consumer<List<WatchEvent<
125125
try {
126126
return CompletableFuture.supplyAsync(() -> {
127127
try {
128+
Watchable watchable = Platform.get().newWatchable(path.getPath());
128129
WatchEvent.Kind<?>[] kinds = new WatchEvent.Kind[]{ ENTRY_CREATE, ENTRY_MODIFY, OVERFLOW, ENTRY_DELETE };
129-
var watchable = Platform.get().newWatchable(path.getPath());
130130
if (path.isRecursive()) {
131131
return watchable.register(service, kinds, ExtendedWatchEventModifier.FILE_TREE);
132132
}

src/main/java/engineering/swat/watch/impl/mac/MacWatchKey.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ public class MacWatchKey implements WatchKey {
5050
private final NativeEventStream stream;
5151

5252
private volatile Configuration config = new Configuration();
53-
private volatile boolean signalled = false;
53+
private volatile boolean signalled = false; // `!signalled` means "ready"
5454
private volatile boolean cancelled = false;
5555

56-
5756
public MacWatchKey(MacWatchable watchable, MacWatchService service) throws IOException {
5857
this.watchable = watchable;
5958
this.service = service;
@@ -198,8 +197,10 @@ public boolean reset() {
198197
return false;
199198
}
200199

201-
signalled = false;
202-
signalWhen(!pendingEvents.isEmpty());
200+
if (signalled) {
201+
signalled = false;
202+
signalWhen(!pendingEvents.isEmpty());
203+
}
203204

204205
// Invalidation of this key *during* the invocation of this method is
205206
// observationally equivalent to invalidation immediately *after*. Thus,

src/main/java/engineering/swat/watch/impl/mac/MacWatchable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public WatchKey register(WatchService watcher, Kind<?>[] events, Modifier... mod
7575
var service = (MacWatchService) watcher;
7676
var newKey = new MacWatchKey(this, service);
7777
var oldKey = registrations.putIfAbsent(service, newKey);
78-
return (oldKey == null ? newKey : oldKey).initialize(events, modifiers);
78+
return (oldKey != null ? oldKey : newKey).initialize(events, modifiers);
7979
}
8080

8181
@Override

0 commit comments

Comments
 (0)