Created
October 21, 2022 12:32
-
-
Save lptr/f5e48ef4451bc0586ecf6cbb3ba6d580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/file-events/src/file-events/cpp/generic_fsnotifier.cpp b/file-events/src/file-events/cpp/generic_fsnotifier.cpp | |
index f058278..20127ca 100644 | |
--- a/file-events/src/file-events/cpp/generic_fsnotifier.cpp | |
+++ b/file-events/src/file-events/cpp/generic_fsnotifier.cpp | |
@@ -77,27 +77,6 @@ jobject wrapServer(JNIEnv* env, AbstractServer* server) { | |
return env->NewDirectByteBuffer(server, sizeof(server)); | |
} | |
-void AbstractServer::executeRunLoop(JNIEnv* env) { | |
- try { | |
- runLoop(); | |
- } catch (const exception& ex) { | |
- rethrowAsJavaException(env, ex); | |
- } | |
- unique_lock<mutex> terminationLock(terminationMutex); | |
- terminated = true; | |
- terminationVariable.notify_all(); | |
-} | |
- | |
-bool AbstractServer::awaitTermination(long timeoutInMillis) { | |
- unique_lock<mutex> terminationLock(terminationMutex); | |
- if (terminated) { | |
- return true; | |
- } | |
- auto status = terminationVariable.wait_for(terminationLock, chrono::milliseconds(timeoutInMillis)); | |
- bool success = status != cv_status::timeout; | |
- return success; | |
-} | |
- | |
JNIEXPORT void JNICALL | |
Java_net_rubygrapefruit_platform_internal_jni_AbstractNativeFileEventFunctions_00024NativeFileWatcher_initializeRunLoop0(JNIEnv* env, jobject, jobject javaServer) { | |
try { | |
@@ -112,7 +91,8 @@ JNIEXPORT void JNICALL | |
Java_net_rubygrapefruit_platform_internal_jni_AbstractNativeFileEventFunctions_00024NativeFileWatcher_executeRunLoop0(JNIEnv* env, jobject, jobject javaServer) { | |
try { | |
AbstractServer* server = getServer(env, javaServer); | |
- server->executeRunLoop(env); | |
+ server->runLoop(); | |
+ // delete server; | |
} catch (const exception& e) { | |
rethrowAsJavaException(env, e); | |
} | |
@@ -155,21 +135,6 @@ Java_net_rubygrapefruit_platform_internal_jni_AbstractNativeFileEventFunctions_0 | |
} | |
} | |
-JNIEXPORT jboolean JNICALL | |
-Java_net_rubygrapefruit_platform_internal_jni_AbstractNativeFileEventFunctions_00024NativeFileWatcher_awaitTermination0(JNIEnv* env, jobject, jobject javaServer, jlong timeoutInMillis) { | |
- try { | |
- AbstractServer* server = getServer(env, javaServer); | |
- bool successful = server->awaitTermination((long) timeoutInMillis); | |
- if (successful) { | |
- delete server; | |
- } | |
- return successful; | |
- } catch (const exception& e) { | |
- rethrowAsJavaException(env, e); | |
- return false; | |
- } | |
-} | |
- | |
JNIEXPORT void JNICALL | |
Java_net_rubygrapefruit_platform_internal_jni_AbstractNativeFileEventFunctions_invalidateLogLevelCache0(JNIEnv* env, jobject) { | |
try { | |
diff --git a/file-events/src/file-events/cpp/win_fsnotifier.cpp b/file-events/src/file-events/cpp/win_fsnotifier.cpp | |
index 92d662c..8c19a11 100644 | |
--- a/file-events/src/file-events/cpp/win_fsnotifier.cpp | |
+++ b/file-events/src/file-events/cpp/win_fsnotifier.cpp | |
@@ -377,7 +377,7 @@ void Server::runLoop() { | |
logToJava(LogLevel::FINE, "Waiting for any pending watch points to abort completely", NULL); | |
SleepEx(0, true); | |
- // Warn about any unfinished watchpoints | |
+ // Warn about any unfinished watchpoints | |
for (auto& it : watchPoints) { | |
auto& watchPoint = it.second; | |
switch (watchPoint.status) { | |
diff --git a/file-events/src/file-events/headers/generic_fsnotifier.h b/file-events/src/file-events/headers/generic_fsnotifier.h | |
index 22fee59..54656bd 100644 | |
--- a/file-events/src/file-events/headers/generic_fsnotifier.h | |
+++ b/file-events/src/file-events/headers/generic_fsnotifier.h | |
@@ -44,7 +44,7 @@ public: | |
virtual ~AbstractServer(); | |
virtual void initializeRunLoop() = 0; | |
- void executeRunLoop(JNIEnv* env); | |
+ virtual void runLoop() = 0; | |
/** | |
* Registers new watch point with the server for the given paths. | |
@@ -61,24 +61,13 @@ public: | |
*/ | |
virtual void shutdownRunLoop() = 0; | |
- /** | |
- * Waits for the given timeout for the server to finsih terminating. | |
- */ | |
- bool awaitTermination(long timeoutInMillis); | |
- | |
protected: | |
- virtual void runLoop() = 0; | |
- | |
void reportChangeEvent(JNIEnv* env, ChangeType type, const u16string& path); | |
void reportUnknownEvent(JNIEnv* env, const u16string& path); | |
void reportOverflow(JNIEnv* env, const u16string& path); | |
void reportFailure(JNIEnv* env, const exception& ex); | |
private: | |
- mutex terminationMutex; | |
- condition_variable terminationVariable; | |
- bool terminated = false; | |
- | |
JniGlobalRef<jobject> watcherCallback; | |
jmethodID watcherReportChangeEventMethod; | |
jmethodID watcherReportUnknownEventMethod; | |
diff --git a/file-events/src/main/java/net/rubygrapefruit/platform/internal/jni/AbstractFileEventFunctions.java b/file-events/src/main/java/net/rubygrapefruit/platform/internal/jni/AbstractFileEventFunctions.java | |
index ecf04e5..eccaa3a 100644 | |
--- a/file-events/src/main/java/net/rubygrapefruit/platform/internal/jni/AbstractFileEventFunctions.java | |
+++ b/file-events/src/main/java/net/rubygrapefruit/platform/internal/jni/AbstractFileEventFunctions.java | |
@@ -196,19 +196,8 @@ public abstract class AbstractFileEventFunctions<W extends FileWatcher> implemen | |
@Override | |
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { | |
- long timeoutInMillis = unit.toMillis(timeout); | |
- long startTime = System.currentTimeMillis(); | |
- boolean successful = awaitTermination(timeoutInMillis); | |
- if (successful) { | |
- long endTime = System.currentTimeMillis(); | |
- long remainingTimeout = timeoutInMillis - (endTime - startTime); | |
- if (remainingTimeout > 0) { | |
- processorThread.join(remainingTimeout); | |
- } | |
- return !processorThread.isAlive(); | |
- } else { | |
- return false; | |
- } | |
+ processorThread.join(unit.toMillis(timeout)); | |
+ return !processorThread.isAlive(); | |
} | |
protected abstract void initializeRunLoop(); | |
@@ -221,8 +210,6 @@ public abstract class AbstractFileEventFunctions<W extends FileWatcher> implemen | |
protected abstract void doShutdown(); | |
- protected abstract boolean awaitTermination(long timeoutInMillis); | |
- | |
private void ensureOpen() { | |
if (shutdown) { | |
throw new IllegalStateException("Watcher already closed"); | |
diff --git a/file-events/src/main/java/net/rubygrapefruit/platform/internal/jni/AbstractNativeFileEventFunctions.java b/file-events/src/main/java/net/rubygrapefruit/platform/internal/jni/AbstractNativeFileEventFunctions.java | |
index 8b16233..7bc522a 100644 | |
--- a/file-events/src/main/java/net/rubygrapefruit/platform/internal/jni/AbstractNativeFileEventFunctions.java | |
+++ b/file-events/src/main/java/net/rubygrapefruit/platform/internal/jni/AbstractNativeFileEventFunctions.java | |
@@ -73,12 +73,5 @@ public abstract class AbstractNativeFileEventFunctions<W extends FileWatcher> ex | |
} | |
private native void shutdown0(Object server); | |
- | |
- @Override | |
- protected boolean awaitTermination(long timeoutInMillis) { | |
- return awaitTermination0(server, timeoutInMillis); | |
- } | |
- | |
- private native boolean awaitTermination0(Object server, long timeoutInMillis); | |
} | |
} | |
diff --git a/file-events/src/test/groovy/net/rubygrapefruit/platform/internal/jni/TestFileEventFunctions.groovy b/file-events/src/test/groovy/net/rubygrapefruit/platform/internal/jni/TestFileEventFunctions.groovy | |
index 8e0922d..4989cc7 100644 | |
--- a/file-events/src/test/groovy/net/rubygrapefruit/platform/internal/jni/TestFileEventFunctions.groovy | |
+++ b/file-events/src/test/groovy/net/rubygrapefruit/platform/internal/jni/TestFileEventFunctions.groovy | |
@@ -63,11 +63,6 @@ class TestFileEventFunctions extends AbstractFileEventFunctions<TestFileEventFun | |
commands.put(Command.TERMINATE) | |
} | |
- @Override | |
- protected boolean awaitTermination(long timeoutInMillis) { | |
- return true; | |
- } | |
- | |
@Override | |
protected void doStartWatching(Collection<File> paths) { | |
throw new UnsupportedOperationException() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment