1 /* 2 Copyright (c) 2000, 2010, Oracle and/or its affiliates. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; version 2 of the License. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ 16 17 /* 18 File to include when we want to use alarm or a loop_counter to display 19 some information when a program is running 20 */ 21 #ifndef _my_alarm_h 22 #define _my_alarm_h 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 extern int volatile my_have_got_alarm; 28 extern ulong my_time_to_wait_for_lock; 29 30 #if defined(HAVE_ALARM) && !defined(NO_ALARM_LOOP) 31 #include <signal.h> 32 #ifdef HAVE_SIGHANDLER_T 33 #define sig_return sighandler_t 34 #elif defined(SOLARIS) || defined(__sun) || defined(__APPLE__) 35 typedef void (*sig_return)(int); /* Returns type from signal */ 36 #else 37 typedef void (*sig_return)(void); /* Returns type from signal */ 38 #endif 39 #define ALARM_VARIABLES uint alarm_old=0; \ 40 sig_return alarm_signal=0 41 #define ALARM_INIT my_have_got_alarm=0 ; \ 42 alarm_old=(uint) alarm(MY_HOW_OFTEN_TO_ALARM); \ 43 alarm_signal=signal(SIGALRM,my_set_alarm_variable); 44 #define ALARM_END (void) signal(SIGALRM,alarm_signal); \ 45 (void) alarm(alarm_old); 46 #define ALARM_TEST my_have_got_alarm 47 #ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY 48 #define ALARM_REINIT (void) alarm(MY_HOW_OFTEN_TO_ALARM); \ 49 (void) signal(SIGALRM,my_set_alarm_variable);\ 50 my_have_got_alarm=0; 51 #else 52 #define ALARM_REINIT (void) alarm((uint) MY_HOW_OFTEN_TO_ALARM); \ 53 my_have_got_alarm=0; 54 #endif /* SIGNAL_HANDLER_RESET_ON_DELIVERY */ 55 #else 56 #define ALARM_VARIABLES long alarm_pos=0,alarm_end_pos=MY_HOW_OFTEN_TO_WRITE-1 57 #define ALARM_INIT 58 #define ALARM_END 59 #define ALARM_TEST (alarm_pos++ >= alarm_end_pos) 60 #define ALARM_REINIT (alarm_end_pos+=MY_HOW_OFTEN_TO_WRITE) 61 #endif /* HAVE_ALARM */ 62 63 #ifdef __cplusplus 64 } 65 #endif 66 #endif 67