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

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