File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ class Watcher
3636
3737 std::atomic<bool > mRunning ;
3838 SingleshotSemaphore mHasStartedSemaphore ;
39+ SingleshotSemaphore mIsRunningSemaphore ;
3940 mutable std::mutex mErrorMutex ;
4041 std::string mError ;
4142
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ std::string Watcher::getUTF8Directory(std::wstring path) {
3838 // before returning it to the user
3939 stripNTPrefix (uft16DirectoryString);
4040 }
41-
41+
4242 int utf8length = WideCharToMultiByte (
4343 CP_UTF8,
4444 0 ,
@@ -239,6 +239,7 @@ void Watcher::start() {
239239 mRunner = std::thread ([this ] {
240240 // mRunning is set to false in the d'tor
241241 mRunning = true ;
242+ mIsRunningSemaphore .signal ();
242243 run ();
243244 });
244245
@@ -247,11 +248,16 @@ void Watcher::start() {
247248 return ;
248249 }
249250
251+ if (!mIsRunningSemaphore .waitFor (std::chrono::seconds (10 ))) {
252+ setError (" Watcher is not started" );
253+ return ;
254+ }
255+
250256 QueueUserAPC ([](__in ULONG_PTR self) {
251257 auto watcher = reinterpret_cast <Watcher*>(self);
252258 watcher->pollDirectoryChanges ();
253259 watcher->mHasStartedSemaphore .signal ();
254- } , mRunner .native_handle (), (ULONG_PTR)this );
260+ }, mRunner .native_handle (), (ULONG_PTR)this );
255261
256262 if (!mHasStartedSemaphore .waitFor (std::chrono::seconds (10 ))) {
257263 setError (" Watcher is not started" );
You can’t perform that action at this time.
0 commit comments