thr_alarm.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. /* Prototypes when using thr_alarm library functions */
  13. #ifndef _thr_alarm_h
  14. #define _thr_alarm_h
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #ifndef USE_ALARM_THREAD
  19. #define USE_ONE_SIGNAL_HAND /* One must call process_alarm */
  20. #endif
  21. #ifdef HAVE_rts_threads
  22. #undef USE_ONE_SIGNAL_HAND
  23. #define USE_ALARM_THREAD
  24. #define THR_SERVER_ALARM SIGUSR1
  25. #else
  26. #define THR_SERVER_ALARM SIGALRM
  27. #endif
  28. typedef struct st_alarm_info
  29. {
  30. time_t next_alarm_time;
  31. uint active_alarms;
  32. uint max_used_alarms;
  33. } ALARM_INFO;
  34. void thr_alarm_info(ALARM_INFO *info);
  35. extern my_bool my_disable_thr_alarm;
  36. #ifdef _WIN32
  37. #define DONT_USE_THR_ALARM
  38. #endif
  39. #if defined(DONT_USE_THR_ALARM)
  40. #define USE_ALARM_THREAD
  41. #undef USE_ONE_SIGNAL_HAND
  42. typedef my_bool thr_alarm_t;
  43. typedef my_bool ALARM;
  44. #define thr_alarm_init(A) (*(A))=0
  45. #define thr_alarm_in_use(A) (*(A) != 0)
  46. #define thr_end_alarm(A)
  47. #define thr_alarm(A,B,C) ((*(A)=1)-1)
  48. /* The following should maybe be (*(A)) */
  49. #define thr_got_alarm(A) 0
  50. #define init_thr_alarm(A)
  51. #define thr_alarm_kill(A)
  52. #define resize_thr_alarm(N)
  53. #define end_thr_alarm(A)
  54. #else
  55. #if defined(__WIN__)
  56. typedef struct st_thr_alarm_entry
  57. {
  58. UINT_PTR crono;
  59. } thr_alarm_entry;
  60. #else /* System with posix threads */
  61. typedef int thr_alarm_entry;
  62. #define thr_got_alarm(thr_alarm) (**(thr_alarm))
  63. #endif /* __WIN__ */
  64. typedef thr_alarm_entry* thr_alarm_t;
  65. typedef struct st_alarm {
  66. time_t expire_time;
  67. thr_alarm_entry alarmed; /* set when alarm is due */
  68. pthread_t thread;
  69. my_thread_id thread_id;
  70. uint index_in_queue;
  71. my_bool malloced;
  72. } ALARM;
  73. extern uint thr_client_alarm;
  74. extern pthread_t alarm_thread;
  75. #define thr_alarm_init(A) (*(A))=0
  76. #define thr_alarm_in_use(A) (*(A)!= 0)
  77. void init_thr_alarm(uint max_alarm);
  78. void resize_thr_alarm(uint max_alarms);
  79. my_bool thr_alarm(thr_alarm_t *alarmed, uint sec, ALARM *buff);
  80. void thr_alarm_kill(my_thread_id thread_id);
  81. void thr_end_alarm(thr_alarm_t *alarmed);
  82. void end_thr_alarm(my_bool free_structures);
  83. sig_handler process_alarm(int);
  84. #ifndef thr_got_alarm
  85. my_bool thr_got_alarm(thr_alarm_t *alrm);
  86. #endif
  87. #endif /* DONT_USE_THR_ALARM */
  88. #ifdef __cplusplus
  89. }
  90. #endif /* __cplusplus */
  91. #endif /* _thr_alarm_h */