1 /* Copyright (C) 2000 MySQL AB 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; either version 2 of the License, or 6 (at your option) any later version. 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 16 17 /* Prototypes when using thr_alarm library functions */ 18 19 #ifndef _thr_alarm_h 20 #define _thr_alarm_h 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #ifndef USE_ALARM_THREAD 26 #define USE_ONE_SIGNAL_HAND /* One must call process_alarm */ 27 #endif 28 #ifdef HAVE_LINUXTHREADS 29 #define THR_CLIENT_ALARM SIGALRM 30 #else 31 #define THR_CLIENT_ALARM SIGUSR1 32 #endif 33 #ifdef HAVE_rts_threads 34 #undef USE_ONE_SIGNAL_HAND 35 #define USE_ALARM_THREAD 36 #define THR_SERVER_ALARM SIGUSR1 37 #else 38 #define THR_SERVER_ALARM SIGALRM 39 #endif 40 41 typedef struct st_alarm_info 42 { 43 ulong next_alarm_time; 44 uint active_alarms; 45 uint max_used_alarms; 46 } ALARM_INFO; 47 48 void thr_alarm_info(ALARM_INFO *info); 49 50 #if defined(DONT_USE_THR_ALARM) || !defined(THREAD) 51 52 #define USE_ALARM_THREAD 53 #undef USE_ONE_SIGNAL_HAND 54 55 typedef my_bool thr_alarm_t; 56 typedef my_bool ALARM; 57 58 #define thr_alarm_init(A) (*(A))=0 59 #define thr_alarm_in_use(A) (*(A) != 0) 60 #define thr_end_alarm(A) 61 #define thr_alarm(A,B,C) ((*(A)=1)-1) 62 /* The following should maybe be (*(A)) */ 63 #define thr_got_alarm(A) 0 64 #define init_thr_alarm(A) 65 #define thr_alarm_kill(A) 66 #define resize_thr_alarm(N) 67 #define end_thr_alarm() 68 69 #else 70 #if defined(__WIN__) 71 typedef struct st_thr_alarm_entry 72 { 73 rf_SetTimer crono; 74 } thr_alarm_entry; 75 76 #elif defined(__EMX__) || defined(OS2) 77 78 typedef struct st_thr_alarm_entry 79 { 80 uint crono; 81 uint event; 82 } thr_alarm_entry; 83 84 #else /* System with posix threads */ 85 86 typedef int thr_alarm_entry; 87 88 #define thr_got_alarm(thr_alarm) (**(thr_alarm)) 89 90 #endif /* __WIN__ */ 91 92 typedef thr_alarm_entry* thr_alarm_t; 93 94 typedef struct st_alarm { 95 ulong expire_time; 96 thr_alarm_entry alarmed; /* set when alarm is due */ 97 pthread_t thread; 98 my_bool malloced; 99 } ALARM; 100 101 #define thr_alarm_init(A) (*(A))=0 102 #define thr_alarm_in_use(A) (*(A)!= 0) 103 void init_thr_alarm(uint max_alarm); 104 void resize_thr_alarm(uint max_alarms); 105 my_bool thr_alarm(thr_alarm_t *alarmed, uint sec, ALARM *buff); 106 void thr_alarm_kill(pthread_t thread_id); 107 void thr_end_alarm(thr_alarm_t *alarmed); 108 void end_thr_alarm(my_bool free_structures); 109 sig_handler process_alarm(int); 110 #ifndef thr_got_alarm 111 bool thr_got_alarm(thr_alarm_t *alrm); 112 #endif 113 114 115 #endif /* DONT_USE_THR_ALARM */ 116 117 #ifdef __cplusplus 118 } 119 #endif /* __cplusplus */ 120 #endif /* _thr_alarm_h */ 121