Google OR-Tools: ortools/util/sigint.h Source File

Go to the documentation of this file.

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef ORTOOLS_UTIL_SIGINT_H_

15#define ORTOOLS_UTIL_SIGINT_H_

16

17#include <atomic>

18#include <functional>

19

21

22#if ORTOOLS_TARGET_OS_SUPPORTS_THREADS

23

25

26class SigintHandler {

27 public:

28 SigintHandler() = default;

29 ~SigintHandler();

30

31

32

33 void Register(const std::function<void()>& f);

34

35 private:

36 std::atomic<int> num_calls_ = 0;

37

38 static void SigHandler(int s);

39 thread_local static std::function<void()> handler_;

40};

41

42class SigtermHandler {

43 public:

44 SigtermHandler() = default;

45 ~SigtermHandler();

46

47

48

49 void Register(const std::function<void()>& f);

50

51 private:

52 static void SigHandler(int s);

53 thread_local static std::function<void()> handler_;

54};

55

56}

57

58#endif

59

60#endif