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

Last change on this file since 91 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
RevLine 
[62]1!--------------------------------------------------------------!
[74]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/
[68]8! $Id: signal_checkpoint.F90 91 2012-10-10 15:55:32Z g7moreau $
[62]9!--------------------------------------------------------------!
10
11module Signal_Checkpoint
12
13#ifdef __INTEL_COMPILER
14use IFPORT, only: signal
15#endif
16
17implicit none
[71]18save
[62]19private
20
[73]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
[91]28integer,parameter :: SIGXCPU = 24  ! Signal XCPU
[62]29
[72]30! Internal counter
[73]31integer :: SIGNAL_RECEIVED_COUNT_ = 0       ! Global signal counter
32logical :: CODE_ERROR_ON_EXIT_    = .false. ! Global return state
[62]33
[73]34! Public interface
[67]35public :: SIGHUP
36public :: SIGINT
37public :: SIGQUIT
38public :: SIGUSR1
[62]39public :: SIGUSR2
[67]40public :: SIGTERM
[91]41public :: SIGXCPU
[62]42public :: signal_checkpoint_connect
43public :: signal_checkpoint_is_received
44public :: signal_checkpoint_received_times
[70]45public :: signal_checkpoint_ask_for_exit_code
[62]46
47!--------------------------------------------------------------!
48contains
49!--------------------------------------------------------------!
50
[70]51subroutine signal_checkpoint_connect (SIG_NUM, EXIT)
[73]52   integer,intent(in)          :: SIG_NUM
53   logical,intent(in),optional :: EXIT
[62]54
55#ifdef __INTEL_COMPILER
[63]56   integer :: ERR
[70]57
58   if (present(EXIT)) then
[71]59      ERR = signal(SIG_NUM, trap_callback_intel_exit_, -1)
60   else
61      ERR = signal(SIG_NUM, trap_callback_intel_count_, -1)
[70]62   end if
[62]63#endif
[64]64
[90]65#if defined (__GNUC__) || defined (XLF)
[64]66   intrinsic signal
67
[70]68   if (present(EXIT)) then
[71]69      call signal(SIG_NUM, trap_callback_exit_)
70   else
71      call signal(SIG_NUM, trap_callback_count_)
[70]72   end if
[62]73#endif
74
75end subroutine
76
77!--------------------------------------------------------------!
[64]78
[62]79function signal_checkpoint_is_received () result (IS_RECEIVED)
80   logical :: IS_RECEIVED
81
[73]82   IS_RECEIVED = ( SIGNAL_RECEIVED_COUNT_ > 0 )
[62]83end function
84
85!--------------------------------------------------------------!
[64]86
[62]87function signal_checkpoint_received_times () result (RECEIVED_TIMES)
88   integer :: RECEIVED_TIMES
89
[73]90   RECEIVED_TIMES = SIGNAL_RECEIVED_COUNT_
[62]91end function
92
93!--------------------------------------------------------------!
[70]94
95function signal_checkpoint_ask_for_exit_code () result (EXIT)
96   logical :: EXIT
97   
[73]98   EXIT = CODE_ERROR_ON_EXIT_
[70]99end function
100
101!--------------------------------------------------------------!
[62]102!--------------------------------------------------------------!
103
[73]104subroutine trap_callback_count_
[62]105
[73]106   SIGNAL_RECEIVED_COUNT_ = SIGNAL_RECEIVED_COUNT_ + 1
[71]107end subroutine
108
[62]109!--------------------------------------------------------------!
[71]110
[73]111subroutine trap_callback_exit_
[71]112
[73]113   CODE_ERROR_ON_EXIT_ = .true.
[71]114   call trap_callback_count_
115end subroutine
116
[62]117!--------------------------------------------------------------!
118
[71]119function trap_callback_intel_exit_ (SIG_NUM) result (ONE)
[73]120   integer,intent(in) :: SIG_NUM
121   integer            :: ONE
[62]122
[71]123   call trap_callback_exit_
124   ONE = 1
125end function
[62]126
[64]127!--------------------------------------------------------------!
128
[71]129function trap_callback_intel_count_ (SIG_NUM) result (ONE)
[73]130   integer,intent(in) :: SIG_NUM
131   integer            :: ONE
[62]132
[71]133   call trap_callback_count_
[63]134   ONE = 1
[71]135end function
[64]136
137!--------------------------------------------------------------!
[71]138end module
[64]139!--------------------------------------------------------------!
Note: See TracBrowser for help on using the repository browser.