diff options
author | unknown <monty@donna.mysql.com> | 2001-02-17 14:19:19 +0200 |
---|---|---|
committer | unknown <monty@donna.mysql.com> | 2001-02-17 14:19:19 +0200 |
commit | 132e667b0bbbe33137b6baeb59f3f22b7524f066 (patch) | |
tree | bfe39951a73e906579ab819bf5198ad8f3a64a36 /innobase/thr | |
parent | b084cf1951eb271f662a9326c950f4cf0570258d (diff) | |
download | mariadb-git-132e667b0bbbe33137b6baeb59f3f22b7524f066.tar.gz |
Added Innobase to source distribution
Docs/manual.texi:
Added Innobase documentation
configure.in:
Incremented version
include/my_base.h:
Added option for Innobase
myisam/mi_check.c:
cleanup
mysql-test/t/bdb.test:
cleanup
mysql-test/t/innobase.test:
Extended with new tests from bdb.test
mysql-test/t/merge.test:
Added test of SHOW create
mysys/my_init.c:
Fix for UNIXWARE 7
scripts/mysql_install_db.sh:
Always write how to start mysqld
scripts/safe_mysqld.sh:
Fixed type
sql/ha_innobase.cc:
Update to new version
sql/ha_innobase.h:
Update to new version
sql/handler.h:
Added 'update_table_comment()' and 'append_create_info()'
sql/sql_delete.cc:
Fixes for Innobase
sql/sql_select.cc:
Fixes for Innobase
sql/sql_show.cc:
Append create information (for MERGE tables)
sql/sql_update.cc:
Fixes for Innobase
Diffstat (limited to 'innobase/thr')
-rw-r--r-- | innobase/thr/Makefile.am | 24 | ||||
-rw-r--r-- | innobase/thr/makefilewin | 9 | ||||
-rw-r--r-- | innobase/thr/thr0loc.c | 228 | ||||
-rw-r--r-- | innobase/thr/ts/makefile | 14 | ||||
-rw-r--r-- | innobase/thr/ts/tsthr.c | 131 |
5 files changed, 406 insertions, 0 deletions
diff --git a/innobase/thr/Makefile.am b/innobase/thr/Makefile.am new file mode 100644 index 00000000000..5f42138e734 --- /dev/null +++ b/innobase/thr/Makefile.am @@ -0,0 +1,24 @@ +# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +# & Innobase Oy +# +# 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 ../include/Makefile.i + +libs_LIBRARIES = libthr.a + +libthr_a_SOURCES = thr0loc.c + +EXTRA_PROGRAMS = diff --git a/innobase/thr/makefilewin b/innobase/thr/makefilewin new file mode 100644 index 00000000000..3f29ea1d3e3 --- /dev/null +++ b/innobase/thr/makefilewin @@ -0,0 +1,9 @@ +include ..\include\makefile.i + +thr.lib: thr0loc.obj + lib -out:..\libs\thr.lib thr0loc.obj + +thr0loc.obj: thr0loc.c + $(CCOM) $(CFL) -c thr0loc.c + + diff --git a/innobase/thr/thr0loc.c b/innobase/thr/thr0loc.c new file mode 100644 index 00000000000..897e53557c3 --- /dev/null +++ b/innobase/thr/thr0loc.c @@ -0,0 +1,228 @@ +/****************************************************** +The thread local storage + +(c) 1995 Innobase Oy + +Created 10/5/1995 Heikki Tuuri +*******************************************************/ + +#include "thr0loc.h" +#ifdef UNIV_NONINL +#include "thr0loc.ic" +#endif + +#include "sync0sync.h" +#include "hash0hash.h" +#include "mem0mem.h" + +/* + IMPLEMENTATION OF THREAD LOCAL STORAGE + ====================================== + +The threads sometimes need private data which depends on the thread id. +This is implemented as a hash table, where the hash value is calculated +from the thread id, to prepare for a large number of threads. The hash table +is protected by a mutex. If you need modify the program and put new data to +the thread local storage, just add it to struct thr_local_struct in the +header file. */ + +/* Mutex protecting the local storage hash table */ +mutex_t thr_local_mutex; + +/* The hash table. The module is not yet initialized when it is NULL. */ +hash_table_t* thr_local_hash = NULL; + +/* The private data for each thread should be put to +the structure below and the accessor functions written +for the field. */ +typedef struct thr_local_struct thr_local_t; + +struct thr_local_struct{ + os_thread_id_t id; /* id of the thread which owns this struct */ + os_thread_t handle; /* operating system handle to the thread */ + ulint slot_no;/* the index of the slot in the thread table + for this thread */ + ibool in_ibuf;/* TRUE if the the thread is doing an ibuf + operation */ + hash_node_t hash; /* hash chain node */ + ulint magic_n; +}; + +#define THR_LOCAL_MAGIC_N 1231234 + +/*********************************************************************** +Returns the local storage struct for a thread. */ +static +thr_local_t* +thr_local_get( +/*==========*/ + /* out: local storage */ + os_thread_id_t id) /* in: thread id of the thread */ +{ + thr_local_t* local; + +try_again: + ut_ad(thr_local_hash); + ut_ad(mutex_own(&thr_local_mutex)); + + /* Look for the local struct in the hash table */ + + local = NULL; + + HASH_SEARCH(hash, thr_local_hash, os_thread_conv_id_to_ulint(id), + local, local->id == id); + if (local == NULL) { + mutex_exit(&thr_local_mutex); + + thr_local_create(); + + mutex_enter(&thr_local_mutex); + + goto try_again; + } + + ut_ad(local->magic_n == THR_LOCAL_MAGIC_N); + + return(local); +} + +/*********************************************************************** +Gets the slot number in the thread table of a thread. */ + +ulint +thr_local_get_slot_no( +/*==================*/ + /* out: slot number */ + os_thread_id_t id) /* in: thread id of the thread */ +{ + ulint slot_no; + thr_local_t* local; + + mutex_enter(&thr_local_mutex); + + local = thr_local_get(id); + + slot_no = local->slot_no; + + mutex_exit(&thr_local_mutex); + + return(slot_no); +} + +/*********************************************************************** +Sets the slot number in the thread table of a thread. */ + +void +thr_local_set_slot_no( +/*==================*/ + os_thread_id_t id, /* in: thread id of the thread */ + ulint slot_no)/* in: slot number */ +{ + thr_local_t* local; + + mutex_enter(&thr_local_mutex); + + local = thr_local_get(id); + + local->slot_no = slot_no; + + mutex_exit(&thr_local_mutex); +} + +/*********************************************************************** +Returns pointer to the 'in_ibuf' field within the current thread local +storage. */ + +ibool* +thr_local_get_in_ibuf_field(void) +/*=============================*/ + /* out: pointer to the in_ibuf field */ +{ + thr_local_t* local; + + mutex_enter(&thr_local_mutex); + + local = thr_local_get(os_thread_get_curr_id()); + + mutex_exit(&thr_local_mutex); + + return(&(local->in_ibuf)); +} + +/*********************************************************************** +Creates a local storage struct for the calling new thread. */ + +void +thr_local_create(void) +/*==================*/ +{ + thr_local_t* local; + + if (thr_local_hash == NULL) { + thr_local_init(); + } + + local = mem_alloc(sizeof(thr_local_t)); + + local->id = os_thread_get_curr_id(); + local->handle = os_thread_get_curr(); + local->magic_n = THR_LOCAL_MAGIC_N; + + local->in_ibuf = FALSE; + + mutex_enter(&thr_local_mutex); + + HASH_INSERT(thr_local_t, hash, thr_local_hash, + os_thread_conv_id_to_ulint(os_thread_get_curr_id()), + local); + + mutex_exit(&thr_local_mutex); +} + +/*********************************************************************** +Frees the local storage struct for the specified thread. */ + +void +thr_local_free( +/*===========*/ + os_thread_id_t id) /* in: thread id */ +{ + thr_local_t* local; + + mutex_enter(&thr_local_mutex); + + /* Look for the local struct in the hash table */ + + HASH_SEARCH(hash, thr_local_hash, os_thread_conv_id_to_ulint(id), + local, local->id == id); + if (local == NULL) { + mutex_exit(&thr_local_mutex); + + return; + } + + HASH_DELETE(thr_local_t, hash, thr_local_hash, + os_thread_conv_id_to_ulint(id), local); + + mutex_exit(&thr_local_mutex); + + ut_a(local->magic_n == THR_LOCAL_MAGIC_N); + + mem_free(local); +} + +/******************************************************************** +Initializes the thread local storage module. */ + +void +thr_local_init(void) +/*================*/ +{ + + ut_a(thr_local_hash == NULL); + + thr_local_hash = hash_create(OS_THREAD_MAX_N + 100); + + mutex_create(&thr_local_mutex); + mutex_set_level(&thr_local_mutex, SYNC_ANY_LATCH); +} diff --git a/innobase/thr/ts/makefile b/innobase/thr/ts/makefile new file mode 100644 index 00000000000..517f50d197a --- /dev/null +++ b/innobase/thr/ts/makefile @@ -0,0 +1,14 @@ + + + +include ..\..\makefile.i + +tsthr: ..\thr.lib tsthr.c makefile + $(CCOM) $(CFL) -I.. -I..\.. ..\thr.lib ..\..\ha.lib ..\..\sync.lib ..\..\ut.lib ..\..\mem.lib ..\..\os.lib tsthr.c $(LFL) + + + + + + + diff --git a/innobase/thr/ts/tsthr.c b/innobase/thr/ts/tsthr.c new file mode 100644 index 00000000000..af5aaa54522 --- /dev/null +++ b/innobase/thr/ts/tsthr.c @@ -0,0 +1,131 @@ +/************************************************************************ +The test module for the thread management of Innobase + +(c) 1995 Innobase Oy + +Created 10/5/1995 Heikki Tuuri +*************************************************************************/ + +#include "../thr0loc.h" +#include "sync0sync.h" +#include "mem0mem.h" +#include "os0thread.h" +#include "os0sync.h" +#include "ut0ut.h" + +ulint val = 500; +os_event_t event; + +/****************************************************************** +Thread start function in test1. */ + +ulint +thread1( +/*====*/ + void* arg) +{ + ulint n; + + thr_local_create(); + + n = *((ulint*)arg); + + printf("Thread %lu starts\n", n); + + thr_local_set_slot_no(os_thread_get_curr_id(), n); + + ut_a(n == thr_local_get_slot_no(os_thread_get_curr_id())); + + os_event_wait(event); + + thr_local_free(); + + os_thread_exit(0); + + return(0); +} + +/****************************************************************** +Test function for local storage. */ + +void +test1(void) +/*=======*/ +{ + os_thread_t thr1, thr2, thr3, thr4, thr5; + os_thread_id_t id1, id2, id3, id4, id5; + ulint tm, oldtm; + ulint n1, n2, n3, n4, n5; + + printf("-------------------------------------------\n"); + printf("THR-TEST 1. Test of local storage\n"); + + event = os_event_create(NULL); + + oldtm = ut_clock(); + + n1 = 1; + thr1 = os_thread_create(thread1, + &n1, + &id1); + n2 = 2; + thr2 = os_thread_create(thread1, + &n2, + &id2); + n3 = 3; + thr3 = os_thread_create(thread1, + &n3, + &id3); + n4 = 4; + thr4 = os_thread_create(thread1, + &n4, + &id4); + n5 = 5; + thr5 = os_thread_create(thread1, + &n5, + &id5); + + os_thread_sleep(500000); + + ut_a(n1 == thr_local_get_slot_no(id1)); + ut_a(n2 == thr_local_get_slot_no(id2)); + ut_a(n3 == thr_local_get_slot_no(id3)); + ut_a(n4 == thr_local_get_slot_no(id4)); + ut_a(n5 == thr_local_get_slot_no(id5)); + + os_event_set(event); + + os_thread_wait(thr1); + os_thread_wait(thr2); + os_thread_wait(thr3); + os_thread_wait(thr4); + os_thread_wait(thr5); + + tm = ut_clock(); + printf("Wall clock time for 5 threads %ld milliseconds\n", + tm - oldtm); +} + +/************************************************************************ +Main test function. */ + +void +main(void) +/*======*/ +{ + ulint tm, oldtm; + + sync_init(); + mem_init(); + thr_local_init(); + + oldtm = ut_clock(); + + test1(); + + thr_local_close(); + + tm = ut_clock(); + printf("Wall clock time for test %lu milliseconds\n", tm - oldtm); + printf("TESTS COMPLETED SUCCESSFULLY!\n"); +} |