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

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