forked from mindspore-Ecosystem/mindspore
!1274 Do not bring up WatchDog thread on Windows
Merge pull request !1274 from JesseKLee/NoWatchDogOnWindows
This commit is contained in:
commit
8f68e6c29b
|
@ -102,12 +102,14 @@ TaskManager::TaskManager() try : global_interrupt_(0),
|
|||
master_->running_ = true;
|
||||
master_->is_master_ = true;
|
||||
gMyTask = master_.get();
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
// Initialize the semaphore for the watchdog
|
||||
errno_t rc = sem_init(&sem_, 0, 0);
|
||||
if (rc == -1) {
|
||||
MS_LOG(INFO) << "Unable to initialize a semaphore. Errno = " << rc << ".";
|
||||
std::terminate();
|
||||
}
|
||||
#endif
|
||||
} catch (const std::exception &e) {
|
||||
MS_LOG(ERROR) << "MindData initialization failed: " << e.what() << ".";
|
||||
std::terminate();
|
||||
|
@ -122,11 +124,14 @@ TaskManager::~TaskManager() {
|
|||
watchdog_grp_ = nullptr;
|
||||
watchdog_ = nullptr;
|
||||
}
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
(void)sem_destroy(&sem_);
|
||||
#endif
|
||||
}
|
||||
|
||||
Status TaskManager::DoServiceStart() {
|
||||
MS_LOG(INFO) << "Starting Task Manager.";
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
// Create a watchdog for control-c
|
||||
std::shared_ptr<MemoryPool> mp = Services::GetInstance().GetServiceMemPool();
|
||||
// A dummy group just for the watchdog. We aren't really using it. But most code assumes a thread must
|
||||
|
@ -143,6 +148,7 @@ Status TaskManager::DoServiceStart() {
|
|||
}
|
||||
grp_list_.erase(watchdog_grp_);
|
||||
lru_.Remove(watchdog_);
|
||||
#endif
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
|
@ -154,6 +160,7 @@ Status TaskManager::DoServiceStop() {
|
|||
|
||||
Status TaskManager::WatchDog() {
|
||||
TaskManager::FindMe()->Post();
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
errno_t err = sem_wait(&sem_);
|
||||
if (err == -1) {
|
||||
RETURN_STATUS_UNEXPECTED("Errno = " + std::to_string(errno));
|
||||
|
@ -162,6 +169,7 @@ Status TaskManager::WatchDog() {
|
|||
// In addition, we also want to prevent new thread from creating. This can be done
|
||||
// easily by calling the parent function.
|
||||
RETURN_IF_NOT_OK(ServiceStop());
|
||||
#endif
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
#ifndef DATASET_UTIL_TASK_MANAGER_H_
|
||||
#define DATASET_UTIL_TASK_MANAGER_H_
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#include <semaphore.h>
|
||||
#include <signal.h> // for sig_atomic_t
|
||||
#endif
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
@ -81,8 +83,10 @@ class TaskManager : public Service {
|
|||
static void InterruptMaster(const Status &rc = Status::OK());
|
||||
|
||||
static void WakeUpWatchDog() {
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
TaskManager &tm = TaskManager::GetInstance();
|
||||
(void)sem_post(&tm.sem_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ReturnFreeTask(Task *p) noexcept;
|
||||
|
@ -98,7 +102,9 @@ class TaskManager : public Service {
|
|||
std::shared_ptr<Task> master_;
|
||||
List<Task> lru_;
|
||||
List<Task> free_lst_;
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
sem_t sem_;
|
||||
#endif
|
||||
TaskGroup *watchdog_grp_;
|
||||
std::set<TaskGroup *> grp_list_;
|
||||
Task *watchdog_;
|
||||
|
|
Loading…
Reference in New Issue