You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sig_handler.cc 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "minddata/dataset/util/sig_handler.h"
  17. #include <signal.h>
  18. #include <sys/types.h>
  19. #if !defined(_WIN32) && !defined(_WIN64) && !defined(__ANDROID__) && !defined(ANDROID)
  20. #include <ucontext.h>
  21. #endif
  22. #include <unistd.h>
  23. #include "minddata/dataset/util/task_manager.h"
  24. namespace mindspore {
  25. namespace dataset {
  26. // Register the custom signal handlers
  27. #if !defined(_WIN32) && !defined(_WIN64) && !defined(__ANDROID__) && !defined(ANDROID)
  28. void RegisterHandlers() {
  29. struct sigaction new_int_action;
  30. // For the interrupt handler, we do not use SA_RESETHAND so this handler remains in play
  31. // permanently, do not use the OS default handler for it.
  32. new_int_action.sa_sigaction = &IntHandler;
  33. (void)sigemptyset(&new_int_action.sa_mask);
  34. new_int_action.sa_flags = SA_RESTART | SA_SIGINFO;
  35. (void)sigaction(SIGINT, &new_int_action, nullptr);
  36. }
  37. extern void IntHandler(int sig_num, // The signal that was raised
  38. siginfo_t *sig_info, // The siginfo structure.
  39. void *context) { // context info
  40. // Wake up the watchdog which is designed as async-signal-safe.
  41. TaskManager::WakeUpWatchDog();
  42. }
  43. #endif
  44. } // namespace dataset
  45. } // namespace mindspore