diff options
author | unknown <tomas@poseidon.ndb.mysql.com> | 2005-10-06 10:54:07 +0200 |
---|---|---|
committer | unknown <tomas@poseidon.ndb.mysql.com> | 2005-10-06 10:54:07 +0200 |
commit | d04832d195aba5badc42310eaa69c628a4a183bd (patch) | |
tree | cbe58ba165511396b212afaa1654a226d8ae88a4 /mysys | |
parent | 282855e90bf052e2cf126adfaada61924cd8dd41 (diff) | |
parent | 3c2dca475dfa91c95f2488831fafacacaf852347 (diff) | |
download | mariadb-git-d04832d195aba5badc42310eaa69c628a4a183bd.tar.gz |
Merge
BitKeeper/etc/ignore:
auto-union
BUILD/autorun.sh:
Auto merged
BitKeeper/deleted/.del-bdb.vcproj~ed8534936e40cefb:
Auto merged
BitKeeper/deleted/.del-heap.vcproj~70c0cc1d680a51c1:
Auto merged
BitKeeper/deleted/.del-innobase.vcproj~71e1de81f11138bf:
Auto merged
BitKeeper/deleted/.del-myisam.vcproj~32bb9e4a163fcb5a:
Auto merged
BitKeeper/deleted/.del-myisammrg.vcproj~6534e59acbfbb63:
Auto merged
BitKeeper/deleted/.del-mysqld.vcproj~703886a28862bb2:
Auto merged
Makefile.am:
Auto merged
client/mysqltest.c:
Auto merged
include/my_global.h:
Auto merged
include/mysql_com.h:
Auto merged
mysql-test/mysql-test-run.pl:
Auto merged
mysql-test/r/ndb_alter_table.result:
Auto merged
mysql-test/r/ps_6bdb.result:
Auto merged
mysql-test/r/ps_7ndb.result:
Auto merged
mysql-test/t/query_cache.test:
Auto merged
mysys/default.c:
Auto merged
scripts/make_win_src_distribution.sh:
Auto merged
scripts/mysql_create_system_tables.sh:
Auto merged
scripts/mysql_fix_privilege_tables.sql:
Auto merged
sql/Makefile.am:
Auto merged
sql/field.cc:
Auto merged
sql/ha_berkeley.cc:
Auto merged
sql/ha_berkeley.h:
Auto merged
sql/ha_federated.cc:
Auto merged
sql/ha_heap.cc:
Auto merged
sql/ha_innodb.cc:
Auto merged
sql/ha_innodb.h:
Auto merged
sql/ha_myisam.cc:
Auto merged
sql/ha_myisammrg.cc:
Auto merged
sql/ha_ndbcluster.h:
Auto merged
sql/handler.cc:
Auto merged
sql/item.cc:
Auto merged
sql/item_subselect.cc:
Auto merged
sql/log.cc:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/opt_sum.cc:
Auto merged
sql/repl_failsafe.cc:
Auto merged
sql/set_var.cc:
Auto merged
sql/sp.cc:
Auto merged
sql/sql_acl.cc:
Auto merged
sql/sql_acl.h:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_cache.cc:
Auto merged
sql/sql_class.h:
Auto merged
sql/sql_delete.cc:
Auto merged
sql/sql_insert.cc:
Auto merged
sql/sql_lex.cc:
Auto merged
sql/sql_lex.h:
Auto merged
sql/sql_load.cc:
Auto merged
sql/sql_prepare.cc:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_select.h:
Auto merged
sql/sql_show.cc:
Auto merged
sql/sql_table.cc:
Auto merged
sql/sql_update.cc:
Auto merged
sql/sql_yacc.yy:
Auto merged
sql/table.h:
Auto merged
sql/unireg.cc:
Auto merged
storage/innobase/buf/buf0buf.c:
Auto merged
storage/innobase/buf/buf0flu.c:
Auto merged
storage/innobase/data/data0data.c:
Auto merged
storage/innobase/dict/dict0dict.c:
Auto merged
storage/innobase/include/btr0btr.h:
Auto merged
storage/innobase/include/data0type.ic:
Auto merged
storage/innobase/include/dict0dict.h:
Auto merged
storage/innobase/include/dict0mem.h:
Auto merged
storage/innobase/include/mem0mem.h:
Auto merged
storage/innobase/include/mem0mem.ic:
Auto merged
storage/innobase/include/os0file.h:
Auto merged
storage/innobase/include/row0mysql.h:
Auto merged
storage/innobase/include/trx0trx.h:
Auto merged
storage/innobase/include/ut0mem.h:
Auto merged
storage/innobase/mem/mem0mem.c:
Auto merged
storage/innobase/os/os0file.c:
Auto merged
storage/innobase/os/os0proc.c:
Auto merged
storage/innobase/rem/rem0rec.c:
Auto merged
storage/innobase/row/row0ins.c:
Auto merged
storage/innobase/row/row0mysql.c:
Auto merged
storage/innobase/srv/srv0start.c:
Auto merged
storage/innobase/trx/trx0sys.c:
Auto merged
storage/innobase/trx/trx0trx.c:
Auto merged
storage/innobase/ut/ut0mem.c:
Auto merged
storage/myisam/ft_boolean_search.c:
Auto merged
storage/myisam/mi_check.c:
Auto merged
storage/myisam/mi_dbug.c:
Auto merged
storage/myisam/mi_delete.c:
Auto merged
storage/myisam/mi_delete_all.c:
Auto merged
storage/myisam/mi_key.c:
Auto merged
storage/myisam/mi_open.c:
Auto merged
storage/myisam/mi_rkey.c:
Auto merged
storage/myisam/mi_search.c:
Auto merged
storage/myisam/mi_test1.c:
Auto merged
storage/myisam/mi_update.c:
Auto merged
storage/myisam/mi_write.c:
Auto merged
storage/myisam/myisamchk.c:
Auto merged
storage/myisam/myisamdef.h:
Auto merged
storage/myisam/myisampack.c:
Auto merged
storage/myisam/sp_key.c:
Auto merged
storage/myisammrg/myrg_rkey.c:
Auto merged
storage/ndb/include/kernel/GlobalSignalNumbers.h:
Auto merged
storage/ndb/include/kernel/signaldata/ApiVersion.hpp:
Auto merged
storage/ndb/include/kernel/signaldata/EventReport.hpp:
Auto merged
storage/ndb/include/kernel/signaldata/StopReq.hpp:
Auto merged
storage/ndb/include/mgmapi/ndb_logevent.h:
Auto merged
storage/ndb/include/ndbapi/NdbBlob.hpp:
Auto merged
storage/ndb/include/ndbapi/NdbIndexOperation.hpp:
Auto merged
storage/ndb/include/ndbapi/NdbIndexScanOperation.hpp:
Auto merged
storage/ndb/include/ndbapi/NdbOperation.hpp:
Auto merged
storage/ndb/include/ndbapi/NdbRecAttr.hpp:
Auto merged
storage/ndb/include/ndbapi/NdbTransaction.hpp:
Auto merged
storage/ndb/src/common/util/SimpleProperties.cpp:
Auto merged
storage/ndb/src/kernel/blocks/backup/Backup.cpp:
Auto merged
storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp:
Auto merged
storage/ndb/src/kernel/blocks/dbdict/printSchemaFile.cpp:
Auto merged
storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp:
Auto merged
storage/ndb/src/kernel/blocks/dbtup/DbtupRoutines.cpp:
Auto merged
storage/ndb/src/kernel/blocks/dbtup/DbtupTrigger.cpp:
Auto merged
storage/ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp:
Auto merged
storage/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp:
Auto merged
storage/ndb/src/mgmapi/ndb_logevent.cpp:
Auto merged
storage/ndb/src/mgmclient/CommandInterpreter.cpp:
Auto merged
storage/ndb/src/mgmsrv/Config.cpp:
Auto merged
storage/ndb/src/mgmsrv/Config.hpp:
Auto merged
storage/ndb/src/mgmsrv/ConfigInfo.cpp:
Auto merged
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Auto merged
storage/ndb/src/mgmsrv/InitConfigFileParser.hpp:
Auto merged
storage/ndb/src/mgmsrv/MgmtSrvr.hpp:
Auto merged
storage/ndb/src/mgmsrv/MgmtSrvrConfig.cpp:
Auto merged
storage/ndb/src/mgmsrv/MgmtSrvrGeneralSignalHandling.cpp:
Auto merged
storage/ndb/src/mgmsrv/Services.cpp:
Auto merged
storage/ndb/src/mgmsrv/Services.hpp:
Auto merged
storage/ndb/src/mgmsrv/main.cpp:
Auto merged
storage/ndb/src/ndbapi/NdbApiSignal.cpp:
Auto merged
storage/ndb/src/ndbapi/NdbApiSignal.hpp:
Auto merged
storage/ndb/src/ndbapi/NdbBlob.cpp:
Auto merged
storage/ndb/src/ndbapi/NdbImpl.hpp:
Auto merged
storage/ndb/src/ndbapi/NdbRecAttr.cpp:
Auto merged
storage/ndb/src/ndbapi/NdbUtil.cpp:
Auto merged
storage/ndb/src/ndbapi/NdbUtil.hpp:
Auto merged
storage/ndb/src/ndbapi/Ndbif.cpp:
Auto merged
storage/ndb/src/ndbapi/Ndblist.cpp:
Auto merged
storage/ndb/src/ndbapi/ObjectMap.hpp:
Auto merged
storage/ndb/test/include/NDBT_Test.hpp:
Auto merged
storage/ndb/test/ndbapi/bank/BankLoad.cpp:
Auto merged
storage/ndb/test/ndbapi/testOIBasic.cpp:
Auto merged
storage/ndb/test/src/HugoCalculator.cpp:
Auto merged
storage/ndb/test/src/NDBT_Test.cpp:
Auto merged
storage/ndb/test/src/NdbBackup.cpp:
Auto merged
storage/ndb/test/src/NdbRestarts.cpp:
Auto merged
storage/ndb/tools/ndb_condig.cpp:
Auto merged
storage/ndb/tools/restore/Restore.cpp:
Auto merged
storage/ndb/tools/restore/consumer_restore.cpp:
Auto merged
support-files/mysql.spec.sh:
Auto merged
configure.in:
merge
BUILD/SETUP.sh:
merge
BitKeeper/deleted/.del-mysql.sln~f2120278f8a437be:
SCCS merged
libmysqld/Makefile.am:
merge
sql/ha_ndbcluster.cc:
merge
sql/handler.h:
merge
sql/mysqld.cc:
merge
sql/opt_range.cc:
merge
sql/slave.cc:
merge
sql/slave.h:
e
merge
sql/sql_parse.cc:
merge
sql/table.cc:
merge
sql/examples/ha_tina.cc:
merge
sql/examples/ha_tina.h:
merge
sql/share/errmsg.txt:
merge
storage/ndb/include/ndbapi/Ndb.hpp:
merge
storage/ndb/src/common/debugger/EventLogger.cpp:
merge
storage/ndb/src/kernel/blocks/dbdict/Makefile.am:
merge
storage/ndb/src/mgmsrv/MgmtSrvr.cpp:
merge
storage/ndb/src/ndbapi/Ndbinit.cpp:
SCCS merged
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/default.c | 6 | ||||
-rw-r--r-- | mysys/mf_iocache.c | 4 | ||||
-rw-r--r-- | mysys/mf_keycache.c | 72 | ||||
-rw-r--r-- | mysys/my_alloc.c | 51 | ||||
-rw-r--r-- | mysys/my_conio.c | 217 | ||||
-rw-r--r-- | mysys/my_init.c | 25 |
6 files changed, 364 insertions, 11 deletions
diff --git a/mysys/default.c b/mysys/default.c index bca3ec0fed3..edd02402a2a 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -42,6 +42,7 @@ #include <winbase.h> #endif +const char *defaults_file=0; const char *defaults_group_suffix=0; char *defaults_extra_file=0; @@ -138,8 +139,11 @@ int my_search_option_files(const char *conf_file, int *argc, char ***argv, defaults_group_suffix= getenv(STRINGIFY_ARG(DEFAULT_GROUP_SUFFIX_ENV)); if (forced_extra_defaults) - defaults_extra_file= forced_extra_defaults; + defaults_extra_file= (char *) forced_extra_defaults; + if (forced_default_file) + defaults_file= forced_default_file; + /* We can only handle 'defaults-group-suffix' if we are called from load_defaults() as otherwise we can't know the type of 'func_ctx' diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c index b000af19aa0..63f5dc964da 100644 --- a/mysys/mf_iocache.c +++ b/mysys/mf_iocache.c @@ -165,7 +165,7 @@ int init_io_cache(IO_CACHE *info, File file, uint cachesize, (ulong) info, (int) type, (ulong) seek_offset)); info->file= file; - info->type= 0; /* Don't set it until mutex are created */ + info->type= TYPE_NOT_SET; /* Don't set it until mutex are created */ info->pos_in_file= seek_offset; info->pre_close = info->pre_read = info->post_read = 0; info->arg = 0; @@ -1246,7 +1246,7 @@ int end_io_cache(IO_CACHE *info) if (info->type == SEQ_READ_APPEND) { /* Destroy allocated mutex */ - info->type=0; + info->type= TYPE_NOT_SET; #ifdef THREAD pthread_mutex_destroy(&info->append_buffer_lock); #endif diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index a86b6a2f1f4..69410e9faaa 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -161,10 +161,12 @@ KEY_CACHE *dflt_key_cache= &dflt_key_cache_var; #define FLUSH_CACHE 2000 /* sort this many blocks at once */ static int flush_all_key_blocks(KEY_CACHE *keycache); +#ifdef THREAD static void link_into_queue(KEYCACHE_WQUEUE *wqueue, struct st_my_thread_var *thread); static void unlink_from_queue(KEYCACHE_WQUEUE *wqueue, struct st_my_thread_var *thread); +#endif static void free_block(KEY_CACHE *keycache, BLOCK_LINK *block); static void test_key_cache(KEY_CACHE *keycache, const char *where, my_bool lock); @@ -215,6 +217,7 @@ static void keycache_debug_print _VARARGS((const char *fmt,...)); #endif /* defined(KEYCACHE_DEBUG_LOG) && defined(KEYCACHE_DEBUG) */ #if defined(KEYCACHE_DEBUG) || !defined(DBUG_OFF) +#ifdef THREAD static long keycache_thread_id; #define KEYCACHE_THREAD_TRACE(l) \ KEYCACHE_DBUG_PRINT(l,("|thread %ld",keycache_thread_id)) @@ -226,6 +229,11 @@ static long keycache_thread_id; #define KEYCACHE_THREAD_TRACE_END(l) \ KEYCACHE_DBUG_PRINT(l,("]thread %ld",keycache_thread_id)) +#else /* THREAD */ +#define KEYCACHE_THREAD_TRACE(l) KEYCACHE_DBUG_PRINT(l,("")) +#define KEYCACHE_THREAD_TRACE_BEGIN(l) KEYCACHE_DBUG_PRINT(l,("")) +#define KEYCACHE_THREAD_TRACE_END(l) KEYCACHE_DBUG_PRINT(l,("")) +#endif /* THREAD */ #else #define KEYCACHE_THREAD_TRACE_BEGIN(l) #define KEYCACHE_THREAD_TRACE_END(l) @@ -492,6 +500,7 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, keycache_pthread_mutex_lock(&keycache->cache_lock); +#ifdef THREAD wqueue= &keycache->resize_queue; thread= my_thread_var; link_into_queue(wqueue, thread); @@ -500,6 +509,7 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, { keycache_pthread_cond_wait(&thread->suspend, &keycache->cache_lock); } +#endif keycache->resize_in_flush= 1; if (flush_all_key_blocks(keycache)) @@ -512,12 +522,16 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, } keycache->resize_in_flush= 0; keycache->can_be_used= 0; +#ifdef THREAD while (keycache->cnt_for_resize_op) { KEYCACHE_DBUG_PRINT("resize_key_cache: wait", ("suspend thread %ld", thread->id)); keycache_pthread_cond_wait(&thread->suspend, &keycache->cache_lock); } +#else + KEYCACHE_DBUG_ASSERT(keycache->cnt_for_resize_op == 0); +#endif end_key_cache(keycache, 0); /* Don't free mutex */ /* The following will work even if use_mem is 0 */ @@ -525,6 +539,7 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, division_limit, age_threshold); finish: +#ifdef THREAD unlink_from_queue(wqueue, thread); /* Signal for the next resize request to proceeed if any */ if (wqueue->last_thread) @@ -533,6 +548,7 @@ finish: ("thread %ld", wqueue->last_thread->next->id)); keycache_pthread_cond_signal(&wqueue->last_thread->next->suspend); } +#endif keycache_pthread_mutex_unlock(&keycache->cache_lock); return blocks; } @@ -553,6 +569,7 @@ static inline void inc_counter_for_resize_op(KEY_CACHE *keycache) */ static inline void dec_counter_for_resize_op(KEY_CACHE *keycache) { +#ifdef THREAD struct st_my_thread_var *last_thread; if (!--keycache->cnt_for_resize_op && (last_thread= keycache->resize_queue.last_thread)) @@ -561,6 +578,9 @@ static inline void dec_counter_for_resize_op(KEY_CACHE *keycache) ("thread %ld", last_thread->next->id)); keycache_pthread_cond_signal(&last_thread->next->suspend); } +#else + keycache->cnt_for_resize_op--; +#endif } /* @@ -650,6 +670,7 @@ void end_key_cache(KEY_CACHE *keycache, my_bool cleanup) } /* end_key_cache */ +#ifdef THREAD /* Link a thread into double-linked queue of waiting threads. @@ -786,6 +807,7 @@ static void release_queue(KEYCACHE_WQUEUE *wqueue) while (thread != last); wqueue->last_thread= NULL; } +#endif /* @@ -893,6 +915,7 @@ static void link_block(KEY_CACHE *keycache, BLOCK_LINK *block, my_bool hot, BLOCK_LINK **pins; KEYCACHE_DBUG_ASSERT(! (block->hash_link && block->hash_link->requests)); +#ifdef THREAD if (!hot && keycache->waiting_for_block.last_thread) { /* Signal that in the LRU warm sub-chain an available block has appeared */ @@ -929,6 +952,10 @@ static void link_block(KEY_CACHE *keycache, BLOCK_LINK *block, my_bool hot, #endif return; } +#else /* THREAD */ + KEYCACHE_DBUG_ASSERT(! (!hot && keycache->waiting_for_block.last_thread)); + /* Condition not transformed using DeMorgan, to keep the text identical */ +#endif /* THREAD */ pins= hot ? &keycache->used_ins : &keycache->used_last; ins= *pins; if (ins) @@ -1101,6 +1128,7 @@ static inline void remove_reader(BLOCK_LINK *block) static inline void wait_for_readers(KEY_CACHE *keycache, BLOCK_LINK *block) { +#ifdef THREAD struct st_my_thread_var *thread= my_thread_var; while (block->hash_link->requests) { @@ -1111,6 +1139,9 @@ static inline void wait_for_readers(KEY_CACHE *keycache, BLOCK_LINK *block) keycache_pthread_cond_wait(&thread->suspend, &keycache->cache_lock); block->condvar= NULL; } +#else + KEYCACHE_DBUG_ASSERT(block->hash_link->requests == 0); +#endif } @@ -1140,6 +1171,7 @@ static void unlink_hash(KEY_CACHE *keycache, HASH_LINK *hash_link) if ((*hash_link->prev= hash_link->next)) hash_link->next->prev= hash_link->prev; hash_link->block= NULL; +#ifdef THREAD if (keycache->waiting_for_hash_link.last_thread) { /* Signal that a free hash link has appeared */ @@ -1175,6 +1207,9 @@ static void unlink_hash(KEY_CACHE *keycache, HASH_LINK *hash_link) hash_link); return; } +#else /* THREAD */ + KEYCACHE_DBUG_ASSERT(! (keycache->waiting_for_hash_link.last_thread)); +#endif /* THREAD */ hash_link->next= keycache->free_hash_list; keycache->free_hash_list= hash_link; } @@ -1240,6 +1275,7 @@ restart: } else { +#ifdef THREAD /* Wait for a free hash link */ struct st_my_thread_var *thread= my_thread_var; KEYCACHE_DBUG_PRINT("get_hash_link", ("waiting")); @@ -1252,6 +1288,9 @@ restart: keycache_pthread_cond_wait(&thread->suspend, &keycache->cache_lock); thread->opt_info= NULL; +#else + KEYCACHE_DBUG_ASSERT(0); +#endif goto restart; } hash_link->file= file; @@ -1363,6 +1402,7 @@ restart: /* Wait intil the page is flushed on disk */ hash_link->requests--; { +#ifdef THREAD struct st_my_thread_var *thread= my_thread_var; add_to_queue(&block->wqueue[COND_FOR_SAVED], thread); do @@ -1373,6 +1413,16 @@ restart: &keycache->cache_lock); } while(thread->next); +#else + KEYCACHE_DBUG_ASSERT(0); + /* + Given the use of "resize_in_flush", it seems impossible + that this whole branch is ever entered in single-threaded case + because "(wrmode && keycache->resize_in_flush)" cannot be true. + TODO: Check this, and then put the whole branch into the + "#ifdef THREAD" guard. + */ +#endif } /* Invalidate page in the block if it has not been done yet */ if (block->status) @@ -1401,6 +1451,7 @@ restart: KEYCACHE_DBUG_PRINT("find_key_block", ("request waiting for old page to be saved")); { +#ifdef THREAD struct st_my_thread_var *thread= my_thread_var; /* Put the request into the queue of those waiting for the old page */ add_to_queue(&block->wqueue[COND_FOR_SAVED], thread); @@ -1413,6 +1464,10 @@ restart: &keycache->cache_lock); } while(thread->next); +#else + KEYCACHE_DBUG_ASSERT(0); + /* No parallel requests in single-threaded case */ +#endif } KEYCACHE_DBUG_PRINT("find_key_block", ("request for old page resubmitted")); @@ -1471,6 +1526,7 @@ restart: all of them must get the same block */ +#ifdef THREAD if (! keycache->used_last) { struct st_my_thread_var *thread= my_thread_var; @@ -1486,6 +1542,9 @@ restart: while (thread->next); thread->opt_info= NULL; } +#else + KEYCACHE_DBUG_ASSERT(keycache->used_last); +#endif block= hash_link->block; if (! block) { @@ -1674,6 +1733,7 @@ static void read_block(KEY_CACHE *keycache, KEYCACHE_DBUG_PRINT("read_block", ("secondary request waiting for new page to be read")); { +#ifdef THREAD struct st_my_thread_var *thread= my_thread_var; /* Put the request into a queue and wait until it can be processed */ add_to_queue(&block->wqueue[COND_FOR_REQUESTED], thread); @@ -1685,6 +1745,10 @@ static void read_block(KEY_CACHE *keycache, &keycache->cache_lock); } while (thread->next); +#else + KEYCACHE_DBUG_ASSERT(0); + /* No parallel requests in single-threaded case */ +#endif } KEYCACHE_DBUG_PRINT("read_block", ("secondary request: new page in cache")); @@ -1822,7 +1886,7 @@ byte *key_cache_read(KEY_CACHE *keycache, #ifndef THREAD /* This is only true if we where able to read everything in one block */ if (return_buffer) - return (block->buffer); + DBUG_RETURN(block->buffer); #endif buff+= read_length; filepos+= read_length+offset; @@ -2398,6 +2462,7 @@ restart: #endif block= first_in_switch; { +#ifdef THREAD struct st_my_thread_var *thread= my_thread_var; add_to_queue(&block->wqueue[COND_FOR_SAVED], thread); do @@ -2408,6 +2473,10 @@ restart: &keycache->cache_lock); } while (thread->next); +#else + KEYCACHE_DBUG_ASSERT(0); + /* No parallel requests in single-threaded case */ +#endif } #if defined(KEYCACHE_DEBUG) cnt++; @@ -2574,7 +2643,6 @@ static void test_key_cache(KEY_CACHE *keycache __attribute__((unused)), static void keycache_dump(KEY_CACHE *keycache) { FILE *keycache_dump_file=fopen(KEYCACHE_DUMP_FILE, "w"); - struct st_my_thread_var *thread_var= my_thread_var; struct st_my_thread_var *last; struct st_my_thread_var *thread; BLOCK_LINK *block; diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index fd5a4908572..d5346d530c3 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -221,6 +221,57 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size) #endif } + +/* + Allocate many pointers at the same time. + + DESCRIPTION + ptr1, ptr2, etc all point into big allocated memory area. + + SYNOPSIS + multi_alloc_root() + root Memory root + ptr1, length1 Multiple arguments terminated by a NULL pointer + ptr2, length2 ... + ... + NULL + + RETURN VALUE + A pointer to the beginning of the allocated memory block + in case of success or NULL if out of memory. +*/ + +gptr multi_alloc_root(MEM_ROOT *root, ...) +{ + va_list args; + char **ptr, *start, *res; + uint tot_length, length; + DBUG_ENTER("multi_alloc_root"); + + va_start(args, root); + tot_length= 0; + while ((ptr= va_arg(args, char **))) + { + length= va_arg(args, uint); + tot_length+= ALIGN_SIZE(length); + } + va_end(args); + + if (!(start= (char*) alloc_root(root, tot_length))) + DBUG_RETURN(0); /* purecov: inspected */ + + va_start(args, root); + res= start; + while ((ptr= va_arg(args, char **))) + { + *ptr= res; + length= va_arg(args, uint); + res+= ALIGN_SIZE(length); + } + va_end(args); + DBUG_RETURN((gptr) start); +} + #define TRASH_MEM(X) TRASH(((char*)(X) + ((X)->size-(X)->left)), (X)->left) /* Mark all data in blocks free for reusage */ diff --git a/mysys/my_conio.c b/mysys/my_conio.c new file mode 100644 index 00000000000..e381f9f23ef --- /dev/null +++ b/mysys/my_conio.c @@ -0,0 +1,217 @@ +/* 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 "mysys_priv.h" + +#ifdef __WIN__ + +static HANDLE my_coninpfh= 0; /* console input */ + +/* + functions my_pthread_auto_mutex_lock & my_pthread_auto_mutex_free + are experimental at this moment, they are intended to bring + ability of protecting code sections without necessity to explicitly + initialize synchronization object in one of threads + + if found useful they are to be exported in mysys +*/ + +/* + int my_pthread_auto_mutex_lock(HANDLE* ph, const char* name, + int id, int time) + + NOTES + creates a mutex with given name and tries to lock it time msec. + mutex name is appended with id to allow system wide or process wide + locks. Handle to created mutex returned in ph argument. + + RETURN + 0 thread owns mutex + <>0 error + +*/ +static +int my_pthread_auto_mutex_lock(HANDLE* ph, const char* name, int id, int time) +{ + int res; + char tname[FN_REFLEN]; + + sprintf(tname, "%s-%08X", name, id); + + *ph= CreateMutex(NULL, FALSE, tname); + if (*ph == NULL) + return GetLastError(); + + res= WaitForSingleObject(*ph, time); + + if (res == WAIT_TIMEOUT) + return ERROR_SEM_TIMEOUT; + + if (res == WAIT_FAILED) + return GetLastError(); + + return 0; +} + +/* + int my_pthread_auto_mutex_free(HANDLE* ph) + + + NOTES + releases a mutex. + + RETURN + 0 thread released mutex + <>0 error + +*/ +static +int my_pthread_auto_mutex_free(HANDLE* ph) +{ + if (*ph) + { + ReleaseMutex(*ph); + CloseHandle(*ph); + *ph= NULL; + } + + return 0; +} + + +#define pthread_auto_mutex_decl(name) \ + HANDLE __h##name= NULL; + +#define pthread_auto_mutex_lock(name, proc, time) \ + my_pthread_auto_mutex_lock(&__h##name, #name, (proc), (time)) + +#define pthread_auto_mutex_free(name) \ + my_pthread_auto_mutex_free(&__h##name) + + +/* + char* my_cgets(char *string, unsigned long clen, unsigned long* plen) + + NOTES + Replaces _cgets from libc to support input of more than 255 chars. + Reads from the console via ReadConsole into buffer which + should be at least clen characters. + Actual length of string returned in plen. + + WARNING + my_cgets() does NOT check the pushback character buffer (i.e., _chbuf). + Thus, my_cgets() will not return any character that is pushed back by + the _ungetch() call. + + RETURN + string pointer ok + NULL Error + +*/ +char* my_cgets(char *buffer, unsigned long clen, unsigned long* plen) +{ + ULONG state; + char *result; + CONSOLE_SCREEN_BUFFER_INFO csbi; + + pthread_auto_mutex_decl(my_conio_cs); + + /* lock the console for the current process*/ + if (pthread_auto_mutex_lock(my_conio_cs, GetCurrentProcessId(), INFINITE)) + { + /* can not lock console */ + pthread_auto_mutex_free(my_conio_cs); + return NULL; + } + + /* init console input */ + if (my_coninpfh == 0) + { + /* same handle will be used until process termination */ + my_coninpfh= CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, 0, NULL); + } + + if (my_coninpfh == INVALID_HANDLE_VALUE) + { + /* unlock the console */ + pthread_auto_mutex_free(my_conio_cs); + return(NULL); + } + + GetConsoleMode((HANDLE)my_coninpfh, &state); + SetConsoleMode((HANDLE)my_coninpfh, ENABLE_LINE_INPUT | + ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT); + + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); + + /* + there is no known way to determine allowed buffer size for input + though it is known it should not be more than 64K + so we cut 64K and try first size of screen buffer + if it is still to large we cut half of it and try again + later we may want to cycle from min(clen, 65535) to allowed size + with small decrement to determine exact allowed buffer + */ + clen= min(clen, 65535); + do + { + clen= min(clen, (unsigned long)csbi.dwSize.X*csbi.dwSize.Y); + if (!ReadConsole((HANDLE)my_coninpfh, (LPVOID)buffer, clen - 1, plen, NULL)) + { + result= NULL; + clen>>= 1; + } + else + { + result= buffer; + break; + } + } + while (GetLastError() == ERROR_NOT_ENOUGH_MEMORY); + + + if (result != NULL) + { + if (buffer[*plen - 2] == '\r') + { + *plen= *plen - 2; + } + else + { + if (buffer[*plen - 1] == '\r') + { + char tmp[3]; + int tmplen= sizeof(tmp); + + *plen= *plen - 1; + /* read /n left in the buffer */ + ReadConsole((HANDLE)my_coninpfh, (LPVOID)tmp, tmplen, &tmplen, NULL); + } + } + buffer[*plen]= '\0'; + } + + SetConsoleMode((HANDLE)my_coninpfh, state); + /* unlock the console */ + pthread_auto_mutex_free(my_conio_cs); + + return result; +} + +#endif /* __WIN__ */ diff --git a/mysys/my_init.c b/mysys/my_init.c index abb1ad27f7b..f28f47e090e 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -127,11 +127,23 @@ my_bool my_init(void) void my_end(int infoflag) { - FILE *info_file; - if (!(info_file=DBUG_FILE)) - info_file=stderr; - DBUG_PRINT("info",("Shutting down")); - if (infoflag & MY_CHECK_ERROR || info_file != stderr) + /* + this code is suboptimal to workaround a bug in + Sun CC: Sun C++ 5.6 2004/06/02 for x86, and should not be + optimized until this compiler is not in use anymore + */ + FILE *info_file= DBUG_FILE; + my_bool print_info= (info_file != stderr); + DBUG_ENTER("my_end"); + if (!info_file) + { + info_file= stderr; + print_info= 0; + } + + DBUG_PRINT("info",("Shutting down: print_info: %d", print_info)); + if ((infoflag & MY_CHECK_ERROR) || print_info) + { /* Test if some file is left open */ if (my_file_opened | my_stream_opened) { @@ -141,7 +153,8 @@ void my_end(int infoflag) } } my_once_free(); - if (infoflag & MY_GIVE_INFO || info_file != stderr) + + if ((infoflag & MY_GIVE_INFO) || print_info) { #ifdef HAVE_GETRUSAGE struct rusage rus; |