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