mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
f00257ddd0
- Removed not used variables and functions - Added #ifdef around code that is not used - Renamed variables and functions to avoid conflicts - Removed some not used arguments Fixed some class/struct warnings in ndb Added define IS_LONGDATA() to simplify code in libmysql.c I did run gcov on the changes and added 'purecov' comments on almost all lines that was not just variable name changes BUILD/SETUP.sh: Added printing of unused functions and variables. Made it easy to test compiling with -Wshadow BUILD/compile-pentium-gcov: Added warnings Mark binary with -gcov client/mysql.cc: Fixed warnings found with gcc -Wshadow client/mysql_upgrade.c: Fixed warnings found with gcc -Wshadow client/mysqlbinlog.cc: Fixed warnings found with gcc -Wshadow client/mysqldump.c: Fixed warnings found with gcc -Wshadow client/mysqltest.c: Fixed warnings found with gcc -Wshadow client/sql_string.cc: Fixed warnings found with gcc -Wshadow Merged with sql/sql_string.cc client/sql_string.h: Fixed warnings found with gcc -Wshadow Merged with sql/sql_string.h cmd-line-utils/readline/display.c: Fixed compiler warning cmd-line-utils/readline/histexpand.c: Fixed warnings found with gcc -Wshadow cmd-line-utils/readline/input.c: Fixed warnings found with gcc -Wshadow cmd-line-utils/readline/text.c: Fixed warnings found with gcc -Wshadow cmd-line-utils/readline/vi_mode.c: Fixed warnings found with gcc -Wshadow dbug/dbug_analyze.c: Fixed warnings found with gcc -Wshadow extra/my_print_defaults.c: Prefixed defaults_extra_file and defaults_group_suffix with 'my' to avoid conflicts with similar named local variables extra/yassl/include/buffer.hpp: Fixed compiler warnings extra/yassl/include/crypto_wrapper.hpp: Fixed compiler warnings extra/yassl/include/yassl_imp.hpp: Fixed compiler warnings extra/yassl/include/yassl_int.hpp: Fixed compiler warnings extra/yassl/src/crypto_wrapper.cpp: Fixed compiler warnings extra/yassl/taocrypt/benchmark/benchmark.cpp: Fixed warnings found with gcc -Wshadow extra/yassl/taocrypt/include/algebra.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/des.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/hash.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/hmac.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/modarith.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/modes.hpp: Fixed compiler warnings extra/yassl/taocrypt/include/rsa.hpp: Fixed compiler warnings extra/yassl/taocrypt/mySTL/list.hpp: Fixed compiler warnings extra/yassl/taocrypt/src/aes.cpp: Fixed compiler warnings extra/yassl/taocrypt/src/algebra.cpp: Fixed compiler warnings extra/yassl/taocrypt/src/asn.cpp: Fixed compiler warnings extra/yassl/taocrypt/test/test.cpp: Fixed compiler warnings extra/yassl/testsuite/testsuite.cpp: Fixed compiler warnings include/m_ctype.h: Fixed warnings found with gcc -Wshadow include/my_pthread.h: Fixed warnings found with gcc -Wshadow include/my_sys.h: Fixed warnings found with gcc -Wshadow include/my_time.h: Fixed warnings found with gcc -Wshadow include/mysql.h: Fixed warnings found with gcc -Wshadow Added define IS_LONGDATA() to simplify code in libmysql.c libmysql/libmysql.c: Fixed warnings found with gcc -Wshadow (Mostly replaced bind -> my_bind and time -> my_time) libmysqld/lib_sql.cc: Removed not used variables and labels myisam/ft_boolean_search.c: Fixed warnings found with gcc -Wshadow myisam/mi_open.c: Fixed warnings found with gcc -Wshadow myisam/mi_search.c: Fixed warnings found with gcc -Wshadow myisam/mi_unique.c: Fixed compiler warning myisam/myisampack.c: Fixed warnings found with gcc -Wshadow myisam/rt_index.c: Remove not used variables myisam/sort.c: Fixed warnings found with gcc -Wshadow mysql-test/r/mysqlcheck.result: Remove databases and tables possible left by previous test mysql-test/r/mysqltest.result: New test results mysql-test/t/mysql.test: Coverage tests mysql-test/t/mysqlbinlog.test: Coverage tests mysql-test/t/mysqlcheck.test: Remove databases and tables possible left by previous test mysql-test/t/mysqltest.test: Coverage tests mysys/default.c: Prefixed defaults_file, defaults_group_suffix and defaults_extra_file with 'my' to avoid conflicts with local variables in some functions mysys/mf_iocache2.c: Fixed warnings found with gcc -Wshadow mysys/mf_keycache.c: Fixed warnings found with gcc -Wshadow mysys/my_bitmap.c: Fixed warnings found with gcc -Wshadow mysys/sha1.c: Fixed warnings found with gcc -Wshadow ndb/include/kernel/signaldata/ArbitSignalData.hpp: Fixed compiler warning ndb/include/kernel/signaldata/DictTabInfo.hpp: Fixed compiler warnings ndb/include/ndbapi/NdbReceiver.hpp: Fixed warnings found with gcc -Wshadow ndb/include/transporter/TransporterDefinitions.hpp: Fixed compiler warning ndb/include/util/InputStream.hpp: Fixed compiler warning ndb/include/util/OutputStream.hpp: Fixed compiler warning ndb/include/util/SimpleProperties.hpp: Fixed compiler warning ndb/include/util/SocketAuthenticator.hpp: Fixed compiler warning ndb/include/util/SocketServer.hpp: Fixed compiler warning ndb/src/common/mgmcommon/ConfigRetriever.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/portlib/NdbTick.c: Fixed warnings found with gcc -Wshadow ndb/src/common/transporter/SHM_Transporter.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/transporter/TCP_Transporter.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/transporter/TCP_Transporter.hpp: Fixed compiler warning ndb/src/common/transporter/Transporter.cpp: Removed not used variable ndb/src/common/transporter/TransporterRegistry.cpp: Removed not used variable ndb/src/common/util/Bitmask.cpp: Moved function to avoid warnings of not used function ndb/src/common/util/ConfigValues.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/util/File.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/util/Properties.cpp: Fixed warnings found with gcc -Wshadow ndb/src/common/util/SocketClient.cpp: Fixed wrong return value ndb/src/common/util/random.c: Fixed warnings found with gcc -Wshadow ndb/src/common/util/socket_io.cpp: Fixed warnings found with gcc -Wshadow ndb/src/cw/cpcd/APIService.cpp: Removed not used variable ndb/src/cw/cpcd/main.cpp: Removed not used variables ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp: Fixed compiler warnings ndb/src/kernel/blocks/dbdict/Dbdict.cpp: Removed not used variables ndb/src/kernel/blocks/dbdict/Dbdict.hpp: Fixed compiler warnings ndb/src/kernel/blocks/dbdih/Dbdih.hpp: Fixed compiler warnings ndb/src/kernel/blocks/dblqh/Dblqh.hpp: Fixed compiler warnings ndb/src/kernel/blocks/dblqh/DblqhMain.cpp: Removed not used variables ndb/src/kernel/blocks/dbtc/Dbtc.hpp: Fixed compiler warnings ndb/src/kernel/blocks/dbtup/Dbtup.hpp: Fixed compiler warnings ndb/src/kernel/blocks/dbtup/DbtupScan.cpp: Removed not used variable ndb/src/kernel/blocks/dbtux/DbtuxNode.cpp: Removed not used variables ndb/src/kernel/blocks/dbtux/DbtuxScan.cpp: Removed not used variables ndb/src/kernel/blocks/dbtux/DbtuxTree.cpp: Removed not used variables ndb/src/kernel/blocks/ndbcntr/Ndbcntr.hpp: Fixed compiler warnings ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp: Removed not used variables ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp: Fixed compiler warnings ndb/src/kernel/blocks/qmgr/Qmgr.hpp: Fixed compiler warnings ndb/src/kernel/blocks/qmgr/QmgrMain.cpp: Removed not used variables ndb/src/kernel/blocks/suma/Suma.cpp: Removed not used variables ndb/src/kernel/blocks/suma/Suma.hpp: Fixed compiler warnings ndb/src/kernel/vm/MetaData.hpp: Fixed compiler warnings ndb/src/mgmapi/LocalConfig.cpp: Fixed warnings found with gcc -Wshadow ndb/src/mgmapi/mgmapi.cpp: Fixed warnings found with gcc -Wshadow ndb/src/mgmclient/CommandInterpreter.cpp: Removed not used variables ndb/src/mgmsrv/ConfigInfo.cpp: Fixed warnings found with gcc -Wshadow Removed not used variables ndb/src/mgmsrv/ConfigInfo.hpp: Fixed warnings found with gcc -Wshadow ndb/src/mgmsrv/InitConfigFileParser.cpp: Prefixed defaults_file, defaults_group_suffix and defaults_extra_file with 'my' to avoid conflicts with local variables in some functions ndb/src/mgmsrv/MgmtSrvr.cpp: Removed not used variables and functions ndb/src/mgmsrv/MgmtSrvr.hpp: Fixed compiler warnings ndb/src/mgmsrv/Services.cpp: Removed not used variables and functions ndb/src/mgmsrv/main.cpp: Removed not used variable ndb/src/ndbapi/ClusterMgr.hpp: Fixed compiler warnings ndb/src/ndbapi/Ndb.cpp: Removed not used variables ndb/src/ndbapi/NdbBlob.cpp: Removed not used variables ndb/src/ndbapi/NdbDictionaryImpl.cpp: Removed not used variables ndb/src/ndbapi/NdbIndexOperation.cpp: Removed not used variables ndb/src/ndbapi/NdbOperationDefine.cpp: Removed not used variables ndb/src/ndbapi/NdbOperationExec.cpp: Removed not used variables ndb/src/ndbapi/NdbOperationSearch.cpp: Removed not used variables ndb/src/ndbapi/NdbScanFilter.cpp: Fixed compiler warning ndb/src/ndbapi/NdbScanOperation.cpp: Removed not used variables ndb/src/ndbapi/SignalSender.cpp: Removed not used variables ndb/src/ndbapi/ndb_cluster_connection.cpp: Removed not used variable ndb/tools/delete_all.cpp: Removed not used variable ndb/tools/desc.cpp: Removed not used variable ndb/tools/drop_index.cpp: Removed not used variable ndb/tools/drop_tab.cpp: Removed not used variable ndb/tools/listTables.cpp: Removed not used variable ndb/tools/ndb_config.cpp: Fixed warnings found with gcc -Wshadow Added missing puts(desc) ndb/tools/restore/Restore.hpp: Changed delimiter to define instead of static variable, as the static variable caused a LOT of compiler warnings Fixed compiler warning ndb/tools/restore/consumer.hpp: Fixed compiler warning ndb/tools/restore/restore_main.cpp: Fixed compiler warnings ndb/tools/select_all.cpp: Removed not used variables ndb/tools/select_count.cpp: Removed not used variable server-tools/instance-manager/commands.h: Fixed compiler warnings server-tools/instance-manager/guardian.cc: Fixed compiler warnings server-tools/instance-manager/instance_options.cc: Removed not used variables server-tools/instance-manager/mysql_connection.cc: Fixed compiler warnings server-tools/instance-manager/options.cc: Fixed compiler warnings server-tools/instance-manager/options.h: Fixed compiler warnings server-tools/instance-manager/parse.cc: Removed not used variable server-tools/instance-manager/user_map.cc: Fixed compiler warnings server-tools/instance-manager/user_map.h: Fixed compiler warnings sql/field.cc: Fixed compiler warnings sql/field.h: Fixed compiler warnings sql/filesort.cc: Fixed compiler warnings sql/ha_archive.cc: Removed table and share arguments from get_share() / free_share() to get rid of compiler warnings sql/ha_archive.h: Removed table and share arguments from get_share() / free_share() to get rid of compiler warnings sql/ha_federated.cc: Fixed compiler warnings sql/ha_heap.cc: Fixed compiler warnings sql/ha_myisam.cc: Fixed compiler warnings sql/ha_myisammrg.cc: Fixed compiler warnings sql/ha_ndbcluster.cc: Fixed compiler warnings sql/handler.cc: Fixed compiler warnings sql/item.cc: Fixed compiler warnings sql/item.h: Fixed compiler warnings new_item() -> clone_item(), to avoid a lot of warnings with variable 'new_item' el() -> element_index() sql/item_cmpfunc.cc: Fixed compiler warnings sql/item_cmpfunc.h: Fixed compiler warnings sql/item_func.cc: Fixed compiler warnings sql/item_geofunc.cc: Fixed compiler warnings sql/item_row.h: Fixed compiler warnings sql/item_strfunc.cc: Fixed compiler warnings sql/item_subselect.cc: Fixed compiler warnings sql/item_subselect.h: Fixed compiler warnings sql/item_sum.cc: Fixed compiler warnings sql/item_timefunc.cc: Fixed compiler warnings sql/log.cc: Fixed compiler warnings More comments Added #ifdef HAVE_REPLICATION sql/log_event.cc: Fixed compiler warnings sql/log_event.h: Fixed compiler warnings sql/mysql_priv.h: query_id -> global_query_id, to avoid a lot of clashes with function and class variables start_time -> server_start_time sql/mysqld.cc: Fixed compiler warnings: - Removed not used variables - Added #ifndef EMBEDDED_LIBRARY - Fixed shadow warnings sql/net_serv.cc: Fixed compiler warnings sql/opt_range.cc: range -> last_range to avoid shadow warnings Removed not used function print_rowid() sql/opt_range.h: range -> last_range to avoid shadow warnings sql/password.c: Fixed compiler warnings sql/protocol.cc: Fixed compiler warnings sql/repl_failsafe.cc: Fixed compiler warnings sql/set_var.cc: Fixed compiler warnings sql/set_var.h: type() -> show_type() Fixed compiler warnings sql/slave.cc: Fixed compiler warnings sql/sp_head.cc: Fixed compiler warnings sql/sp_head.h: Fixed compiler warnings sql/spatial.cc: Fixed compiler warnings sql/spatial.h: length() -> geom_length() to avoid compiler warnings wkb_end -> wkb_last to avoid compiler warnings with local variables named 'wkb_end' sql/sql_cache.h: Fixed compiler warnings sql/sql_class.cc: Fixed compiler warnings sql/sql_class.h: log -> log_xid() to avoid compiler warnings Fixed shadow compiler warnings sql/sql_derived.cc: Removed not used variable sql/sql_insert.cc: Fixed compiler warnings sql/sql_lex.cc: Fixed compiler warnings sql/sql_lex.h: res -> saved_error to make the meaning of the variable clear and avoid shadow warnings sql/sql_load.cc: Fixed compiler warnings sql/sql_parse.cc: Fixed compiler warnings sql/sql_prepare.cc: Fixed compiler warnings sql/sql_select.cc: Fixed compiler warnings sql/sql_show.cc: Fixed compiler warnings sql/sql_string.cc: Fixed compiler warnings sql/sql_string.h: Fixed compiler warnings sql/sql_table.cc: Fixed compiler warnings sql/sql_trigger.cc: Fixed compiler warnings sql/sql_trigger.h: table -> trigger_table to avoid warnings from local variables sql/sql_union.cc: Fixed compiler warnings (mainly res -> saved_error) sql-common/client.c: Removed not used variable sql-common/my_time.c: Removed not used variable time -> my_time sql/sql_update.cc: Removed not used variable sql/sql_view.cc: Removed not used variable sql/sql_yacc.yy: Removed not used variable sql/table.cc: Removed not used variable sql/tztime.cc: Removed not used variable sql/unireg.cc: Removed not used variable strings/ctype-bin.c: mblen -> mb_len to avoid compiler warnings with local variable mblen strings/ctype-cp932.c: Fixed compiler warnings strings/ctype-eucjpms.c: Fixed compiler warnings strings/ctype-mb.c: mblen -> mb_len to avoid compiler warnings with local variable mblen strings/ctype-simple.c: mblen -> mb_len to avoid compiler warnings with local variable mblen exp -> exponent strings/ctype-sjis.c: Fixed compiler warnings strings/ctype-uca.c: mblen -> mb_len to avoid compiler warnings with local variable mblen strings/ctype-ujis.c: Fixed compiler warnings strings/ctype-utf8.c: Fixed compiler warnings strings/decimal.c: Fixed compiler warnings strings/my_vsnprintf.c: Added comment strings/strtod.c: Fixed compiler warnings tests/mysql_client_test.c: Fixed compiler warnings (Biggest part of patch is to not get a conflict with global function 'bind')
718 lines
25 KiB
C
718 lines
25 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 */
|
|
|
|
/* Defines to make different thread packages compatible */
|
|
|
|
#ifndef _my_pthread_h
|
|
#define _my_pthread_h
|
|
|
|
#include <errno.h>
|
|
#ifndef ETIME
|
|
#define ETIME ETIMEDOUT /* For FreeBSD */
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
#define EXTERNC extern "C"
|
|
extern "C" {
|
|
#else
|
|
#define EXTERNC
|
|
#endif /* __cplusplus */
|
|
|
|
#if defined(__WIN__) || defined(OS2)
|
|
|
|
#ifdef OS2
|
|
typedef ULONG HANDLE;
|
|
typedef ULONG DWORD;
|
|
typedef int sigset_t;
|
|
#endif
|
|
|
|
#ifdef OS2
|
|
typedef HMTX pthread_mutex_t;
|
|
#else
|
|
typedef CRITICAL_SECTION pthread_mutex_t;
|
|
#endif
|
|
typedef HANDLE pthread_t;
|
|
typedef struct thread_attr {
|
|
DWORD dwStackSize ;
|
|
DWORD dwCreatingFlag ;
|
|
int priority ;
|
|
} pthread_attr_t ;
|
|
|
|
typedef struct { int dummy; } pthread_condattr_t;
|
|
|
|
/* Implementation of posix conditions */
|
|
|
|
typedef struct st_pthread_link {
|
|
DWORD thread_id;
|
|
struct st_pthread_link *next;
|
|
} pthread_link;
|
|
|
|
typedef struct {
|
|
uint32 waiting;
|
|
#ifdef OS2
|
|
HEV semaphore;
|
|
#else
|
|
HANDLE semaphore;
|
|
#endif
|
|
} pthread_cond_t;
|
|
|
|
|
|
#ifndef OS2
|
|
struct timespec { /* For pthread_cond_timedwait() */
|
|
time_t tv_sec;
|
|
long tv_nsec;
|
|
};
|
|
#endif
|
|
|
|
typedef int pthread_mutexattr_t;
|
|
#define win_pthread_self my_thread_var->pthread_self
|
|
#ifdef OS2
|
|
#define pthread_handler_t EXTERNC void * _Optlink
|
|
typedef void * (_Optlink *pthread_handler)(void *);
|
|
#else
|
|
#define pthread_handler_t EXTERNC void * __cdecl
|
|
typedef void * (__cdecl *pthread_handler)(void *);
|
|
#endif
|
|
|
|
void win_pthread_init(void);
|
|
int win_pthread_setspecific(void *A,void *B,uint length);
|
|
int pthread_create(pthread_t *,pthread_attr_t *,pthread_handler,void *);
|
|
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
|
|
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
|
|
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
|
struct timespec *abstime);
|
|
int pthread_cond_signal(pthread_cond_t *cond);
|
|
int pthread_cond_broadcast(pthread_cond_t *cond);
|
|
int pthread_cond_destroy(pthread_cond_t *cond);
|
|
int pthread_attr_init(pthread_attr_t *connect_att);
|
|
int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack);
|
|
int pthread_attr_setprio(pthread_attr_t *connect_att,int priority);
|
|
int pthread_attr_destroy(pthread_attr_t *connect_att);
|
|
struct tm *localtime_r(const time_t *timep,struct tm *tmp);
|
|
struct tm *gmtime_r(const time_t *timep,struct tm *tmp);
|
|
|
|
|
|
void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/
|
|
|
|
#ifndef OS2
|
|
#define ETIMEDOUT 145 /* Win32 doesn't have this */
|
|
#define getpid() GetCurrentThreadId()
|
|
#endif
|
|
#define pthread_self() win_pthread_self
|
|
#define HAVE_LOCALTIME_R 1
|
|
#define _REENTRANT 1
|
|
#define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1
|
|
|
|
#ifdef USE_TLS /* For LIBMYSQL.DLL */
|
|
#undef SAFE_MUTEX /* This will cause conflicts */
|
|
#define pthread_key(T,V) DWORD V
|
|
#define pthread_key_create(A,B) ((*A=TlsAlloc())==0xFFFFFFFF)
|
|
#define pthread_key_delete(A) TlsFree(A)
|
|
#define pthread_getspecific(A) (TlsGetValue(A))
|
|
#define my_pthread_getspecific(T,A) ((T) TlsGetValue(A))
|
|
#define my_pthread_getspecific_ptr(T,V) ((T) TlsGetValue(V))
|
|
#define my_pthread_setspecific_ptr(T,V) (!TlsSetValue((T),(V)))
|
|
#define pthread_setspecific(A,B) (!TlsSetValue((A),(B)))
|
|
#else
|
|
#define pthread_key(T,V) __declspec(thread) T V
|
|
#define pthread_key_create(A,B) pthread_dummy(0)
|
|
#define pthread_key_delete(A) pthread_dummy(0)
|
|
#define pthread_getspecific(A) (&(A))
|
|
#define my_pthread_getspecific(T,A) (&(A))
|
|
#define my_pthread_getspecific_ptr(T,V) (V)
|
|
#define my_pthread_setspecific_ptr(T,V) ((T)=(V),0)
|
|
#define pthread_setspecific(A,B) win_pthread_setspecific(&(A),(B),sizeof(A))
|
|
#endif /* USE_TLS */
|
|
|
|
#define pthread_equal(A,B) ((A) == (B))
|
|
#ifdef OS2
|
|
extern int pthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *);
|
|
extern int pthread_mutex_lock (pthread_mutex_t *);
|
|
extern int pthread_mutex_unlock (pthread_mutex_t *);
|
|
extern int pthread_mutex_destroy (pthread_mutex_t *);
|
|
#define my_pthread_setprio(A,B) DosSetPriority(PRTYS_THREAD,PRTYC_NOCHANGE, B, A)
|
|
#define pthread_kill(A,B) raise(B)
|
|
#define pthread_exit(A) pthread_dummy()
|
|
#else
|
|
#define pthread_mutex_init(A,B) (InitializeCriticalSection(A),0)
|
|
#define pthread_mutex_lock(A) (EnterCriticalSection(A),0)
|
|
#define pthread_mutex_trylock(A) (WaitForSingleObject((A), 0) == WAIT_TIMEOUT)
|
|
#define pthread_mutex_unlock(A) LeaveCriticalSection(A)
|
|
#define pthread_mutex_destroy(A) DeleteCriticalSection(A)
|
|
#define my_pthread_setprio(A,B) SetThreadPriority(GetCurrentThread(), (B))
|
|
#define pthread_kill(A,B) pthread_dummy(0)
|
|
#endif /* OS2 */
|
|
|
|
/* Dummy defines for easier code */
|
|
#define pthread_attr_setdetachstate(A,B) pthread_dummy(0)
|
|
#define my_pthread_attr_setprio(A,B) pthread_attr_setprio(A,B)
|
|
#define pthread_attr_setscope(A,B)
|
|
#define pthread_detach_this_thread()
|
|
#define pthread_condattr_init(A)
|
|
#define pthread_condattr_destroy(A)
|
|
|
|
/*Irena: compiler does not like this: */
|
|
/*#define my_pthread_getprio(pthread_t thread_id) pthread_dummy(0) */
|
|
#define my_pthread_getprio(thread_id) pthread_dummy(0)
|
|
|
|
#elif defined(HAVE_UNIXWARE7_THREADS)
|
|
|
|
#include <thread.h>
|
|
#include <synch.h>
|
|
|
|
#ifndef _REENTRANT
|
|
#define _REENTRANT
|
|
#endif
|
|
|
|
#define HAVE_NONPOSIX_SIGWAIT
|
|
#define pthread_t thread_t
|
|
#define pthread_cond_t cond_t
|
|
#define pthread_mutex_t mutex_t
|
|
#define pthread_key_t thread_key_t
|
|
typedef int pthread_attr_t; /* Needed by Unixware 7.0.0 */
|
|
|
|
#define pthread_key_create(A,B) thr_keycreate((A),(B))
|
|
#define pthread_key_delete(A) thr_keydelete(A)
|
|
|
|
#define pthread_handler_t EXTERNC void *
|
|
#define pthread_key(T,V) pthread_key_t V
|
|
|
|
void * my_pthread_getspecific_imp(pthread_key_t key);
|
|
#define my_pthread_getspecific(A,B) ((A) my_pthread_getspecific_imp(B))
|
|
#define my_pthread_getspecific_ptr(T,V) my_pthread_getspecific(T,V)
|
|
|
|
#define pthread_setspecific(A,B) thr_setspecific(A,B)
|
|
#define my_pthread_setspecific_ptr(T,V) pthread_setspecific(T,V)
|
|
|
|
#define pthread_create(A,B,C,D) thr_create(NULL,65536L,(C),(D),THR_DETACHED,(A))
|
|
#define pthread_cond_init(a,b) cond_init((a),USYNC_THREAD,NULL)
|
|
#define pthread_cond_destroy(a) cond_destroy(a)
|
|
#define pthread_cond_signal(a) cond_signal(a)
|
|
#define pthread_cond_wait(a,b) cond_wait((a),(b))
|
|
#define pthread_cond_timedwait(a,b,c) cond_timedwait((a),(b),(c))
|
|
#define pthread_cond_broadcast(a) cond_broadcast(a)
|
|
|
|
#define pthread_mutex_init(a,b) mutex_init((a),USYNC_THREAD,NULL)
|
|
#define pthread_mutex_lock(a) mutex_lock(a)
|
|
#define pthread_mutex_unlock(a) mutex_unlock(a)
|
|
#define pthread_mutex_destroy(a) mutex_destroy(a)
|
|
|
|
#define pthread_self() thr_self()
|
|
#define pthread_exit(A) thr_exit(A)
|
|
#define pthread_equal(A,B) (((A) == (B)) ? 1 : 0)
|
|
#define pthread_kill(A,B) thr_kill((A),(B))
|
|
#define HAVE_PTHREAD_KILL
|
|
|
|
#define pthread_sigmask(A,B,C) thr_sigsetmask((A),(B),(C))
|
|
|
|
extern int my_sigwait(const sigset_t *set,int *sig);
|
|
|
|
#define pthread_detach_this_thread() pthread_dummy(0)
|
|
|
|
#define pthread_attr_init(A) pthread_dummy(0)
|
|
#define pthread_attr_destroy(A) pthread_dummy(0)
|
|
#define pthread_attr_setscope(A,B) pthread_dummy(0)
|
|
#define pthread_attr_setdetachstate(A,B) pthread_dummy(0)
|
|
#define my_pthread_setprio(A,B) pthread_dummy (0)
|
|
#define my_pthread_getprio(A) pthread_dummy (0)
|
|
#define my_pthread_attr_setprio(A,B) pthread_dummy(0)
|
|
|
|
#else /* Normal threads */
|
|
|
|
#ifdef HAVE_rts_threads
|
|
#define sigwait org_sigwait
|
|
#include <signal.h>
|
|
#undef sigwait
|
|
#endif
|
|
#include <pthread.h>
|
|
#ifndef _REENTRANT
|
|
#define _REENTRANT
|
|
#endif
|
|
#ifdef HAVE_THR_SETCONCURRENCY
|
|
#include <thread.h> /* Probably solaris */
|
|
#endif
|
|
#ifdef HAVE_SCHED_H
|
|
#include <sched.h>
|
|
#endif
|
|
#ifdef HAVE_SYNCH_H
|
|
#include <synch.h>
|
|
#endif
|
|
#if defined(__EMX__) && (!defined(EMX_PTHREAD_REV) || (EMX_PTHREAD_REV < 2))
|
|
#error Requires at least rev 2 of EMX pthreads library.
|
|
#endif
|
|
|
|
#ifdef __NETWARE__
|
|
void my_pthread_exit(void *status);
|
|
#define pthread_exit(A) my_pthread_exit(A)
|
|
#endif
|
|
|
|
extern int my_pthread_getprio(pthread_t thread_id);
|
|
|
|
#define pthread_key(T,V) pthread_key_t V
|
|
#define my_pthread_getspecific_ptr(T,V) my_pthread_getspecific(T,(V))
|
|
#define my_pthread_setspecific_ptr(T,V) pthread_setspecific(T,(void*) (V))
|
|
#define pthread_detach_this_thread()
|
|
#define pthread_handler_t EXTERNC void *
|
|
typedef void *(* pthread_handler)(void *);
|
|
|
|
/* Test first for RTS or FSU threads */
|
|
|
|
#if defined(PTHREAD_SCOPE_GLOBAL) && !defined(PTHREAD_SCOPE_SYSTEM)
|
|
#define HAVE_rts_threads
|
|
extern int my_pthread_create_detached;
|
|
#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C))
|
|
#define PTHREAD_CREATE_DETACHED &my_pthread_create_detached
|
|
#define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_GLOBAL
|
|
#define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_LOCAL
|
|
#define USE_ALARM_THREAD
|
|
#elif defined(HAVE_mit_thread)
|
|
#define USE_ALARM_THREAD
|
|
#undef HAVE_LOCALTIME_R
|
|
#define HAVE_LOCALTIME_R
|
|
#undef HAVE_GMTIME_R
|
|
#define HAVE_GMTIME_R
|
|
#undef HAVE_PTHREAD_ATTR_SETSCOPE
|
|
#define HAVE_PTHREAD_ATTR_SETSCOPE
|
|
#undef HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE /* If we are running linux */
|
|
#undef HAVE_RWLOCK_T
|
|
#undef HAVE_RWLOCK_INIT
|
|
#undef HAVE_PTHREAD_RWLOCK_RDLOCK
|
|
#undef HAVE_SNPRINTF
|
|
|
|
#define my_pthread_attr_setprio(A,B)
|
|
#endif /* defined(PTHREAD_SCOPE_GLOBAL) && !defined(PTHREAD_SCOPE_SYSTEM) */
|
|
|
|
#if defined(_BSDI_VERSION) && _BSDI_VERSION < 199910
|
|
int sigwait(sigset_t *set, int *sig);
|
|
#endif
|
|
|
|
#ifndef HAVE_NONPOSIX_SIGWAIT
|
|
#define my_sigwait(A,B) sigwait((A),(B))
|
|
#else
|
|
int my_sigwait(const sigset_t *set,int *sig);
|
|
#endif
|
|
|
|
#ifdef HAVE_NONPOSIX_PTHREAD_MUTEX_INIT
|
|
#ifndef SAFE_MUTEX
|
|
#define pthread_mutex_init(a,b) my_pthread_mutex_init((a),(b))
|
|
extern int my_pthread_mutex_init(pthread_mutex_t *mp,
|
|
const pthread_mutexattr_t *attr);
|
|
#endif /* SAFE_MUTEX */
|
|
#define pthread_cond_init(a,b) my_pthread_cond_init((a),(b))
|
|
extern int my_pthread_cond_init(pthread_cond_t *mp,
|
|
const pthread_condattr_t *attr);
|
|
#endif /* HAVE_NONPOSIX_PTHREAD_MUTEX_INIT */
|
|
|
|
#if defined(HAVE_SIGTHREADMASK) && !defined(HAVE_PTHREAD_SIGMASK)
|
|
#define pthread_sigmask(A,B,C) sigthreadmask((A),(B),(C))
|
|
#endif
|
|
|
|
#if !defined(HAVE_SIGWAIT) && !defined(HAVE_mit_thread) && !defined(HAVE_rts_threads) && !defined(sigwait) && !defined(alpha_linux_port) && !defined(HAVE_NONPOSIX_SIGWAIT) && !defined(HAVE_DEC_3_2_THREADS) && !defined(_AIX)
|
|
int sigwait(sigset_t *setp, int *sigp); /* Use our implemention */
|
|
#endif
|
|
|
|
|
|
/*
|
|
We define my_sigset() and use that instead of the system sigset() so that
|
|
we can favor an implementation based on sigaction(). On some systems, such
|
|
as Mac OS X, sigset() results in flags such as SA_RESTART being set, and
|
|
we want to make sure that no such flags are set.
|
|
*/
|
|
#if defined(HAVE_SIGACTION) && !defined(my_sigset)
|
|
#define my_sigset(A,B) do { struct sigaction l_s; sigset_t l_set; int l_rc; \
|
|
DBUG_ASSERT((A) != 0); \
|
|
sigemptyset(&l_set); \
|
|
l_s.sa_handler = (B); \
|
|
l_s.sa_mask = l_set; \
|
|
l_s.sa_flags = 0; \
|
|
l_rc= sigaction((A), &l_s, (struct sigaction *) NULL);\
|
|
DBUG_ASSERT(l_rc == 0); \
|
|
} while (0)
|
|
#elif defined(HAVE_SIGSET) && !defined(my_sigset)
|
|
#define my_sigset(A,B) sigset((A),(B))
|
|
#elif !defined(my_sigset)
|
|
#define my_sigset(A,B) signal((A),(B))
|
|
#endif
|
|
|
|
#ifndef my_pthread_setprio
|
|
#if defined(HAVE_PTHREAD_SETPRIO_NP) /* FSU threads */
|
|
#define my_pthread_setprio(A,B) pthread_setprio_np((A),(B))
|
|
#elif defined(HAVE_PTHREAD_SETPRIO)
|
|
#define my_pthread_setprio(A,B) pthread_setprio((A),(B))
|
|
#else
|
|
extern void my_pthread_setprio(pthread_t thread_id,int prior);
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef my_pthread_attr_setprio
|
|
#ifdef HAVE_PTHREAD_ATTR_SETPRIO
|
|
#define my_pthread_attr_setprio(A,B) pthread_attr_setprio((A),(B))
|
|
#else
|
|
extern void my_pthread_attr_setprio(pthread_attr_t *attr, int priority);
|
|
#endif
|
|
#endif
|
|
|
|
#if !defined(HAVE_PTHREAD_ATTR_SETSCOPE) || defined(HAVE_DEC_3_2_THREADS)
|
|
#define pthread_attr_setscope(A,B)
|
|
#undef HAVE_GETHOSTBYADDR_R /* No definition */
|
|
#endif
|
|
|
|
#if defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT) && !defined(SAFE_MUTEX)
|
|
extern int my_pthread_cond_timedwait(pthread_cond_t *cond,
|
|
pthread_mutex_t *mutex,
|
|
struct timespec *abstime);
|
|
#define pthread_cond_timedwait(A,B,C) my_pthread_cond_timedwait((A),(B),(C))
|
|
#endif
|
|
|
|
#if defined(OS2)
|
|
#define my_pthread_getspecific(T,A) ((T) &(A))
|
|
#define pthread_setspecific(A,B) win_pthread_setspecific(&(A),(B),sizeof(A))
|
|
#elif !defined( HAVE_NONPOSIX_PTHREAD_GETSPECIFIC)
|
|
#define my_pthread_getspecific(A,B) ((A) pthread_getspecific(B))
|
|
#else
|
|
#define my_pthread_getspecific(A,B) ((A) my_pthread_getspecific_imp(B))
|
|
void *my_pthread_getspecific_imp(pthread_key_t key);
|
|
#endif /* OS2 */
|
|
|
|
#ifndef HAVE_LOCALTIME_R
|
|
struct tm *localtime_r(const time_t *clock, struct tm *res);
|
|
#endif
|
|
|
|
#ifndef HAVE_GMTIME_R
|
|
struct tm *gmtime_r(const time_t *clock, struct tm *res);
|
|
#endif
|
|
|
|
#ifdef HAVE_PTHREAD_CONDATTR_CREATE
|
|
/* DCE threads on HPUX 10.20 */
|
|
#define pthread_condattr_init pthread_condattr_create
|
|
#define pthread_condattr_destroy pthread_condattr_delete
|
|
#endif
|
|
|
|
/* FSU THREADS */
|
|
#if !defined(HAVE_PTHREAD_KEY_DELETE) && !defined(pthread_key_delete)
|
|
#define pthread_key_delete(A) pthread_dummy(0)
|
|
#endif
|
|
|
|
#ifdef HAVE_CTHREADS_WRAPPER /* For MacOSX */
|
|
#define pthread_cond_destroy(A) pthread_dummy(0)
|
|
#define pthread_mutex_destroy(A) pthread_dummy(0)
|
|
#define pthread_attr_delete(A) pthread_dummy(0)
|
|
#define pthread_condattr_delete(A) pthread_dummy(0)
|
|
#define pthread_attr_setstacksize(A,B) pthread_dummy(0)
|
|
#define pthread_equal(A,B) ((A) == (B))
|
|
#define pthread_cond_timedwait(a,b,c) pthread_cond_wait((a),(b))
|
|
#define pthread_attr_init(A) pthread_attr_create(A)
|
|
#define pthread_attr_destroy(A) pthread_attr_delete(A)
|
|
#define pthread_attr_setdetachstate(A,B) pthread_dummy(0)
|
|
#define pthread_create(A,B,C,D) pthread_create((A),*(B),(C),(D))
|
|
#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C))
|
|
#define pthread_kill(A,B) pthread_dummy(0)
|
|
#undef pthread_detach_this_thread
|
|
#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); }
|
|
#endif
|
|
|
|
#ifdef HAVE_DARWIN5_THREADS
|
|
#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C))
|
|
#define pthread_kill(A,B) pthread_dummy(0)
|
|
#define pthread_condattr_init(A) pthread_dummy(0)
|
|
#define pthread_condattr_destroy(A) pthread_dummy(0)
|
|
#undef pthread_detach_this_thread
|
|
#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(tmp); }
|
|
#endif
|
|
|
|
#if ((defined(HAVE_PTHREAD_ATTR_CREATE) && !defined(HAVE_SIGWAIT)) || defined(HAVE_DEC_3_2_THREADS)) && !defined(HAVE_CTHREADS_WRAPPER)
|
|
/* This is set on AIX_3_2 and Siemens unix (and DEC OSF/1 3.2 too) */
|
|
#define pthread_key_create(A,B) \
|
|
pthread_keycreate(A,(B) ?\
|
|
(pthread_destructor_t) (B) :\
|
|
(pthread_destructor_t) pthread_dummy)
|
|
#define pthread_attr_init(A) pthread_attr_create(A)
|
|
#define pthread_attr_destroy(A) pthread_attr_delete(A)
|
|
#define pthread_attr_setdetachstate(A,B) pthread_dummy(0)
|
|
#define pthread_create(A,B,C,D) pthread_create((A),*(B),(C),(D))
|
|
#ifndef pthread_sigmask
|
|
#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C))
|
|
#endif
|
|
#define pthread_kill(A,B) pthread_dummy(0)
|
|
#undef pthread_detach_this_thread
|
|
#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); }
|
|
#elif !defined(__NETWARE__) /* HAVE_PTHREAD_ATTR_CREATE && !HAVE_SIGWAIT */
|
|
#define HAVE_PTHREAD_KILL
|
|
#endif
|
|
|
|
#endif /* defined(__WIN__) */
|
|
|
|
#if defined(HPUX10) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS)
|
|
#undef pthread_cond_timedwait
|
|
#define pthread_cond_timedwait(a,b,c) my_pthread_cond_timedwait((a),(b),(c))
|
|
int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
|
struct timespec *abstime);
|
|
#endif
|
|
|
|
#if defined(HPUX10)
|
|
#define pthread_attr_getstacksize(A,B) my_pthread_attr_getstacksize(A,B)
|
|
void my_pthread_attr_getstacksize(pthread_attr_t *attrib, size_t *size);
|
|
#endif
|
|
|
|
#if defined(HAVE_POSIX1003_4a_MUTEX) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS)
|
|
#undef pthread_mutex_trylock
|
|
#define pthread_mutex_trylock(a) my_pthread_mutex_trylock((a))
|
|
int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
|
|
#endif
|
|
|
|
/* safe_mutex adds checking to mutex for easier debugging */
|
|
|
|
#if defined(__NETWARE__) && !defined(SAFE_MUTEX_DETECT_DESTROY)
|
|
#define SAFE_MUTEX_DETECT_DESTROY
|
|
#endif
|
|
|
|
typedef struct st_safe_mutex_t
|
|
{
|
|
pthread_mutex_t global,mutex;
|
|
const char *file;
|
|
uint line,count;
|
|
pthread_t thread;
|
|
#ifdef SAFE_MUTEX_DETECT_DESTROY
|
|
struct st_safe_mutex_info_t *info; /* to track destroying of mutexes */
|
|
#endif
|
|
} safe_mutex_t;
|
|
|
|
#ifdef SAFE_MUTEX_DETECT_DESTROY
|
|
/*
|
|
Used to track the destroying of mutexes. This needs to be a seperate
|
|
structure because the safe_mutex_t structure could be freed before
|
|
the mutexes are destroyed.
|
|
*/
|
|
|
|
typedef struct st_safe_mutex_info_t
|
|
{
|
|
struct st_safe_mutex_info_t *next;
|
|
struct st_safe_mutex_info_t *prev;
|
|
const char *init_file;
|
|
uint32 init_line;
|
|
} safe_mutex_info_t;
|
|
#endif /* SAFE_MUTEX_DETECT_DESTROY */
|
|
|
|
int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr,
|
|
const char *file, uint line);
|
|
int safe_mutex_lock(safe_mutex_t *mp,const char *file, uint line);
|
|
int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line);
|
|
int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line);
|
|
int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file,
|
|
uint line);
|
|
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
|
|
struct timespec *abstime, const char *file, uint line);
|
|
void safe_mutex_global_init(void);
|
|
void safe_mutex_end(FILE *file);
|
|
|
|
/* Wrappers if safe mutex is actually used */
|
|
#ifdef SAFE_MUTEX
|
|
#undef pthread_mutex_init
|
|
#undef pthread_mutex_lock
|
|
#undef pthread_mutex_unlock
|
|
#undef pthread_mutex_destroy
|
|
#undef pthread_mutex_wait
|
|
#undef pthread_mutex_timedwait
|
|
#undef pthread_mutex_t
|
|
#undef pthread_cond_wait
|
|
#undef pthread_cond_timedwait
|
|
#undef pthread_mutex_trylock
|
|
#define pthread_mutex_init(A,B) safe_mutex_init((A),(B),__FILE__,__LINE__)
|
|
#define pthread_mutex_lock(A) safe_mutex_lock((A),__FILE__,__LINE__)
|
|
#define pthread_mutex_unlock(A) safe_mutex_unlock((A),__FILE__,__LINE__)
|
|
#define pthread_mutex_destroy(A) safe_mutex_destroy((A),__FILE__,__LINE__)
|
|
#define pthread_cond_wait(A,B) safe_cond_wait((A),(B),__FILE__,__LINE__)
|
|
#define pthread_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__)
|
|
#define pthread_mutex_trylock(A) pthread_mutex_lock(A)
|
|
#define pthread_mutex_t safe_mutex_t
|
|
#define safe_mutex_assert_owner(mp) \
|
|
DBUG_ASSERT((mp)->count > 0 && \
|
|
pthread_equal(pthread_self(), (mp)->thread))
|
|
#define safe_mutex_assert_not_owner(mp) \
|
|
DBUG_ASSERT(! (mp)->count || \
|
|
! pthread_equal(pthread_self(), (mp)->thread))
|
|
#else
|
|
#define safe_mutex_assert_owner(mp)
|
|
#define safe_mutex_assert_not_owner(mp)
|
|
#endif /* SAFE_MUTEX */
|
|
|
|
/* READ-WRITE thread locking */
|
|
|
|
#ifdef HAVE_BROKEN_RWLOCK /* For OpenUnix */
|
|
#undef HAVE_PTHREAD_RWLOCK_RDLOCK
|
|
#undef HAVE_RWLOCK_INIT
|
|
#undef HAVE_RWLOCK_T
|
|
#endif
|
|
|
|
#if defined(USE_MUTEX_INSTEAD_OF_RW_LOCKS)
|
|
/* use these defs for simple mutex locking */
|
|
#define rw_lock_t pthread_mutex_t
|
|
#define my_rwlock_init(A,B) pthread_mutex_init((A),(B))
|
|
#define rw_rdlock(A) pthread_mutex_lock((A))
|
|
#define rw_wrlock(A) pthread_mutex_lock((A))
|
|
#define rw_tryrdlock(A) pthread_mutex_trylock((A))
|
|
#define rw_trywrlock(A) pthread_mutex_trylock((A))
|
|
#define rw_unlock(A) pthread_mutex_unlock((A))
|
|
#define rwlock_destroy(A) pthread_mutex_destroy((A))
|
|
#elif defined(HAVE_PTHREAD_RWLOCK_RDLOCK)
|
|
#define rw_lock_t pthread_rwlock_t
|
|
#define my_rwlock_init(A,B) pthread_rwlock_init((A),(B))
|
|
#define rw_rdlock(A) pthread_rwlock_rdlock(A)
|
|
#define rw_wrlock(A) pthread_rwlock_wrlock(A)
|
|
#define rw_tryrdlock(A) pthread_rwlock_tryrdlock((A))
|
|
#define rw_trywrlock(A) pthread_rwlock_trywrlock((A))
|
|
#define rw_unlock(A) pthread_rwlock_unlock(A)
|
|
#define rwlock_destroy(A) pthread_rwlock_destroy(A)
|
|
#elif defined(HAVE_RWLOCK_INIT)
|
|
#ifdef HAVE_RWLOCK_T /* For example Solaris 2.6-> */
|
|
#define rw_lock_t rwlock_t
|
|
#endif
|
|
#define my_rwlock_init(A,B) rwlock_init((A),USYNC_THREAD,0)
|
|
#else
|
|
/* Use our own version of read/write locks */
|
|
typedef struct _my_rw_lock_t {
|
|
pthread_mutex_t lock; /* lock for structure */
|
|
pthread_cond_t readers; /* waiting readers */
|
|
pthread_cond_t writers; /* waiting writers */
|
|
int state; /* -1:writer,0:free,>0:readers */
|
|
int waiters; /* number of waiting writers */
|
|
} my_rw_lock_t;
|
|
|
|
#define rw_lock_t my_rw_lock_t
|
|
#define rw_rdlock(A) my_rw_rdlock((A))
|
|
#define rw_wrlock(A) my_rw_wrlock((A))
|
|
#define rw_tryrdlock(A) my_rw_tryrdlock((A))
|
|
#define rw_trywrlock(A) my_rw_trywrlock((A))
|
|
#define rw_unlock(A) my_rw_unlock((A))
|
|
#define rwlock_destroy(A) my_rwlock_destroy((A))
|
|
|
|
extern int my_rwlock_init(my_rw_lock_t *, void *);
|
|
extern int my_rwlock_destroy(my_rw_lock_t *);
|
|
extern int my_rw_rdlock(my_rw_lock_t *);
|
|
extern int my_rw_wrlock(my_rw_lock_t *);
|
|
extern int my_rw_unlock(my_rw_lock_t *);
|
|
extern int my_rw_tryrdlock(my_rw_lock_t *);
|
|
extern int my_rw_trywrlock(my_rw_lock_t *);
|
|
#endif /* USE_MUTEX_INSTEAD_OF_RW_LOCKS */
|
|
|
|
#define GETHOSTBYADDR_BUFF_SIZE 2048
|
|
|
|
#ifndef HAVE_THR_SETCONCURRENCY
|
|
#define thr_setconcurrency(A) pthread_dummy(0)
|
|
#endif
|
|
#if !defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) && ! defined(pthread_attr_setstacksize)
|
|
#define pthread_attr_setstacksize(A,B) pthread_dummy(0)
|
|
#endif
|
|
|
|
/* Define mutex types, see my_thr_init.c */
|
|
#define MY_MUTEX_INIT_SLOW NULL
|
|
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
|
|
extern pthread_mutexattr_t my_fast_mutexattr;
|
|
#define MY_MUTEX_INIT_FAST &my_fast_mutexattr
|
|
#else
|
|
#define MY_MUTEX_INIT_FAST NULL
|
|
#endif
|
|
#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
|
|
extern pthread_mutexattr_t my_errorcheck_mutexattr;
|
|
#define MY_MUTEX_INIT_ERRCHK &my_errorcheck_mutexattr
|
|
#else
|
|
#define MY_MUTEX_INIT_ERRCHK NULL
|
|
#endif
|
|
|
|
extern my_bool my_thread_global_init(void);
|
|
extern void my_thread_global_end(void);
|
|
extern my_bool my_thread_init(void);
|
|
extern void my_thread_end(void);
|
|
extern const char *my_thread_name(void);
|
|
extern long my_thread_id(void);
|
|
extern int pthread_no_free(void *);
|
|
extern int pthread_dummy(int);
|
|
|
|
/* All thread specific variables are in the following struct */
|
|
|
|
#define THREAD_NAME_SIZE 10
|
|
#ifndef DEFAULT_THREAD_STACK
|
|
#if SIZEOF_CHARP > 4
|
|
/*
|
|
MySQL can survive with 32K, but some glibc libraries require > 128K stack
|
|
To resolve hostnames. Also recursive stored procedures needs stack.
|
|
*/
|
|
#define DEFAULT_THREAD_STACK (256*1024L)
|
|
#else
|
|
#define DEFAULT_THREAD_STACK (192*1024)
|
|
#endif
|
|
#endif
|
|
|
|
struct st_my_thread_var
|
|
{
|
|
int thr_errno;
|
|
pthread_cond_t suspend;
|
|
pthread_mutex_t mutex;
|
|
pthread_mutex_t * volatile current_mutex;
|
|
pthread_cond_t * volatile current_cond;
|
|
pthread_t pthread_self;
|
|
long id;
|
|
int cmp_length;
|
|
int volatile abort;
|
|
my_bool init;
|
|
struct st_my_thread_var *next,**prev;
|
|
void *opt_info;
|
|
#ifndef DBUG_OFF
|
|
gptr dbug;
|
|
char name[THREAD_NAME_SIZE+1];
|
|
#endif
|
|
};
|
|
|
|
extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const));
|
|
extern uint my_thread_end_wait_time;
|
|
#define my_thread_var (_my_thread_var())
|
|
#define my_errno my_thread_var->thr_errno
|
|
/*
|
|
Keep track of shutdown,signal, and main threads so that my_end() will not
|
|
report errors with them
|
|
*/
|
|
/* statistics_xxx functions are for not essential statistic */
|
|
|
|
#ifndef thread_safe_increment
|
|
#ifdef HAVE_ATOMIC_ADD
|
|
#define thread_safe_increment(V,L) atomic_inc((atomic_t*) &V)
|
|
#define thread_safe_decrement(V,L) atomic_dec((atomic_t*) &V)
|
|
#define thread_safe_add(V,C,L) atomic_add((C),(atomic_t*) &V)
|
|
#define thread_safe_sub(V,C,L) atomic_sub((C),(atomic_t*) &V)
|
|
#else
|
|
#define thread_safe_increment(V,L) \
|
|
(pthread_mutex_lock((L)), (V)++, pthread_mutex_unlock((L)))
|
|
#define thread_safe_decrement(V,L) \
|
|
(pthread_mutex_lock((L)), (V)--, pthread_mutex_unlock((L)))
|
|
#define thread_safe_add(V,C,L) (pthread_mutex_lock((L)), (V)+=(C), pthread_mutex_unlock((L)))
|
|
#define thread_safe_sub(V,C,L) \
|
|
(pthread_mutex_lock((L)), (V)-=(C), pthread_mutex_unlock((L)))
|
|
#endif /* HAVE_ATOMIC_ADD */
|
|
#ifdef SAFE_STATISTICS
|
|
#define statistic_increment(V,L) thread_safe_increment((V),(L))
|
|
#define statistic_decrement(V,L) thread_safe_decrement((V),(L))
|
|
#define statistic_add(V,C,L) thread_safe_add((V),(C),(L))
|
|
#else
|
|
#define statistic_decrement(V,L) (V)--
|
|
#define statistic_increment(V,L) (V)++
|
|
#define statistic_add(V,C,L) (V)+=(C)
|
|
#endif /* SAFE_STATISTICS */
|
|
#endif /* thread_safe_increment */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif /* _my_ptread_h */
|