my_alarm.h 2.0 KB

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