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

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