MDEV-32567 Remove thr_alarm from server codebase

Remove alarm() remnants

- Replace thread-unsafe use of alarm() inside my_lock.c with a
  timed loop.
- Remove configure time checks
- Remove mysys my_alarm.c/my_alarm.h
This commit is contained in:
Vladislav Vaintroub 2023-10-26 18:12:09 +02:00 committed by Daniel Black
parent 013fc02a23
commit f8600b1755
8 changed files with 12 additions and 128 deletions

View file

@ -22,7 +22,6 @@
IF(MSVC)
SET(BFD_H_EXISTS 0 CACHE INTERNAL "")
SET(HAVE_ACCESS 1 CACHE INTERNAL "")
SET(HAVE_ALARM CACHE INTERNAL "")
SET(HAVE_ALLOCA_H CACHE INTERNAL "")
SET(HAVE_ARPA_INET_H CACHE INTERNAL "")
SET(HAVE_BACKTRACE CACHE INTERNAL "")

View file

@ -126,7 +126,6 @@
/* Functions we may want to use. */
#cmakedefine HAVE_ACCEPT4 1
#cmakedefine HAVE_ACCESS 1
#cmakedefine HAVE_ALARM 1
#cmakedefine HAVE_ALLOCA 1
#cmakedefine HAVE_BFILL 1
#cmakedefine HAVE_INDEX 1

View file

@ -325,7 +325,6 @@ ENDIF()
#
CHECK_FUNCTION_EXISTS (accept4 HAVE_ACCEPT4)
CHECK_FUNCTION_EXISTS (access HAVE_ACCESS)
CHECK_FUNCTION_EXISTS (alarm HAVE_ALARM)
SET(HAVE_ALLOCA 1)
CHECK_FUNCTION_EXISTS (backtrace HAVE_BACKTRACE)
CHECK_FUNCTION_EXISTS (backtrace_symbols HAVE_BACKTRACE_SYMBOLS)

View file

@ -1,69 +0,0 @@
/*
Copyright (c) 2000, 2010, Oracle and/or its affiliates.
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; version 2 of the License.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
/*
File to include when we want to use alarm or a loop_counter to display
some information when a program is running
*/
#ifndef _my_alarm_h
#define _my_alarm_h
#ifdef __cplusplus
extern "C" {
#endif
extern int volatile my_have_got_alarm;
extern ulong my_time_to_wait_for_lock;
#if defined(HAVE_ALARM) && !defined(NO_ALARM_LOOP)
#include <signal.h>
#ifdef HAVE_SIGHANDLER_T
#define sig_return sighandler_t
#elif defined(SOLARIS) || defined(__sun) || defined(__APPLE__) || \
defined(_AIX) || \
defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
defined(__DragonFly__)
typedef void (*sig_return)(int); /* Returns type from signal */
#else
typedef void (*sig_return)(void); /* Returns type from signal */
#endif
#define ALARM_VARIABLES uint alarm_old=0; \
sig_return alarm_signal=0
#define ALARM_INIT my_have_got_alarm=0 ; \
alarm_old=(uint) alarm(MY_HOW_OFTEN_TO_ALARM); \
alarm_signal=signal(SIGALRM,my_set_alarm_variable);
#define ALARM_END (void) signal(SIGALRM,alarm_signal); \
(void) alarm(alarm_old);
#define ALARM_TEST my_have_got_alarm
#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY
#define ALARM_REINIT (void) alarm(MY_HOW_OFTEN_TO_ALARM); \
(void) signal(SIGALRM,my_set_alarm_variable);\
my_have_got_alarm=0;
#else
#define ALARM_REINIT (void) alarm((uint) MY_HOW_OFTEN_TO_ALARM); \
my_have_got_alarm=0;
#endif /* SIGNAL_HANDLER_RESET_ON_DELIVERY */
#else
#define ALARM_VARIABLES long alarm_pos=0,alarm_end_pos=MY_HOW_OFTEN_TO_WRITE-1
#define ALARM_INIT
#define ALARM_END
#define ALARM_TEST (alarm_pos++ >= alarm_end_pos)
#define ALARM_REINIT (alarm_end_pos+=MY_HOW_OFTEN_TO_WRITE)
#endif /* HAVE_ALARM */
#ifdef __cplusplus
}
#endif
#endif

View file

@ -158,10 +158,6 @@ IF(UNIX)
SET (MYSYS_SOURCES ${MYSYS_SOURCES} my_addr_resolve.c my_setuser.c)
ENDIF()
IF(HAVE_ALARM)
SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_alarm.c)
ENDIF()
IF(HAVE_MLOCK)
SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_lockmem.c)
ENDIF()

View file

@ -1,33 +0,0 @@
/* Copyright (C) 2000 MySQL AB
Use is subject to license terms
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; version 2 of the License.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/* Function to set a varible when we got a alarm */
/* Used by my_lock samt functions in m_alarm.h */
#include "mysys_priv.h"
#include "my_alarm.h"
#ifdef HAVE_ALARM
/* ARGSUSED */
sig_handler my_set_alarm_variable(int signo __attribute__((unused)))
{
my_have_got_alarm=1; /* Tell program that time expired */
return;
}
#endif /* HAVE_ALARM */

View file

@ -16,12 +16,8 @@
#include "mysys_priv.h"
#include "mysys_err.h"
#include <errno.h>
#undef MY_HOW_OFTEN_TO_ALARM
#define MY_HOW_OFTEN_TO_ALARM ((int) my_time_to_wait_for_lock)
#ifdef NO_ALARM_LOOP
#undef NO_ALARM_LOOP
#endif
#include <my_alarm.h>
/* Wait timeout for short lock (2 seconds) */
#define NANOSECONDS_TO_WAIT_FOR_LOCK 2000000000ULL
#ifdef _WIN32
#define WIN_LOCK_INFINITE -1
@ -139,7 +135,6 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
{
#ifdef HAVE_FCNTL
int value;
ALARM_VARIABLES;
#endif
DBUG_ENTER("my_lock");
@ -171,6 +166,7 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
if (MyFlags & (MY_NO_WAIT | MY_SHORT_WAIT))
{
ulonglong end_time;
if (fcntl(fd,F_SETLK,&lock) != -1) /* Check if we can lock */
DBUG_RETURN(0); /* Ok, file locked */
if (MyFlags & MY_NO_WAIT)
@ -179,14 +175,16 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
DBUG_RETURN(-1);
}
DBUG_PRINT("info",("Was locked, trying with alarm"));
ALARM_INIT;
while ((value=fcntl(fd,F_SETLKW,&lock)) && ! ALARM_TEST &&
errno == EINTR)
{ /* Setup again so we don`t miss it */
ALARM_REINIT;
DBUG_PRINT("info",("Was locked, trying with timeout"));
end_time= my_interval_timer() + NANOSECONDS_TO_WAIT_FOR_LOCK;
while ((value= fcntl(fd, F_SETLKW, &lock)) == -1)
{
if (errno != EACCES && errno != EAGAIN && errno != EINTR)
break;
if (my_interval_timer() > end_time)
break;
my_sleep(1000);
}
ALARM_END;
if (value != -1)
DBUG_RETURN(0);
if (errno == EINTR)

View file

@ -21,8 +21,6 @@
#include "mysys_priv.h"
#include "my_static.h"
#include "my_alarm.h"
PSI_memory_key key_memory_DYNAMIC_STRING;
PSI_memory_key key_memory_IO_CACHE;
@ -95,9 +93,6 @@ const char *soundex_map= "01230120022455012623010202";
USED_MEM* my_once_root_block=0; /* pointer to first block */
uint my_once_extra=ONCE_ALLOC_INIT; /* Memory to alloc / block */
/* from my_alarm */
int volatile my_have_got_alarm=0; /* declare variable to reset */
ulong my_time_to_wait_for_lock=2; /* In seconds */
/* from errors.c */
#ifdef SHARED_LIBRARY