| 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-1301 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 | #define ALARM_VARIABLES uint alarm_old=0; \ |
| 33 | sig_return alarm_signal=0 |
| 34 | #define ALARM_INIT my_have_got_alarm=0 ; \ |
| 35 | alarm_old=(uint) alarm(MY_HOW_OFTEN_TO_ALARM); \ |
| 36 | alarm_signal=signal(SIGALRM,my_set_alarm_variable); |
| 37 | #define ALARM_END (void) signal(SIGALRM,alarm_signal); \ |
| 38 | (void) alarm(alarm_old); |
| 39 | #define ALARM_TEST my_have_got_alarm |
| 40 | #ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY |
| 41 | #define ALARM_REINIT (void) alarm(MY_HOW_OFTEN_TO_ALARM); \ |
| 42 | (void) signal(SIGALRM,my_set_alarm_variable);\ |
| 43 | my_have_got_alarm=0; |
| 44 | #else |
| 45 | #define ALARM_REINIT (void) alarm((uint) MY_HOW_OFTEN_TO_ALARM); \ |
| 46 | my_have_got_alarm=0; |
| 47 | #endif /* SIGNAL_HANDLER_RESET_ON_DELIVERY */ |
| 48 | #else |
| 49 | #define ALARM_VARIABLES long alarm_pos=0,alarm_end_pos=MY_HOW_OFTEN_TO_WRITE-1 |
| 50 | #define ALARM_INIT |
| 51 | #define ALARM_END |
| 52 | #define ALARM_TEST (alarm_pos++ >= alarm_end_pos) |
| 53 | #define ALARM_REINIT (alarm_end_pos+=MY_HOW_OFTEN_TO_WRITE) |
| 54 | #endif /* HAVE_ALARM */ |
| 55 | |
| 56 | #ifdef __cplusplus |
| 57 | } |
| 58 | #endif |
| 59 | #endif |
| 60 | |