source: trunk/signal-checkpoint/signal_checkpoint.F90 @ 72

Last change on this file since 72 was 72, checked in by g7moreau, 12 years ago
  • Replace integer flag by a logical variable
  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1!--------------------------------------------------------------!
2! 2012/04/20 (C) Gabriel Moreau
3! Licence LGPLv2 or latter
4! $Id: signal_checkpoint.F90 72 2012-05-29 09:20:54Z g7moreau $
5!--------------------------------------------------------------!
6
7module Signal_Checkpoint
8
9#ifdef __INTEL_COMPILER
10use IFPORT, only: signal
11#endif
12
13implicit none
14save
15private
16
17integer, parameter :: SIGHUP  =  1  ! Signal HUP
18integer, parameter :: SIGINT  =  2  ! Signal INT
19integer, parameter :: SIGQUIT =  3  ! Signal QUIT
20integer, parameter :: SIGUSR1 = 10  ! Signal USR1
21integer, parameter :: SIGUSR2 = 12  ! Signal USR2
22integer, parameter :: SIGTERM = 15  ! Signal TERM
23
24! Internal counter
25integer :: INTERNAL_RECEIVED_COUNT_ = 0       ! Global Signal Counter
26logical :: INTERNAL_ERROR_ON_EXIT_  = .false. ! Global State
27
28public :: SIGHUP
29public :: SIGINT
30public :: SIGQUIT
31public :: SIGUSR1
32public :: SIGUSR2
33public :: SIGTERM
34public :: signal_checkpoint_connect
35public :: signal_checkpoint_is_received
36public :: signal_checkpoint_received_times
37public :: signal_checkpoint_ask_for_exit_code
38
39!--------------------------------------------------------------!
40contains
41!--------------------------------------------------------------!
42
43subroutine signal_checkpoint_connect (SIG_NUM, EXIT)
44   integer, intent(in) :: SIG_NUM
45   logical, intent(in), optional :: EXIT
46
47#ifdef __INTEL_COMPILER
48   integer :: ERR
49
50   if (present(EXIT)) then
51      ERR = signal(SIG_NUM, trap_callback_intel_exit_, -1)
52   else
53      ERR = signal(SIG_NUM, trap_callback_intel_count_, -1)
54   end if
55#endif
56
57#ifdef __GNUC__
58   intrinsic signal
59
60   if (present(EXIT)) then
61      call signal(SIG_NUM, trap_callback_exit_)
62   else
63
64      call signal(SIG_NUM, trap_callback_count_)
65   end if
66#endif
67
68end subroutine
69
70!--------------------------------------------------------------!
71
72function signal_checkpoint_is_received () result (IS_RECEIVED)
73   logical :: IS_RECEIVED
74
75   IS_RECEIVED = ( INTERNAL_RECEIVED_COUNT_ > 0 )
76end function
77
78!--------------------------------------------------------------!
79
80function signal_checkpoint_received_times () result (RECEIVED_TIMES)
81   integer :: RECEIVED_TIMES
82
83   RECEIVED_TIMES = INTERNAL_RECEIVED_COUNT_
84end function
85
86!--------------------------------------------------------------!
87
88function signal_checkpoint_ask_for_exit_code () result (EXIT)
89   logical :: EXIT
90   
91   EXIT = INTERNAL_ERROR_ON_EXIT_
92end function
93
94!--------------------------------------------------------------!
95!--------------------------------------------------------------!
96
97subroutine trap_callback_count_ !(SIG_NUM)
98   !integer, intent(in) :: SIG_NUM
99
100   INTERNAL_RECEIVED_COUNT_ = INTERNAL_RECEIVED_COUNT_ + 1
101end subroutine
102
103!--------------------------------------------------------------!
104
105subroutine trap_callback_exit_ !(SIG_NUM)
106   !integer, intent(in) :: SIG_NUM
107
108   INTERNAL_ERROR_ON_EXIT_ = .true.
109   call trap_callback_count_
110end subroutine
111
112!--------------------------------------------------------------!
113
114function trap_callback_intel_exit_ (SIG_NUM) result (ONE)
115   integer, intent(in) :: SIG_NUM
116   integer :: ONE
117
118   call trap_callback_exit_
119   ONE = 1
120end function
121
122!--------------------------------------------------------------!
123
124function trap_callback_intel_count_ (SIG_NUM) result (ONE)
125   integer, intent(in) :: SIG_NUM
126   integer :: ONE
127
128   call trap_callback_count_
129   ONE = 1
130end function
131
132!--------------------------------------------------------------!
133end module
134!--------------------------------------------------------------!
Note: See TracBrowser for help on using the repository browser.