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