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

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