mariadb/mysys/thr_alarm.c
unknown cfab46f546 Update copyright
Fixed memory leak on shutdown (Affects the embedded version & MyODBC)


client/client_priv.h:
  Update copyright
client/completion_hash.cc:
  Update copyright
client/completion_hash.h:
  Update copyright
client/connect_test.c:
  Update copyright
client/errmsg.c:
  Update copyright
client/get_password.c:
  Update copyright
client/insert_test.c:
  Update copyright
client/list_test.c:
  Update copyright
client/my_readline.h:
  Update copyright
client/mysql.cc:
  Update copyright
client/mysqladmin.c:
  Update copyright
client/mysqlbinlog.cc:
  Update copyright
client/mysqlcheck.c:
  Update copyright
client/mysqldump.c:
  Update copyright
client/mysqlimport.c:
  Update copyright
client/mysqlmanager-pwgen.c:
  Update copyright
client/mysqlmanagerc.c:
  Update copyright
client/mysqlshow.c:
  Update copyright
client/mysqltest.c:
  Update copyright
client/password.c:
  Update copyright
client/readline.cc:
  Update copyright
client/select_test.c:
  Update copyright
client/showdb_test.c:
  Update copyright
client/sql_string.cc:
  Update copyright
client/sql_string.h:
  Update copyright
client/ssl_test.c:
  Update copyright
client/thimble.cc:
  Update copyright
client/thread_test.c:
  Update copyright
div/deadlock_test.c:
  Update copyright
extra/comp_err.c:
  Update copyright
extra/my_print_defaults.c:
  Update copyright
extra/perror.c:
  Update copyright
extra/replace.c:
  Update copyright
extra/resolve_stack_dump.c:
  Update copyright
extra/resolveip.c:
  Update copyright
fs/database.c:
  Update copyright
fs/libmysqlfs.c:
  Update copyright
fs/mysqlcorbafs.c:
  Update copyright
fs/mysqlcorbafs.h:
  Update copyright
fs/mysqlcorbafs_test.c:
  Update copyright
heap/_check.c:
  Update copyright
heap/_rectest.c:
  Update copyright
heap/heapdef.h:
  Update copyright
heap/hp_block.c:
  Update copyright
heap/hp_clear.c:
  Update copyright
heap/hp_close.c:
  Update copyright
heap/hp_create.c:
  Update copyright
heap/hp_delete.c:
  Update copyright
heap/hp_extra.c:
  Update copyright
heap/hp_hash.c:
  Update copyright
heap/hp_info.c:
  Update copyright
heap/hp_open.c:
  Update copyright
heap/hp_panic.c:
  Update copyright
heap/hp_rename.c:
  Update copyright
heap/hp_rfirst.c:
  Update copyright
heap/hp_rkey.c:
  Update copyright
heap/hp_rlast.c:
  Update copyright
heap/hp_rnext.c:
  Update copyright
heap/hp_rprev.c:
  Update copyright
heap/hp_rrnd.c:
  Update copyright
heap/hp_rsame.c:
  Update copyright
heap/hp_scan.c:
  Update copyright
heap/hp_static.c:
  Update copyright
heap/hp_test1.c:
  Update copyright
heap/hp_test2.c:
  Update copyright
heap/hp_update.c:
  Update copyright
heap/hp_write.c:
  Update copyright
include/config-win.h:
  Update copyright
include/dbug.h:
  Update copyright
include/errmsg.h:
  Update copyright
include/ft_global.h:
  Update copyright
include/getopt.h:
  Update copyright
include/hash.h:
  Update copyright
include/heap.h:
  Update copyright
include/m_ctype.h:
  Update copyright
include/m_string.h:
  Update copyright
include/md5.h:
  Update copyright
include/merge.h:
  Update copyright
include/my_alarm.h:
  Update copyright
include/my_base.h:
  Update copyright
include/my_bitmap.h:
  Update copyright
include/my_dir.h:
  Update copyright
include/my_global.h:
  Update copyright
include/my_list.h:
  Update copyright
include/my_net.h:
  Update copyright
include/my_no_pthread.h:
  Update copyright
include/my_nosys.h:
  Update copyright
include/my_pthread.h:
  Update copyright
include/my_sys.h:
  Update copyright
include/my_tree.h:
  Update copyright
include/myisam.h:
  Update copyright
include/myisammrg.h:
  Update copyright
include/myisampack.h:
  Update copyright
include/mysql.h:
  Update copyright
include/mysql_com.h:
  Update copyright
include/mysql_embed.h:
  Update copyright
include/mysqld_error.h:
  Update copyright
include/mysys_err.h:
  Update copyright
include/nisam.h:
  Update copyright
include/queues.h:
  Update copyright
include/raid.h:
  Update copyright
include/sslopt-case.h:
  Update copyright
include/sslopt-longopts.h:
  Update copyright
include/sslopt-usage.h:
  Update copyright
include/sslopt-vars.h:
  Update copyright
include/t_ctype.h:
  Update copyright
include/thr_alarm.h:
  Update copyright
include/thr_lock.h:
  Update copyright
include/violite.h:
  Update copyright
isam/_cache.c:
  Update copyright
isam/_dbug.c:
  Update copyright
isam/_key.c:
  Update copyright
isam/_locking.c:
  Update copyright
isam/_packrec.c:
  Update copyright
isam/_page.c:
  Update copyright
isam/_search.c:
  Update copyright
isam/_statrec.c:
  Update copyright
isam/changed.c:
  Update copyright
isam/close.c:
  Update copyright
isam/create.c:
  Update copyright
isam/delete.c:
  Update copyright
isam/extra.c:
  Update copyright
isam/info.c:
  Update copyright
isam/isamchk.c:
  Update copyright
isam/isamdef.h:
  Update copyright
isam/log.c:
  Update copyright
isam/open.c:
  Update copyright
isam/panic.c:
  Update copyright
isam/range.c:
  Update copyright
isam/rfirst.c:
  Update copyright
isam/rkey.c:
  Update copyright
isam/rlast.c:
  Update copyright
isam/rnext.c:
  Update copyright
isam/rprev.c:
  Update copyright
isam/rrnd.c:
  Update copyright
isam/rsame.c:
  Update copyright
isam/rsamepos.c:
  Update copyright
isam/sort.c:
  Update copyright
isam/static.c:
  Update copyright
isam/test1.c:
  Update copyright
isam/test2.c:
  Update copyright
isam/test3.c:
  Update copyright
isam/update.c:
  Update copyright
isam/write.c:
  Update copyright
libmysql/conf_to_src.c:
  Update copyright
libmysql/dll.c:
  Update copyright
libmysql/errmsg.c:
  Update copyright
libmysql/get_password.c:
  Update copyright
libmysql/libmysql.c:
  Update copyright
libmysql/manager.c:
  Update copyright
libmysql/net.c:
  Update copyright
libmysql/password.c:
  Update copyright
libmysqld/lib_sql.cc:
  Update copyright
libmysqld/lib_vio.c:
  Update copyright
libmysqld/libmysqld.c:
  Update copyright
merge/mrg_close.c:
  Update copyright
merge/mrg_create.c:
  Update copyright
merge/mrg_def.h:
  Update copyright
merge/mrg_delete.c:
  Update copyright
merge/mrg_extra.c:
  Update copyright
merge/mrg_info.c:
  Update copyright
merge/mrg_locking.c:
  Update copyright
merge/mrg_open.c:
  Update copyright
merge/mrg_panic.c:
  Update copyright
merge/mrg_rrnd.c:
  Update copyright
merge/mrg_rsame.c:
  Update copyright
merge/mrg_static.c:
  Update copyright
merge/mrg_update.c:
  Update copyright
myisam/ft_boolean_search.c:
  Update copyright
myisam/ft_dump.c:
  Update copyright
myisam/ft_eval.h:
  Update copyright
myisam/ft_static.c:
  Update copyright
myisam/ft_stem.c:
  Update copyright
myisam/ft_stopwords.c:
  Update copyright
myisam/ft_test1.h:
  Update copyright
myisam/mi_cache.c:
  Update copyright
myisam/mi_changed.c:
  Update copyright
myisam/mi_check.c:
  Update copyright
myisam/mi_checksum.c:
  Update copyright
myisam/mi_close.c:
  Update copyright
myisam/mi_create.c:
  Update copyright
myisam/mi_dbug.c:
  Update copyright
myisam/mi_delete.c:
  Update copyright
myisam/mi_delete_all.c:
  Update copyright
myisam/mi_delete_table.c:
  Update copyright
myisam/mi_dynrec.c:
  Update copyright
myisam/mi_extra.c:
  Update copyright
myisam/mi_info.c:
  Update copyright
myisam/mi_key.c:
  Update copyright
myisam/mi_locking.c:
  Update copyright
myisam/mi_log.c:
  Update copyright
myisam/mi_open.c:
  Update copyright
myisam/mi_packrec.c:
  Update copyright
myisam/mi_page.c:
  Update copyright
myisam/mi_panic.c:
  Update copyright
myisam/mi_range.c:
  Update copyright
myisam/mi_rename.c:
  Update copyright
myisam/mi_rfirst.c:
  Update copyright
myisam/mi_rlast.c:
  Update copyright
myisam/mi_rnext_same.c:
  Update copyright
myisam/mi_rrnd.c:
  Update copyright
myisam/mi_rsame.c:
  Update copyright
myisam/mi_rsamepos.c:
  Update copyright
myisam/mi_scan.c:
  Update copyright
myisam/mi_search.c:
  Update copyright
myisam/mi_static.c:
  Update copyright
myisam/mi_statrec.c:
  Update copyright
myisam/mi_test1.c:
  Update copyright
myisam/mi_test2.c:
  Update copyright
myisam/mi_test3.c:
  Update copyright
myisam/mi_unique.c:
  Update copyright
myisam/mi_update.c:
  Update copyright
myisam/mi_write.c:
  Update copyright
myisam/myisamchk.c:
  Update copyright
myisam/myisampack.c:
  Update copyright
myisammrg/myrg_close.c:
  Update copyright
myisammrg/myrg_create.c:
  Update copyright
myisammrg/myrg_def.h:
  Update copyright
myisammrg/myrg_delete.c:
  Update copyright
myisammrg/myrg_locking.c:
  Update copyright
myisammrg/myrg_open.c:
  Update copyright
myisammrg/myrg_panic.c:
  Update copyright
myisammrg/myrg_rsame.c:
  Update copyright
myisammrg/myrg_static.c:
  Update copyright
myisammrg/myrg_update.c:
  Update copyright
myisammrg/myrg_write.c:
  Update copyright
mysql-test/r/gcc296.result:
  Update of benchmark results
mysql-test/r/innodb.result:
  Update of benchmark results
mysql-test/r/join_outer.result:
  Update of benchmark results
mysql-test/r/myisam.result:
  Update of benchmark results
mysys/array.c:
  Update copyright
mysys/charset.c:
  Fix for restart of character sets
mysys/checksum.c:
  Update copyright
mysys/default.c:
  Update copyright
mysys/errors.c:
  Update copyright
mysys/getopt.c:
  Cleanup
mysys/getvar.c:
  Update copyright
mysys/hash.c:
  Update copyright
mysys/list.c:
  Update copyright
mysys/make-conf.c:
  Update copyright
mysys/md5.c:
  Update copyright
mysys/mf_brkhant.c:
  Update copyright
mysys/mf_cache.c:
  Update copyright
mysys/mf_casecnv.c:
  Update copyright
mysys/mf_dirname.c:
  Update copyright
mysys/mf_fn_ext.c:
  Update copyright
mysys/mf_format.c:
  Update copyright
mysys/mf_getdate.c:
  Update copyright
mysys/mf_iocache.c:
  Update copyright
mysys/mf_iocache2.c:
  Update copyright
mysys/mf_keycache.c:
  Update copyright
mysys/mf_loadpath.c:
  Update copyright
mysys/mf_pack.c:
  Update copyright
mysys/mf_path.c:
  Update copyright
mysys/mf_qsort.c:
  Update copyright
mysys/mf_qsort2.c:
  Update copyright
mysys/mf_radix.c:
  Update copyright
mysys/mf_same.c:
  Update copyright
mysys/mf_sleep.c:
  Update copyright
mysys/mf_sort.c:
  Update copyright
mysys/mf_soundex.c:
  Update copyright
mysys/mf_stripp.c:
  Update copyright
mysys/mf_tempfile.c:
  Update copyright
mysys/mf_unixpath.c:
  Update copyright
mysys/mf_util.c:
  Update copyright
mysys/mf_wcomp.c:
  Update copyright
mysys/mf_wfile.c:
  Update copyright
mysys/mulalloc.c:
  Update copyright
mysys/my_alarm.c:
  Update copyright
mysys/my_alloc.c:
  Update copyright
mysys/my_append.c:
  Update copyright
mysys/my_bit.c:
  Update copyright
mysys/my_bitmap.c:
  Update copyright
mysys/my_chsize.c:
  Update copyright
mysys/my_clock.c:
  Update copyright
mysys/my_compress.c:
  Update copyright
mysys/my_copy.c:
  Update copyright
mysys/my_create.c:
  Update copyright
mysys/my_delete.c:
  Update copyright
mysys/my_div.c:
  Update copyright
mysys/my_dup.c:
  Update copyright
mysys/my_error.c:
  Update copyright
mysys/my_fopen.c:
  Update copyright
mysys/my_fstream.c:
  Update copyright
mysys/my_getwd.c:
  Update copyright
mysys/my_init.c:
  Free 'once_alloc' memory at shutdown.
mysys/my_lib.c:
  Update copyright
mysys/my_lock.c:
  Update copyright
mysys/my_lockmem.c:
  Update copyright
mysys/my_lread.c:
  Update copyright
mysys/my_lwrite.c:
  Update copyright
mysys/my_malloc.c:
  Update copyright
mysys/my_messnc.c:
  Update copyright
mysys/my_mkdir.c:
  Update copyright
mysys/my_net.c:
  Update copyright
mysys/my_once.c:
  Update copyright
mysys/my_open.c:
  Update copyright
mysys/my_pread.c:
  Update copyright
mysys/my_pthread.c:
  Update copyright
mysys/my_quick.c:
  Update copyright
mysys/my_read.c:
  Update copyright
mysys/my_realloc.c:
  Update copyright
mysys/my_redel.c:
  Update copyright
mysys/my_rename.c:
  Update copyright
mysys/my_seek.c:
  Update copyright
mysys/my_static.c:
  Update copyright
mysys/my_static.h:
  Update copyright
mysys/my_symlink.c:
  Update copyright
mysys/my_symlink2.c:
  Update copyright
mysys/my_tempnam.c:
  Update copyright
mysys/my_thr_init.c:
  Update copyright
mysys/my_vsnprintf.c:
  Update copyright
mysys/my_wincond.c:
  Update copyright
mysys/my_winthread.c:
  Update copyright
mysys/my_write.c:
  Update copyright
mysys/mysys_priv.h:
  Update copyright
mysys/ptr_cmp.c:
  Update copyright
mysys/queues.c:
  Update copyright
mysys/raid.cc:
  Update copyright
mysys/safemalloc.c:
  Update copyright
mysys/string.c:
  Update copyright
mysys/test_charset.c:
  Update copyright
mysys/test_dir.c:
  Update copyright
mysys/test_fn.c:
  Update copyright
mysys/testhash.c:
  Update copyright
mysys/thr_alarm.c:
  Update copyright
mysys/thr_lock.c:
  Update copyright
mysys/thr_mutex.c:
  Update copyright
mysys/thr_rwlock.c:
  Update copyright
mysys/tree.c:
  Update copyright
mysys/typelib.c:
  Update copyright
pstack/debug.c:
  Update copyright
pstack/debug.h:
  Update copyright
pstack/demangle.h:
  Update copyright
pstack/ieee.c:
  Update copyright
pstack/ieee.h:
  Update copyright
pstack/pstack.c:
  Update copyright
readline/bind.c:
  Cleanup empty lines
readline/complete.c:
  Cleanup empty lines
readline/display.c:
  Cleanup empty lines
readline/funmap.c:
  Cleanup empty lines
readline/histexpand.c:
  Cleanup empty lines
readline/histfile.c:
  Cleanup empty lines
readline/history.c:
  Cleanup empty lines
readline/history.h:
  Cleanup empty lines
readline/input.c:
  Cleanup empty lines
readline/kill.c:
  Cleanup empty lines
readline/readline.c:
  Cleanup empty lines
readline/readline.h:
  Cleanup empty lines
readline/vi_mode.c:
  Cleanup empty lines
sql/cache_manager.cc:
  Update copyright
sql/cache_manager.h:
  Update copyright
sql/convert.cc:
  Update copyright
sql/custom_conf.h:
  Update copyright
sql/derror.cc:
  Update copyright
sql/field.cc:
  Update copyright
sql/field.h:
  Update copyright
sql/field_conv.cc:
  Update copyright
sql/filesort.cc:
  Update copyright
sql/frm_crypt.cc:
  Update copyright
sql/ha_berkeley.cc:
  Update copyright
sql/ha_heap.cc:
  Update copyright
sql/ha_heap.h:
  Update copyright
sql/ha_innobase.cc:
  Update copyright
sql/ha_isam.cc:
  Update copyright
sql/ha_isam.h:
  Update copyright
sql/ha_isammrg.cc:
  Update copyright
sql/ha_isammrg.h:
  Update copyright
sql/ha_myisam.cc:
  Update copyright
sql/handler.cc:
  Update copyright
sql/hash_filo.cc:
  Update copyright
sql/hash_filo.h:
  Update copyright
sql/hostname.cc:
  Update copyright
sql/init.cc:
  Update copyright
sql/item.cc:
  Update copyright
sql/item.h:
  Update copyright
sql/item_buff.cc:
  Update copyright
sql/item_cmpfunc.cc:
  Update copyright
sql/item_cmpfunc.h:
  Update copyright
sql/item_create.cc:
  Update copyright
sql/item_create.h:
  Update copyright
sql/item_func.cc:
  Update copyright
sql/item_strfunc.cc:
  Update copyright
sql/item_sum.cc:
  Update copyright
sql/item_sum.h:
  Update copyright
sql/item_timefunc.cc:
  Update copyright
sql/item_timefunc.h:
  Update copyright
sql/item_uniq.cc:
  Update copyright
sql/item_uniq.h:
  Update copyright
sql/key.cc:
  Update copyright
sql/lex_symbol.h:
  Update copyright
sql/lock.cc:
  Update copyright
sql/log.cc:
  Update copyright
sql/log_event.cc:
  Update copyright
sql/log_event.h:
  Update copyright
sql/matherr.c:
  Update copyright
sql/mf_iocache.cc:
  Update copyright
sql/mini_client.cc:
  Update copyright
sql/mini_client.h:
  Update copyright
sql/my_lock.c:
  Update copyright
sql/mysqld.cc:
  Update copyright
sql/net_pkg.cc:
  Update copyright
sql/net_serv.cc:
  Update copyright
sql/opt_sum.cc:
  Update copyright
sql/password.c:
  Update copyright
sql/procedure.cc:
  Update copyright
sql/procedure.h:
  Update copyright
sql/records.cc:
  Update copyright
sql/repl_failsafe.cc:
  Update copyright
sql/slave.cc:
  Update copyright
sql/slave.h:
  Update copyright
sql/sql_acl.cc:
  Update copyright
sql/sql_acl.h:
  Update copyright
sql/sql_analyse.cc:
  Update copyright
sql/sql_analyse.h:
  Update copyright
sql/sql_base.cc:
  Update copyright
sql/sql_cache.cc:
  Update copyright
sql/sql_class.cc:
  Update copyright
sql/sql_class.h:
  Update copyright
sql/sql_crypt.cc:
  Update copyright
sql/sql_crypt.h:
  Update copyright
sql/sql_db.cc:
  Update copyright
sql/sql_delete.cc:
  Update copyright
sql/sql_handler.cc:
  Update copyright
sql/sql_insert.cc:
  Update copyright
sql/sql_lex.cc:
  Update copyright
sql/sql_lex.h:
  Update copyright
sql/sql_list.cc:
  Update copyright
sql/sql_list.h:
  Update copyright
sql/sql_load.cc:
  Update copyright
sql/sql_map.cc:
  Update copyright
sql/sql_map.h:
  Update copyright
sql/sql_parse.cc:
  Update copyright
sql/sql_rename.cc:
  Update copyright
sql/sql_repl.cc:
  Update copyright
sql/sql_select.h:
  Update copyright
sql/sql_string.cc:
  Update copyright
sql/sql_string.h:
  Update copyright
sql/sql_table.cc:
  Update copyright
sql/sql_test.cc:
  Update copyright
sql/sql_udf.cc:
  Update copyright
sql/sql_udf.h:
  Update copyright
sql/stacktrace.c:
  Update copyright
sql/structs.h:
  Update copyright
sql/table.cc:
  Update copyright
sql/table.h:
  Update copyright
sql/thr_malloc.cc:
  Update copyright
sql/time.cc:
  Update copyright
sql/udf_example.cc:
  Update copyright
sql/uniques.cc:
  Update copyright
sql/unireg.cc:
  Update copyright
sql/unireg.h:
  Update copyright
strings/atof.c:
  Update copyright
strings/bchange.c:
  Update copyright
strings/bcmp.c:
  Update copyright
strings/bcopy-duff.c:
  Update copyright
strings/bfill.c:
  Update copyright
strings/bmove.c:
  Update copyright
strings/bmove512.c:
  Update copyright
strings/bmove_upp.c:
  Update copyright
strings/bzero.c:
  Update copyright
strings/conf_to_src.c:
  Update copyright
strings/ctype-big5.c:
  Update copyright
strings/ctype-czech.c:
  Update copyright
strings/ctype-euc_kr.c:
  Update copyright
strings/ctype-gb2312.c:
  Update copyright
strings/ctype-gbk.c:
  Update copyright
strings/ctype-latin1_de.c:
  Update copyright
strings/ctype-sjis.c:
  Update copyright
strings/ctype-tis620.c:
  Update copyright
strings/ctype-ujis.c:
  Update copyright
strings/ctype.c:
  Update copyright
strings/do_ctype.c:
  Update copyright
strings/int2str.c:
  Update copyright
strings/is_prefix.c:
  Update copyright
strings/llstr.c:
  Update copyright
strings/longlong2str.c:
  Update copyright
strings/memcmp.c:
  Update copyright
strings/memcpy.c:
  Update copyright
strings/memset.c:
  Update copyright
strings/r_strinstr.c:
  Update copyright
strings/str2int.c:
  Update copyright
strings/str_test.c:
  Update copyright
strings/strappend.c:
  Update copyright
strings/strcat.c:
  Update copyright
strings/strcend.c:
  Update copyright
strings/strchr.c:
  Update copyright
strings/strcmp.c:
  Update copyright
strings/strcont.c:
  Update copyright
strings/strend.c:
  Update copyright
strings/strfill.c:
  Update copyright
strings/strings-not-used.h:
  Update copyright
strings/strinstr.c:
  Update copyright
strings/strlen.c:
  Update copyright
strings/strmake.c:
  Update copyright
strings/strmov.c:
  Update copyright
strings/strnlen.c:
  Update copyright
strings/strnmov.c:
  Update copyright
strings/strrchr.c:
  Update copyright
strings/strstr.c:
  Update copyright
strings/strto.c:
  Update copyright
strings/strtol.c:
  Update copyright
strings/strtoll.c:
  Update copyright
strings/strtoul.c:
  Update copyright
strings/strtoull.c:
  Update copyright
strings/strxmov.c:
  Update copyright
strings/strxnmov.c:
  Update copyright
strings/t_ctype.h:
  Update copyright
strings/udiv.c:
  Update copyright
tools/mysqlmanager.c:
  Update copyright
vio/test-ssl.c:
  Update copyright
vio/test-sslclient.c:
  Update copyright
vio/test-sslserver.c:
  Update copyright
vio/vio.c:
  Update copyright
vio/viosocket.c:
  Update copyright
vio/viossl.c:
  Update copyright
vio/viosslfactories.c:
  Update copyright
vio/viotest-ssl.c:
  Update copyright
2001-12-06 14:10:51 +02:00

954 lines
24 KiB
C

/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <my_global.h>
#if defined(THREAD) && !defined(DONT_USE_THR_ALARM)
#include <errno.h>
#include <my_pthread.h>
#include <signal.h>
#include <my_sys.h>
#include <m_string.h>
#include <queues.h>
#include "thr_alarm.h"
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h> /* AIX needs this for fd_set */
#endif
#ifndef ETIME
#define ETIME ETIMEDOUT
#endif
static my_bool alarm_aborted=1;
my_bool thr_alarm_inited=0;
#if !defined(__WIN__) && !defined(__EMX__) && !defined(OS2)
static pthread_mutex_t LOCK_alarm;
static sigset_t full_signal_set;
static QUEUE alarm_queue;
pthread_t alarm_thread;
#ifdef USE_ALARM_THREAD
static pthread_cond_t COND_alarm;
static void *alarm_handler(void *arg);
#define reschedule_alarms() pthread_cond_signal(&COND_alarm)
#else
#define reschedule_alarms() pthread_kill(alarm_thread,THR_SERVER_ALARM)
#endif
#if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD)
static sig_handler thread_alarm(int sig __attribute__((unused)));
#endif
static int compare_ulong(void *not_used __attribute__((unused)),
byte *a_ptr,byte* b_ptr)
{
ulong a=*((ulong*) a_ptr),b= *((ulong*) b_ptr);
return (a < b) ? -1 : (a == b) ? 0 : 1;
}
void init_thr_alarm(uint max_alarms)
{
sigset_t s;
DBUG_ENTER("init_thr_alarm");
alarm_aborted=0;
init_queue(&alarm_queue,max_alarms+1,offsetof(ALARM,expire_time),0,
compare_ulong,NullS);
sigfillset(&full_signal_set); /* Neaded to block signals */
pthread_mutex_init(&LOCK_alarm,MY_MUTEX_INIT_FAST);
#if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD)
#if defined(HAVE_mit_thread)
sigset(THR_CLIENT_ALARM,thread_alarm); /* int. thread system calls */
#else
{
struct sigaction sact;
sact.sa_flags = 0;
sact.sa_handler = thread_alarm;
sigaction(THR_CLIENT_ALARM, &sact, (struct sigaction*) 0);
}
#endif
#endif
sigemptyset(&s);
sigaddset(&s, THR_SERVER_ALARM);
alarm_thread=pthread_self();
#if defined(USE_ALARM_THREAD)
{
pthread_attr_t thr_attr;
pthread_attr_init(&thr_attr);
pthread_cond_init(&COND_alarm,NULL);
pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS);
pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
pthread_attr_setstacksize(&thr_attr,8196);
my_pthread_attr_setprio(&thr_attr,100); /* Very high priority */
VOID(pthread_create(&alarm_thread,&thr_attr,alarm_handler,NULL));
VOID(pthread_attr_destroy(&thr_attr));
}
#elif defined(USE_ONE_SIGNAL_HAND)
pthread_sigmask(SIG_BLOCK, &s, NULL); /* used with sigwait() */
#if THR_SERVER_ALARM == THR_CLIENT_ALARM
sigset(THR_CLIENT_ALARM,process_alarm); /* Linuxthreads */
pthread_sigmask(SIG_UNBLOCK, &s, NULL);
#endif
#else
pthread_sigmask(SIG_UNBLOCK, &s, NULL);
sigset(THR_SERVER_ALARM,process_alarm);
#endif
DBUG_VOID_RETURN;
}
/*
** Request alarm after sec seconds.
** A pointer is returned with points to a non-zero int when the alarm has been
** given. This can't be called from the alarm-handling thread.
** Returns 0 if no more alarms are allowed (aborted by process)
*/
bool thr_alarm(thr_alarm_t *alrm, uint sec, ALARM *alarm_data)
{
ulong now;
sigset_t old_mask;
my_bool reschedule;
DBUG_ENTER("thr_alarm");
DBUG_PRINT("enter",("thread: %s sec: %d",my_thread_name(),sec));
now=(ulong) time((time_t*) 0);
pthread_sigmask(SIG_BLOCK,&full_signal_set,&old_mask);
pthread_mutex_lock(&LOCK_alarm); /* Lock from threads & alarms */
if (alarm_aborted)
{ /* No signal thread */
DBUG_PRINT("info", ("alarm aborted"));
pthread_mutex_unlock(&LOCK_alarm);
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
DBUG_RETURN(1);
}
if (alarm_queue.elements == alarm_queue.max_elements)
{
DBUG_PRINT("info", ("alarm queue full"));
fprintf(stderr,"Warning: thr_alarm queue is full\n");
pthread_mutex_unlock(&LOCK_alarm);
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
DBUG_RETURN(1);
}
reschedule= (!alarm_queue.elements ||
(int) (((ALARM*) queue_top(&alarm_queue))->expire_time - now) >
(int) sec);
if (!alarm_data)
{
if (!(alarm_data=(ALARM*) my_malloc(sizeof(ALARM),MYF(MY_WME))))
{
DBUG_PRINT("info", ("failed my_malloc()"));
pthread_mutex_unlock(&LOCK_alarm);
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
DBUG_RETURN(1);
}
alarm_data->malloced=1;
}
else
alarm_data->malloced=0;
alarm_data->expire_time=now+sec;
alarm_data->alarmed=0;
alarm_data->thread=pthread_self();
queue_insert(&alarm_queue,(byte*) alarm_data);
/* Reschedule alarm if the current one has more than sec left */
if (reschedule)
{
DBUG_PRINT("info", ("reschedule"));
if (pthread_equal(pthread_self(),alarm_thread))
alarm(sec); /* purecov: inspected */
else
reschedule_alarms(); /* Reschedule alarms */
}
pthread_mutex_unlock(&LOCK_alarm);
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
(*alrm)= &alarm_data->alarmed;
DBUG_RETURN(0);
}
/*
** Remove alarm from list of alarms
*/
void thr_end_alarm(thr_alarm_t *alarmed)
{
ALARM *alarm_data;
sigset_t old_mask;
uint i;
bool found=0;
DBUG_ENTER("thr_end_alarm");
pthread_sigmask(SIG_BLOCK,&full_signal_set,&old_mask);
pthread_mutex_lock(&LOCK_alarm);
alarm_data= (ALARM*) ((byte*) *alarmed - offsetof(ALARM,alarmed));
for (i=0 ; i < alarm_queue.elements ; i++)
{
if ((ALARM*) queue_element(&alarm_queue,i) == alarm_data)
{
queue_remove(&alarm_queue,i),MYF(0);
if (alarm_data->malloced)
my_free((gptr) alarm_data,MYF(0));
found=1;
break;
}
}
if (!found)
{
#ifdef MAIN
printf("Warning: Didn't find alarm %lx in queue of %d alarms\n",
(long) *alarmed, alarm_queue.elements);
#endif
DBUG_PRINT("warning",("Didn't find alarm %lx in queue\n",*alarmed));
}
if (alarm_aborted && !alarm_queue.elements)
delete_queue(&alarm_queue);
pthread_mutex_unlock(&LOCK_alarm);
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
DBUG_VOID_RETURN;
}
/*
Come here when some alarm in queue is due.
Mark all alarms with are finnished in list.
Shedule alarms to be sent again after 1-10 sec (many alarms at once)
If alarm_aborted is set then all alarms are given and resent
every second.
*/
sig_handler process_alarm(int sig __attribute__((unused)))
{
sigset_t old_mask;
ALARM *alarm_data;
DBUG_ENTER("process_alarm");
DBUG_PRINT("info",("sig: %d active alarms: %d",sig,alarm_queue.elements));
#if THR_SERVER_ALARM == THR_CLIENT_ALARM
if (!pthread_equal(pthread_self(),alarm_thread))
{
#if defined(MAIN) && !defined(__bsdi__)
printf("thread_alarm\n"); fflush(stdout);
#endif
#ifdef DONT_REMEMBER_SIGNAL
sigset(THR_CLIENT_ALARM,process_alarm); /* int. thread system calls */
#endif
DBUG_VOID_RETURN;
}
#endif
#if defined(MAIN) && !defined(__bsdi__)
printf("process_alarm\n"); fflush(stdout);
#endif
#ifndef USE_ALARM_THREAD
pthread_sigmask(SIG_SETMASK,&full_signal_set,&old_mask);
pthread_mutex_lock(&LOCK_alarm);
#endif
if (alarm_queue.elements)
{
if (alarm_aborted)
{
uint i;
for (i=0 ; i < alarm_queue.elements ;)
{
alarm_data=(ALARM*) queue_element(&alarm_queue,i);
alarm_data->alarmed=1; /* Info to thread */
if (pthread_equal(alarm_data->thread,alarm_thread) ||
pthread_kill(alarm_data->thread, THR_CLIENT_ALARM))
{
#ifdef MAIN
printf("Warning: pthread_kill couldn't find thread!!!\n");
#endif
queue_remove(&alarm_queue,i); /* No thread. Remove alarm */
}
else
i++; /* Signal next thread */
}
#ifndef USE_ALARM_THREAD
if (alarm_queue.elements)
alarm(1); /* Signal soon again */
#endif
}
else
{
ulong now=(ulong) time((time_t*) 0);
ulong next=now+10-(now%10);
while ((alarm_data=(ALARM*) queue_top(&alarm_queue))->expire_time <= now)
{
alarm_data->alarmed=1; /* Info to thread */
DBUG_PRINT("info",("sending signal to waiting thread"));
if (pthread_equal(alarm_data->thread,alarm_thread) ||
pthread_kill(alarm_data->thread, THR_CLIENT_ALARM))
{
#ifdef MAIN
printf("Warning: pthread_kill couldn't find thread!!!\n");
#endif
queue_remove(&alarm_queue,0); /* No thread. Remove alarm */
if (!alarm_queue.elements)
break;
}
else
{
alarm_data->expire_time=next;
queue_replaced(&alarm_queue);
}
}
#ifndef USE_ALARM_THREAD
if (alarm_queue.elements)
{
#ifdef __bsdi__
alarm(0); /* Remove old alarm */
#endif
alarm((uint) (alarm_data->expire_time-now));
}
#endif
}
}
#ifndef USE_ALARM_THREAD
#if defined(DONT_REMEMBER_SIGNAL) && !defined(USE_ONE_SIGNAL_HAND)
sigset(THR_SERVER_ALARM,process_alarm);
#endif
pthread_mutex_unlock(&LOCK_alarm);
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
#endif
DBUG_VOID_RETURN;
}
/*
** Shedule all alarms now.
** When all alarms are given, Free alarm memory and don't allow more alarms.
*/
void end_thr_alarm(void)
{
DBUG_ENTER("end_thr_alarm");
pthread_mutex_lock(&LOCK_alarm);
if (!alarm_aborted)
{
DBUG_PRINT("info",("Resheduling %d waiting alarms",alarm_queue.elements));
alarm_aborted=1; /* mark aborted */
if (!alarm_queue.elements)
delete_queue(&alarm_queue);
if (pthread_equal(pthread_self(),alarm_thread))
alarm(1); /* Shut down everything soon */
else
reschedule_alarms();
}
pthread_mutex_unlock(&LOCK_alarm);
DBUG_VOID_RETURN;
}
/*
** Remove another thread from the alarm
*/
void thr_alarm_kill(pthread_t thread_id)
{
uint i;
pthread_mutex_lock(&LOCK_alarm);
for (i=0 ; i < alarm_queue.elements ; i++)
{
if (pthread_equal(((ALARM*) queue_element(&alarm_queue,i))->thread,
thread_id))
{
ALARM *tmp=(ALARM*) queue_remove(&alarm_queue,i);
tmp->expire_time=0;
queue_insert(&alarm_queue,(byte*) tmp);
reschedule_alarms();
break;
}
}
pthread_mutex_unlock(&LOCK_alarm);
}
/*
** This is here for thread to get interruptet from read/write/fcntl
** ARGSUSED
*/
#if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD)
static sig_handler thread_alarm(int sig)
{
#ifdef MAIN
printf("thread_alarm\n"); fflush(stdout);
#endif
#ifdef DONT_REMEMBER_SIGNAL
sigset(sig,thread_alarm); /* int. thread system calls */
#endif
}
#endif
#ifdef HAVE_TIMESPEC_TS_SEC
#define tv_sec ts_sec
#define tv_nsec ts_nsec
#endif
/* set up a alarm thread with uses 'sleep' to sleep between alarms */
#ifdef USE_ALARM_THREAD
static void *alarm_handler(void *arg __attribute__((unused)))
{
int error;
struct timespec abstime;
#ifdef MAIN
puts("Starting alarm thread");
#endif
my_thread_init();
pthread_mutex_lock(&LOCK_alarm);
for (;;)
{
if (alarm_queue.elements)
{
ulong sleep_time,now=time((time_t*) 0);
if (alarm_aborted)
sleep_time=now+1;
else
sleep_time= ((ALARM*) queue_top(&alarm_queue))->expire_time;
if (sleep_time > now)
{
abstime.tv_sec=sleep_time;
abstime.tv_nsec=0;
if ((error=pthread_cond_timedwait(&COND_alarm,&LOCK_alarm,&abstime)) &&
error != ETIME && error != ETIMEDOUT)
{
#ifdef MAIN
printf("Got error: %d from ptread_cond_timedwait (errno: %d)\n",
error,errno);
#endif
}
}
}
else if (alarm_aborted)
break;
else if ((error=pthread_cond_wait(&COND_alarm,&LOCK_alarm)))
{
#ifdef MAIN
printf("Got error: %d from ptread_cond_wait (errno: %d)\n",
error,errno);
#endif
}
process_alarm(0);
}
bzero((char*) &alarm_thread,sizeof(alarm_thread)); /* For easy debugging */
pthread_mutex_unlock(&LOCK_alarm);
pthread_exit(0);
return 0; /* Impossible */
}
#endif /* USE_ALARM_THREAD */
/*****************************************************************************
** thr_alarm for OS/2
*****************************************************************************/
#elif defined(__EMX__) || defined(OS2)
#define INCL_BASE
#define INCL_NOPMAPI
#include <os2.h>
static pthread_mutex_t LOCK_alarm;
static sigset_t full_signal_set;
static QUEUE alarm_queue;
pthread_t alarm_thread;
#ifdef USE_ALARM_THREAD
static pthread_cond_t COND_alarm;
static void *alarm_handler(void *arg);
#define reschedule_alarms() pthread_cond_signal(&COND_alarm)
#else
#define reschedule_alarms() pthread_kill(alarm_thread,THR_SERVER_ALARM)
#endif
sig_handler process_alarm(int sig __attribute__((unused)))
{
sigset_t old_mask;
ALARM *alarm_data;
DBUG_PRINT("info",("sig: %d active alarms: %d",sig,alarm_queue.elements));
}
/*
** Remove another thread from the alarm
*/
void thr_alarm_kill(pthread_t thread_id)
{
uint i;
pthread_mutex_lock(&LOCK_alarm);
for (i=0 ; i < alarm_queue.elements ; i++)
{
if (pthread_equal(((ALARM*) queue_element(&alarm_queue,i))->thread,
thread_id))
{
ALARM *tmp=(ALARM*) queue_remove(&alarm_queue,i);
tmp->expire_time=0;
queue_insert(&alarm_queue,(byte*) tmp);
reschedule_alarms();
break;
}
}
pthread_mutex_unlock(&LOCK_alarm);
}
bool thr_alarm(thr_alarm_t *alrm, uint sec, ALARM *alarm)
{
APIRET rc;
if (alarm_aborted)
{
alarm->alarmed.crono=0;
alarm->alarmed.event=0;
return 1;
}
if (rc = DosCreateEventSem(NULL,(HEV *) &alarm->alarmed.event,
DC_SEM_SHARED,FALSE))
{
printf("Error creating event semaphore! [%d] \n",rc);
alarm->alarmed.crono=0;
alarm->alarmed.event=0;
return 1;
}
if (rc = DosAsyncTimer((long) sec*1000L, (HSEM) alarm->alarmed.event,
(HTIMER *) &alarm->alarmed.crono))
{
printf("Error starting async timer! [%d] \n",rc);
DosCloseEventSem((HEV) alarm->alarmed.event);
alarm->alarmed.crono=0;
alarm->alarmed.event=0;
return 1;
} /* endif */
(*alrm)= &alarm->alarmed;
return 1;
}
bool thr_got_alarm(thr_alarm_t *alrm_ptr)
{
thr_alarm_t alrm= *alrm_ptr;
APIRET rc;
if (alrm->crono)
{
rc = DosWaitEventSem((HEV) alrm->event, SEM_IMMEDIATE_RETURN);
if (rc == 0) {
DosCloseEventSem((HEV) alrm->event);
alrm->crono = 0;
alrm->event = 0;
} /* endif */
}
return !alrm->crono || alarm_aborted;
}
void thr_end_alarm(thr_alarm_t *alrm_ptr)
{
thr_alarm_t alrm= *alrm_ptr;
if (alrm->crono)
{
DosStopTimer((HTIMER) alrm->crono);
DosCloseEventSem((HEV) alrm->event);
alrm->crono = 0;
alrm->event = 0;
}
}
void end_thr_alarm(void)
{
DBUG_ENTER("end_thr_alarm");
alarm_aborted=1; /* No more alarms */
DBUG_VOID_RETURN;
}
void init_thr_alarm(uint max_alarm)
{
DBUG_ENTER("init_thr_alarm");
alarm_aborted=0; /* Yes, Gimmie alarms */
DBUG_VOID_RETURN;
}
/*****************************************************************************
** thr_alarm for win95
*****************************************************************************/
#else /* __WIN__ */
void thr_alarm_kill(pthread_t thread_id)
{
/* Can't do this yet */
}
sig_handler process_alarm(int sig __attribute__((unused)))
{
/* Can't do this yet */
}
bool thr_alarm(thr_alarm_t *alrm, uint sec, ALARM *alarm)
{
if (alarm_aborted)
{
alarm->alarmed.crono=0;
return 1;
}
if (!(alarm->alarmed.crono=SetTimer((HWND) NULL,0, sec*1000,
(TIMERPROC) NULL)))
return 1;
(*alrm)= &alarm->alarmed;
return 0;
}
bool thr_got_alarm(thr_alarm_t *alrm_ptr)
{
thr_alarm_t alrm= *alrm_ptr;
MSG msg;
if (alrm->crono)
{
PeekMessage(&msg,NULL,WM_TIMER,WM_TIMER,PM_REMOVE) ;
if (msg.message == WM_TIMER || alarm_aborted)
{
KillTimer(NULL, alrm->crono);
alrm->crono = 0;
}
}
return !alrm->crono || alarm_aborted;
}
void thr_end_alarm(thr_alarm_t *alrm_ptr)
{
thr_alarm_t alrm= *alrm_ptr;
if (alrm->crono)
{
KillTimer(NULL, alrm->crono);
alrm->crono = 0;
}
}
void end_thr_alarm(void)
{
DBUG_ENTER("end_thr_alarm");
alarm_aborted=1; /* No more alarms */
DBUG_VOID_RETURN;
}
void init_thr_alarm(uint max_alarm)
{
DBUG_ENTER("init_thr_alarm");
alarm_aborted=0; /* Yes, Gimmie alarms */
DBUG_VOID_RETURN;
}
#endif /* __WIN__ */
#endif /* THREAD */
/****************************************************************************
** Handling of MAIN
***************************************************************************/
#ifdef MAIN
#if defined(THREAD) && !defined(DONT_USE_THR_ALARM)
static pthread_cond_t COND_thread_count;
static pthread_mutex_t LOCK_thread_count;
static uint thread_count;
#ifdef HPUX
typedef int * fd_set_ptr;
#else
typedef fd_set * fd_set_ptr;
#endif /* HPUX */
static void *test_thread(void *arg)
{
int i,param=*((int*) arg),wait_time,retry;
time_t start_time;
thr_alarm_t got_alarm;
fd_set fd;
FD_ZERO(&fd);
my_thread_init();
printf("Thread %d (%s) started\n",param,my_thread_name()); fflush(stdout);
for (i=1 ; i <= 10 ; i++)
{
wait_time=param ? 11-i : i;
start_time=time((time_t*) 0);
if (thr_alarm(&got_alarm,wait_time,0))
{
printf("Thread: %s Alarms aborted\n",my_thread_name());
break;
}
if (wait_time == 3)
{
printf("Thread: %s Simulation of no alarm needed\n",my_thread_name());
fflush(stdout);
}
else
{
for (retry=0 ; !thr_got_alarm(&got_alarm) && retry < 10 ; retry++)
{
printf("Thread: %s Waiting %d sec\n",my_thread_name(),wait_time);
select(0,(fd_set_ptr) &fd,0,0,0);
}
if (!thr_got_alarm(&got_alarm))
{
printf("Thread: %s didn't get an alarm. Aborting!\n",
my_thread_name());
break;
}
if (wait_time == 7)
{ /* Simulate alarm-miss */
fd_set readFDs;
uint max_connection=fileno(stdin);
FD_ZERO(&readFDs);
FD_SET(max_connection,&readFDs);
retry=0;
for (;;)
{
printf("Thread: %s Simulating alarm miss\n",my_thread_name());
fflush(stdout);
if (select(max_connection+1, (fd_set_ptr) &readFDs,0,0,0) < 0)
{
if (errno == EINTR)
break; /* Got new interrupt */
printf("Got errno: %d from select. Retrying..\n",errno);
if (retry++ >= 3)
{
printf("Warning: Interrupt of select() doesn't set errno!\n");
break;
}
}
else /* This shouldn't happen */
{
if (!FD_ISSET(max_connection,&readFDs))
{
printf("Select interrupted, but errno not set\n");
fflush(stdout);
if (retry++ >= 3)
break;
continue;
}
VOID(getchar()); /* Somebody was playing */
}
}
}
}
printf("Thread: %s Slept for %d (%d) sec\n",my_thread_name(),
(int) (time((time_t*) 0)-start_time), wait_time); fflush(stdout);
thr_end_alarm(&got_alarm);
fflush(stdout);
}
pthread_mutex_lock(&LOCK_thread_count);
thread_count--;
VOID(pthread_cond_signal(&COND_thread_count)); /* Tell main we are ready */
pthread_mutex_unlock(&LOCK_thread_count);
free((gptr) arg);
return 0;
}
#ifdef USE_ONE_SIGNAL_HAND
static sig_handler print_signal_warning(int sig)
{
printf("Warning: Got signal %d from thread %s\n",sig,my_thread_name());
fflush(stdout);
#ifdef DONT_REMEMBER_SIGNAL
sigset(sig,print_signal_warning); /* int. thread system calls */
#endif
#ifndef OS2
if (sig == SIGALRM)
alarm(2); /* reschedule alarm */
#endif
}
#endif /* USE_ONE_SIGNAL_HAND */
static void *signal_hand(void *arg __attribute__((unused)))
{
sigset_t set;
int sig,error,err_count=0;;
my_thread_init();
pthread_detach_this_thread();
init_thr_alarm(10); /* Setup alarm handler */
pthread_mutex_lock(&LOCK_thread_count); /* Required by bsdi */
VOID(pthread_cond_signal(&COND_thread_count)); /* Tell main we are ready */
pthread_mutex_unlock(&LOCK_thread_count);
#ifndef OS2
sigemptyset(&set); /* Catch all signals */
sigaddset(&set,SIGINT);
sigaddset(&set,SIGQUIT);
sigaddset(&set,SIGTERM);
#if THR_CLIENT_ALARM != SIGHUP
sigaddset(&set,SIGHUP);
#endif
#ifdef SIGTSTP
sigaddset(&set,SIGTSTP);
#endif
#ifdef USE_ONE_SIGNAL_HAND
sigaddset(&set,THR_SERVER_ALARM); /* For alarms */
puts("Starting signal and alarm handling thread");
#else
puts("Starting signal handling thread");
#endif
#endif /* OS2 */
printf("server alarm: %d thread alarm: %d\n",
THR_SERVER_ALARM,THR_CLIENT_ALARM);
DBUG_PRINT("info",("Starting signal and alarm handling thread"));
for(;;)
{
while ((error=my_sigwait(&set,&sig)) == EINTR)
printf("sigwait restarted\n");
if (error)
{
fprintf(stderr,"Got error %d from sigwait\n",error);
if (err_count++ > 5)
exit(1); /* Too many errors in test */
continue;
}
#ifdef USE_ONE_SIGNAL_HAND
if (sig != THR_SERVER_ALARM)
#endif
printf("Main thread: Got signal %d\n",sig);
switch (sig) {
case SIGINT:
case SIGQUIT:
case SIGTERM:
#ifndef OS2
case SIGHUP:
#endif
printf("Aborting nicely\n");
end_thr_alarm();
break;
#ifdef SIGTSTP
case SIGTSTP:
printf("Aborting\n");
exit(1);
return 0; /* Keep some compilers happy */
#endif
#ifndef OS2
#ifdef USE_ONE_SIGNAL_HAND
case THR_SERVER_ALARM:
process_alarm(sig);
break;
#endif
#endif /* OS2 */
}
}
}
int main(int argc __attribute__((unused)),char **argv __attribute__((unused)))
{
pthread_t tid;
pthread_attr_t thr_attr;
int i,*param,error;
sigset_t set;
MY_INIT(argv[0]);
if (argc > 1 && argv[1][0] == '-' && argv[1][1] == '#')
DBUG_PUSH(argv[1]+2);
pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST);
pthread_cond_init(&COND_thread_count,NULL);
/* Start a alarm handling thread */
#ifndef OS2
sigemptyset(&set);
sigaddset(&set,SIGINT);
sigaddset(&set,SIGQUIT);
sigaddset(&set,SIGTERM);
sigaddset(&set,SIGHUP);
signal(SIGTERM,SIG_DFL); /* If it's blocked by parent */
#ifdef SIGTSTP
sigaddset(&set,SIGTSTP);
#endif
sigaddset(&set,THR_SERVER_ALARM);
sigdelset(&set,THR_CLIENT_ALARM);
(void) pthread_sigmask(SIG_SETMASK,&set,NULL);
#ifdef NOT_USED
sigemptyset(&set);
sigaddset(&set,THR_CLIENT_ALARM);
VOID(pthread_sigmask(SIG_UNBLOCK, &set, (sigset_t*) 0));
#endif
#endif /* OS2 */
pthread_attr_init(&thr_attr);
pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS);
pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
pthread_attr_setstacksize(&thr_attr,65536L);
/* Start signal thread and wait for it to start */
VOID(pthread_mutex_lock(&LOCK_thread_count));
pthread_create(&tid,&thr_attr,signal_hand,NULL);
VOID(pthread_cond_wait(&COND_thread_count,&LOCK_thread_count));
VOID(pthread_mutex_unlock(&LOCK_thread_count));
DBUG_PRINT("info",("signal thread created"));
thr_setconcurrency(3);
pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS);
printf("Main thread: %s\n",my_thread_name());
for (i=0 ; i < 2 ; i++)
{
param=(int*) malloc(sizeof(int));
*param= i;
pthread_mutex_lock(&LOCK_thread_count);
if ((error=pthread_create(&tid,&thr_attr,test_thread,(void*) param)))
{
printf("Can't create thread %d, error: %d\n",i,error);
exit(1);
}
thread_count++;
pthread_mutex_unlock(&LOCK_thread_count);
}
pthread_attr_destroy(&thr_attr);
pthread_mutex_lock(&LOCK_thread_count);
while (thread_count)
{
VOID(pthread_cond_wait(&COND_thread_count,&LOCK_thread_count));
if (thread_count == 1)
{
printf("Calling end_thr_alarm. This should cancel the last thread\n");
end_thr_alarm();
}
}
pthread_mutex_unlock(&LOCK_thread_count);
printf("Test succeeded\n");
return 0;
}
#else /* THREAD */
int main(int argc __attribute__((unused)),char **argv __attribute__((unused)))
{
#ifndef THREAD
printf("thr_alarm disabled because we are not using threads\n");
#else
printf("thr_alarm disabled with DONT_USE_THR_ALARM\n");
#endif
exit(1);
}
#endif /* THREAD */
#endif /* MAIN */