diff --git a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp index 1ede032efed4f62747ac0eb5f971f24389de7c43..5e9340b791e4817d610a9564fd453a22539c795a 100644 --- a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp +++ b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -28,7 +27,6 @@ using namespace OHOS::FileManagement::LibN; using namespace std; mutex FileWatcher::watchMutex_; -mutex FileWatcher::selectMutex_; FileWatcher::FileWatcher() {} @@ -150,10 +148,6 @@ int FileWatcher::StopNotify(shared_ptr arg) void FileWatcher::GetNotifyEvent(WatcherCallback callback) { - unique_lock lock(selectMutex_, std::try_to_lock); - if (!lock.try_lock()) { - return; - } if (run_) { return; } @@ -163,15 +157,12 @@ void FileWatcher::GetNotifyEvent(WatcherCallback callback) fd_set fds; FD_ZERO(&fds); FD_SET(notifyFd_, &fds); - struct timeval tv; - tv.tv_sec = 0; - tv.tv_usec = 1000; while (run_) { if (notifyFd_ < 0) { HILOGE("Failed to run Listener Thread because notifyFd_:%{public}d", notifyFd_); break; } - if (select(notifyFd_ + 1, &fds, nullptr, nullptr, &tv) > 0) { + if (select(notifyFd_ + 1, &fds, nullptr, nullptr, nullptr) > 0) { int len, index = 0; while (((len = read(notifyFd_, &buf, sizeof(buf))) < 0) && (errno == EINTR)) {}; while (index < len) { diff --git a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.h b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.h index 102430604da1cbe0de6d46d0459b36da9e3878ee..37db1b7bf9227d950edbe9ae09202a5ad619a534 100644 --- a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.h +++ b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.h @@ -67,7 +67,6 @@ private: private: static std::mutex watchMutex_; - static std::mutex selectMutex_; bool run_ = false; int32_t notifyFd_ = -1; std::unordered_set> watcherInfoSet_;