summaryrefslogtreecommitdiff
path: root/innobase/srv/srv0start.c
diff options
context:
space:
mode:
authorunknown <monty@narttu.mysql.fi>2003-06-05 00:12:45 +0300
committerunknown <monty@narttu.mysql.fi>2003-06-05 00:12:45 +0300
commitad5e39bf12b7aeefbc313e464a1349541a7b15c5 (patch)
tree824e127f68404d3fbe881d6619e34ad389d21202 /innobase/srv/srv0start.c
parent020baadcfebbd0f2248d9a3fa15f29d6e9d954b4 (diff)
parentc6c60f6ee819a238ab62e3f9608502c9a8f25b36 (diff)
downloadmariadb-git-ad5e39bf12b7aeefbc313e464a1349541a7b15c5.tar.gz
merge with public tree
BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union client/mysql.cc: Auto merged configure.in: Auto merged include/config-win.h: Auto merged include/mysql.h: Auto merged include/mysql_version.h.in: Auto merged libmysqld/lib_sql.cc: Auto merged mysql-test/r/alter_table.result: Auto merged mysql-test/r/create.result: Auto merged mysql-test/r/ctype_collate.result: Auto merged mysql-test/r/innodb.result: Auto merged mysql-test/r/show_check.result: Auto merged mysql-test/r/subselect.result: Auto merged mysql-test/r/type_blob.result: Auto merged mysql-test/t/subselect.test: Auto merged mysys/default.c: Auto merged sql/Makefile.am: Auto merged sql/field.cc: Auto merged sql/item.cc: Auto merged sql/item.h: Auto merged sql/item_cmpfunc.cc: Auto merged sql/mysql_priv.h: Auto merged sql/mysqld.cc: Auto merged sql/protocol.cc: Auto merged sql/set_var.cc: Auto merged sql/set_var.h: Auto merged sql/slave.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_string.cc: Auto merged sql/sql_string.h: Auto merged sql/sql_table.cc: Auto merged sql/sql_yacc.yy: Auto merged
Diffstat (limited to 'innobase/srv/srv0start.c')
-rw-r--r--innobase/srv/srv0start.c95
1 files changed, 71 insertions, 24 deletions
diff --git a/innobase/srv/srv0start.c b/innobase/srv/srv0start.c
index 536aa5b67e4..9a2bf72130b 100644
--- a/innobase/srv/srv0start.c
+++ b/innobase/srv/srv0start.c
@@ -1481,9 +1481,7 @@ innobase_start_or_create_for_mysql(void)
os_fast_mutex_unlock(&srv_os_test_mutex);
-#if defined(__NETWARE__) || defined(SAFE_MUTEX_DETECT_DESTROY)
- os_fast_mutex_free(&srv_os_test_mutex); /* all platforms? */
-#endif /* __NETWARE__ */
+ os_fast_mutex_free(&srv_os_test_mutex);
if (srv_print_verbose_log) {
ut_print_timestamp(stderr);
@@ -1509,6 +1507,8 @@ innobase_shutdown_for_mysql(void)
/*=============================*/
/* out: DB_SUCCESS or error code */
{
+ ulint i;
+
if (!srv_was_started) {
if (srv_is_being_started) {
ut_print_timestamp(stderr);
@@ -1521,7 +1521,7 @@ innobase_shutdown_for_mysql(void)
return(DB_SUCCESS);
}
- /* Flush buffer pool to disk, write the current lsn to
+ /* 1. Flush buffer pool to disk, write the current lsn to
the tablespace header(s), and copy all log data to archive */
logs_empty_and_mark_files_at_shutdown();
@@ -1533,30 +1533,77 @@ innobase_shutdown_for_mysql(void)
srv_conc_n_threads);
}
-#if defined(__NETWARE__) || defined(SAFE_MUTEX_DETECT_DESTROY)
- /*
- TODO: Fix this temporary solution
- We are having a race condition occure with io_handler_thread threads.
- When they yield in os_aio_simulated_handle during shutdown, this
- thread was able to free the memory early.
- */
- os_thread_yield();
+ /* 2. Make all threads created by InnoDB to exit */
+
+ srv_shutdown_state = SRV_SHUTDOWN_EXIT_THREADS;
+
+ /* All threads end up waiting for certain events. Put those events
+ to the signaled state. Then the threads will exit themselves in
+ os_thread_event_wait(). */
+
+ for (i = 0; i < 1000; i++) {
+ /* NOTE: IF YOU CREATE THREADS IN INNODB, YOU MUST EXIT THEM
+ HERE OR EARLIER */
+
+ /* 1. Let the lock timeout thread exit */
+ os_event_set(srv_lock_timeout_thread_event);
+
+ /* 2. srv error monitor thread exits automatically, no need
+ to do anything here */
+
+ /* 3. We wake the master thread so that it exits */
+ srv_wake_master_thread();
+
+ /* 4. Exit the i/o threads */
+
+ os_aio_wake_all_threads_at_shutdown();
+
+ os_mutex_enter(os_sync_mutex);
+
+ if (os_thread_count == 0) {
+ /* All the threads have exited or are just exiting;
+ NOTE that the threads may not have completed their
+ exit yet. Should we use pthread_join() to make sure
+ they have exited? Now we just sleep 0.1 seconds and
+ hope that is enough! */
+
+ os_mutex_exit(os_sync_mutex);
+
+ os_thread_sleep(100000);
+
+ break;
+ }
+
+ os_mutex_exit(os_sync_mutex);
+
+ os_thread_sleep(100000);
+ }
+
+ if (i == 1000) {
+ fprintf(stderr,
+"InnoDB: Warning: %lu threads created by InnoDB had not exited at shutdown!\n",
+ os_thread_count);
+ }
+
+ /* 3. Free all InnoDB's own mutexes */
+
+ sync_close();
+
+ /* 4. Free all OS synchronization primitives (in Windows currently
+ events are not freed) */
- /* TODO: Where should this be called? */
srv_free();
+ os_sync_free();
+
+ /* 5. Free all allocated memory (and the os_fast_mutex created in
+ ut0mem.c */
- /* TODO: Where should this be called? */
- srv_general_free();
-#endif
- /*
- TODO: We should exit the i/o-handler and other utility threads
- before freeing all memory. Now this can potentially cause a seg
- fault!
- */
-#if defined(NOT_WORKING_YET) || defined(__NETWARE__) || defined(SAFE_MUTEX_DETECT_DESTROY)
- /* NetWare requires this free */
ut_free_all_mem();
-#endif
+
+ if (srv_print_verbose_log) {
+ ut_print_timestamp(stderr);
+ fprintf(stderr, " InnoDB: Shutdown completed\n");
+ }
return((int) DB_SUCCESS);
}